Repair Doxygen build infrastructure
[vpp.git] / vpp-api / java / jvpp-core / io / fd / vpp / jvpp / core / test / CallbackJVppFacadeTest.java
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
3  *
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:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package io.fd.vpp.jvpp.core.test;
18
19 import io.fd.vpp.jvpp.JVppRegistry;
20 import io.fd.vpp.jvpp.JVppRegistryImpl;
21 import io.fd.vpp.jvpp.VppCallbackException;
22 import io.fd.vpp.jvpp.core.JVppCoreImpl;
23 import io.fd.vpp.jvpp.core.callback.GetNodeIndexCallback;
24 import io.fd.vpp.jvpp.core.callback.ShowVersionCallback;
25 import io.fd.vpp.jvpp.core.callfacade.CallbackJVppCoreFacade;
26 import io.fd.vpp.jvpp.core.dto.GetNodeIndex;
27 import io.fd.vpp.jvpp.core.dto.GetNodeIndexReply;
28 import io.fd.vpp.jvpp.core.dto.ShowVersionReply;
29
30 /**
31  * CallbackJVppFacade together with CallbackJVppFacadeCallback allow for setting different callback for each request.
32  * This is more convenient than the approach shown in CallbackApiTest.
33  */
34 public class CallbackJVppFacadeTest {
35
36     private static ShowVersionCallback showVersionCallback1 = new ShowVersionCallback() {
37         @Override
38         public void onShowVersionReply(final ShowVersionReply msg) {
39             System.out.printf("ShowVersionCallback1 received ShowVersionReply: context=%d, program=%s,"
40                     + "version=%s, buildDate=%s, buildDirectory=%s%n", msg.context, new String(msg.program),
41                 new String(msg.version), new String(msg.buildDate), new String(msg.buildDirectory));
42         }
43
44         @Override
45         public void onError(VppCallbackException ex) {
46             System.out.printf("Received onError exception in showVersionCallback1: call=%s, reply=%d, context=%d%n",
47                 ex.getMethodName(), ex.getErrorCode(), ex.getCtxId());
48         }
49     };
50
51     private static ShowVersionCallback showVersionCallback2 = new ShowVersionCallback() {
52         @Override
53         public void onShowVersionReply(final ShowVersionReply msg) {
54             System.out.printf("ShowVersionCallback2 received ShowVersionReply: context=%d, program=%s,"
55                     + "version=%s, buildDate=%s, buildDirectory=%s%n", msg.context, new String(msg.program),
56                 new String(msg.version), new String(msg.buildDate), new String(msg.buildDirectory));
57         }
58
59         @Override
60         public void onError(VppCallbackException ex) {
61             System.out.printf("Received onError exception in showVersionCallback2: call=%s, reply=%d, context=%d%n",
62                 ex.getMethodName(), ex.getErrorCode(), ex.getCtxId());
63         }
64
65     };
66
67     private static GetNodeIndexCallback getNodeIndexCallback = new GetNodeIndexCallback() {
68         @Override
69         public void onGetNodeIndexReply(final GetNodeIndexReply msg) {
70             System.out.printf("Received GetNodeIndexReply: %s%n", msg);
71         }
72
73         @Override
74         public void onError(VppCallbackException ex) {
75             System.out.printf("Received onError exception in getNodeIndexCallback: call=%s, reply=%d, context=%d%n",
76                 ex.getMethodName(), ex.getErrorCode(), ex.getCtxId());
77         }
78     };
79
80     private static void testCallbackFacade() throws Exception {
81         System.out.println("Testing CallbackJVppFacade");
82
83         try (final JVppRegistry registry = new JVppRegistryImpl("CallbackFacadeTest");
84              final CallbackJVppCoreFacade callbackFacade = new CallbackJVppCoreFacade(registry, new JVppCoreImpl())) {
85             System.out.println("Successfully connected to VPP");
86
87             callbackFacade.showVersion(showVersionCallback1);
88             callbackFacade.showVersion(showVersionCallback2);
89
90             GetNodeIndex getNodeIndexRequest = new GetNodeIndex();
91             getNodeIndexRequest.nodeName = "dummyNode".getBytes();
92             callbackFacade.getNodeIndex(getNodeIndexRequest, getNodeIndexCallback);
93
94             Thread.sleep(2000);
95             System.out.println("Disconnecting...");
96         }
97         Thread.sleep(1000);
98     }
99
100     public static void main(String[] args) throws Exception {
101         testCallbackFacade();
102     }
103 }