2 * Copyright (c) 2016 Cisco and/or its affiliates.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.openvpp.jvpp.test;
19 import org.openvpp.jvpp.JVpp;
20 import org.openvpp.jvpp.JVppImpl;
21 import org.openvpp.jvpp.VppCallbackException;
22 import org.openvpp.jvpp.VppJNIConnection;
23 import org.openvpp.jvpp.callback.GetNodeIndexCallback;
24 import org.openvpp.jvpp.callback.ShowVersionCallback;
25 import org.openvpp.jvpp.dto.*;
27 public class OnErrorCallbackTest {
29 private static class TestCallback implements GetNodeIndexCallback, ShowVersionCallback{
32 public void onGetNodeIndexReply(final GetNodeIndexReply msg) {
33 System.out.printf("Received GetNodeIndexReply: context=%d, nodeIndex=%d\n",
34 msg.context, msg.nodeIndex);
37 public void onShowVersionReply(final ShowVersionReply msg) {
38 System.out.printf("Received ShowVersionReply: context=%d, program=%s, version=%s, " +
39 "buildDate=%s, buildDirectory=%s\n",
40 msg.context, new String(msg.program), new String(msg.version),
41 new String(msg.buildDate), new String(msg.buildDirectory));
45 public void onError(VppCallbackException ex) {
46 System.out.printf("Received onError exception: call=%s, context=%d, retval=%d\n", ex.getMethodName(), ex.getCtxId(), ex.getErrorCode());
50 private static void testCallbackApi() throws Exception {
51 System.out.println("Testing Java callback API");
52 JVpp jvpp = new JVppImpl(new VppJNIConnection("CallbackApiTest"));
53 jvpp.connect(new TestCallback());
54 System.out.println("Successfully connected to VPP");
56 System.out.println("Sending ShowVersion request...");
57 jvpp.send(new ShowVersion());
59 System.out.println("Sending GetNodeIndex request...");
60 GetNodeIndex getNodeIndexRequest = new GetNodeIndex();
61 getNodeIndexRequest.nodeName = "dummyNode".getBytes();
62 jvpp.send(getNodeIndexRequest);
66 System.out.println("Disconnecting...");
71 public static void main(String[] args) throws Exception {