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 java.util.HashMap;
21 import org.openvpp.jvpp.JVpp;
22 import org.openvpp.jvpp.JVppImpl;
23 import org.openvpp.jvpp.VppJNIConnection;
24 import org.openvpp.jvpp.callback.JVppCallback;
25 import org.openvpp.jvpp.callback.ShowVersionCallback;
26 import org.openvpp.jvpp.callfacade.CallbackJVppFacade;
27 import org.openvpp.jvpp.callfacade.CallbackJVppFacadeCallback;
30 * CallbackJVppFacade together with CallbackJVppFacadeCallback allow for setting different callback for each request.
31 * This is more convenient than the approach shown in CallbackApiTest.
33 public class CallbackJVppFacadeTest {
35 private static ShowVersionCallback showVersionCallback1 = msg ->
36 System.out.printf("ShowVersionCallback1 received ShowVersionReply: context=%d, retval=%d, program=%s," +
37 "version=%s, buildDate=%s, buildDirectory=%s\n", msg.context, msg.retval, new String(msg.program),
38 new String(msg.version), new String(msg.buildDate), new String(msg.buildDirectory));
40 private static ShowVersionCallback showVersionCallback2 = msg ->
41 System.out.printf("ShowVersionCallback2 received ShowVersionReply: context=%d, retval=%d, program=%s," +
42 "version=%s, buildDate=%s, buildDirectory=%s\n", msg.context, msg.retval, new String(msg.program),
43 new String(msg.version), new String(msg.buildDate), new String(msg.buildDirectory));
45 private static void testCallbackFacade() throws Exception {
46 System.out.println("Testing CallbackJVppFacade");
48 final Map<Integer, JVppCallback> callbackMap = new HashMap<>();
49 JVpp impl = new JVppImpl(VppJNIConnection.create("CallbackApiTest", new CallbackJVppFacadeCallback(callbackMap)));
50 CallbackJVppFacade jvpp = new CallbackJVppFacade(impl, callbackMap);
51 System.out.println("Successfully connected to VPP");
53 jvpp.showVersion(showVersionCallback1);
54 jvpp.showVersion(showVersionCallback2);
59 System.out.println("Disconnecting...");
64 public static void main(String[] args) throws Exception {