Update LYNQ test
Change-Id: I9e434803f0cce9f24048f2fbc5eed2d26fa33503
diff --git a/mbtk/test/liblynq_lib/lynq-qser-voice-demo.cpp b/mbtk/test/liblynq_lib/lynq-qser-voice-demo.cpp
new file mode 100755
index 0000000..d6ddaf1
--- /dev/null
+++ b/mbtk/test/liblynq_lib/lynq-qser-voice-demo.cpp
@@ -0,0 +1,303 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+#include <pthread.h>
+#include <unistd.h>
+#include <dlfcn.h>
+#include <stdint.h>
+
+#include"lynq-qser-voice-demo.h"
+
+typedef struct
+{
+ int cmdIdx;
+ char *funcName;
+} st_api_test_case;
+
+//for server test
+st_api_test_case at_api_testcases[] =
+{
+ {0, "print_help"},
+ {1, "qser_voice_call_start"},
+ {2, "qser_voice_call_end"},
+ {3, "qser_voice_call_answer"},
+ {4, "qser_voice_set_speech_volume"},
+ {5, "qser_voice_get_speech_volume"},
+ {6, "qser_voice_set_dtmf"},
+ {-1, NULL}
+};
+
+
+
+typedef uint32_t voice_client_handle_type;
+
+
+int (*qser_voice_call_client_init)(voice_client_handle_type *ph_voice);
+int (*qser_voice_call_client_deinit)(voice_client_handle_type );
+int (*qser_voice_call_addstatehandler)(voice_client_handle_type h_voice,
+ QSER_VoiceCall_StateHandlerFunc_t handlerPtr,
+ void *contextPtr);
+
+int (*qser_voice_call_removestatehandle)(voice_client_handle_type );
+int (*qser_voice_call_start)(voice_client_handle_type h_voice,
+ E_QSER_VCALL_ID_T simId,
+ char *phone_number, int *call_id);
+
+int (*qser_voice_call_end)(voice_client_handle_type ,int );
+int (*qser_voice_call_answer)(voice_client_handle_type ,int );
+int (*qser_voice_set_speech_volume)(const int volume);
+int (*qser_voice_get_speech_volume)(int *volume);
+int (*qser_voice_set_dtmf)(const char callnum);
+
+void *dlHandle_call = NULL;
+
+static void yk_voice_call_cb_func(int call_id,
+ char* phone_num,
+ qser_voice_call_state_t state,
+ void *contextPtr)
+{
+ char *call_state[] = {"INCOMING", "DIALING", "ALERTING", "ACTIVE", "HOLDING", "END", "WAITING"};
+
+ printf("######### Call id=%d, PhoneNum:%s, event=%s! ######\n", call_id, phone_num, call_state[state]);
+}
+
+void print_help(void)
+{
+ int i;
+ printf("Supported test cases:\n");
+ for(i = 0; ; i++)
+ {
+ if(at_api_testcases[i].cmdIdx == -1)
+ {
+ break;
+ }
+ printf("%d:\t%s\n", at_api_testcases[i].cmdIdx, at_api_testcases[i].funcName);
+ }
+}
+
+int main(int argc, char const *argv[])
+{
+ int cmdIdx = 0;
+ int ret = 0;
+ int voice_call_id = 0;
+ voice_client_handle_type h_voice = 0;
+
+ const char *lynqLibPath_Call = "/lib/liblynq-qser-voice.so";
+ dlHandle_call = dlopen(lynqLibPath_Call, RTLD_NOW);
+ if (dlHandle_call == NULL)
+ {
+ printf("dlopen dlHandle_call failed: %s\n", dlerror());
+ exit(EXIT_FAILURE);
+ }
+
+ qser_voice_call_client_init = (int(*)(voice_client_handle_type *ph_voice))dlsym(dlHandle_call, "qser_voice_call_client_init");
+ if(qser_voice_call_client_init == NULL)
+ {
+ printf("qser_voice_call_client_init not defined or exported in %s\n", lynqLibPath_Call);
+ return -1;
+ }
+
+ qser_voice_call_addstatehandler = (int(*)(voice_client_handle_type h_voice,
+ QSER_VoiceCall_StateHandlerFunc_t handlerPtr,
+ void *contextPtr))dlsym(dlHandle_call,"qser_voice_call_addstatehandler");
+ if(qser_voice_call_addstatehandler == NULL)
+ {
+ printf("qser_voice_call_addstatehandler not defined or exported in %s\n", lynqLibPath_Call);
+ return -1;
+ }
+
+ qser_voice_call_answer = (int(*)(voice_client_handle_type,int ))dlsym(dlHandle_call,"qser_voice_call_answer");
+ if(qser_voice_call_answer == NULL)
+ {
+ printf("qser_voice_call_answer not defined or exported in %s\n", lynqLibPath_Call);
+ return -1;
+ }
+
+ qser_voice_call_start = (int(*)(voice_client_handle_type h_voice,E_QSER_VCALL_ID_T simId,
+ char *phone_number, int *call_id))dlsym(dlHandle_call,"qser_voice_call_start");
+ if(qser_voice_call_start == NULL)
+ {
+ printf("qser_voice_call_start not defined or exported in %s\n", lynqLibPath_Call);
+ return -1;
+ }
+
+ qser_voice_call_end = (int(*)(voice_client_handle_type ,int))dlsym(dlHandle_call,"qser_voice_call_end");
+ if(qser_voice_call_end == NULL)
+ {
+ printf("qser_voice_call_end not defined or exported in %s\n", lynqLibPath_Call);
+ return -1;
+ }
+
+
+ qser_voice_call_client_deinit = (int (*)(voice_client_handle_type h_voice))dlsym(dlHandle_call,"qser_voice_call_client_deinit");
+ if(qser_voice_call_client_deinit == NULL)
+ {
+ printf("qser_voice_call_client_deinit not defined or exported in %s\n", lynqLibPath_Call);
+ return -1;
+ }
+
+ qser_voice_call_removestatehandle = (int (*)(voice_client_handle_type))dlsym(dlHandle_call,"qser_voice_call_removestatehandle");
+ if(qser_voice_call_removestatehandle == NULL)
+ {
+ printf("qser_voice_call_removestatehandle not defined or exported in %s\n", lynqLibPath_Call);
+ return -1;
+ }
+
+ qser_voice_set_speech_volume = (int (*)(const int ))dlsym(dlHandle_call,"qser_voice_set_speech_volume");
+ if(qser_voice_set_speech_volume == NULL)
+ {
+ printf("qser_voice_set_speech_volume not defined or exported in %s\n", lynqLibPath_Call);
+ return -1;
+ }
+
+ qser_voice_get_speech_volume = (int (*)(int* ))dlsym(dlHandle_call,"qser_voice_get_speech_volume");
+ if(qser_voice_get_speech_volume == NULL)
+ {
+ printf("qser_voice_get_speech_volume not defined or exported in %s\n", lynqLibPath_Call);
+ return -1;
+ }
+
+ qser_voice_set_dtmf = (int (*)(const char ))dlsym(dlHandle_call,"qser_voice_set_dtmf");
+ if(qser_voice_set_dtmf == NULL)
+ {
+ printf("qser_voice_set_dtmf not defined or exported in %s\n", lynqLibPath_Call);
+ return -1;
+ }
+
+ ret = qser_voice_call_client_init(&h_voice);
+ if(ret != 0 )
+ {
+ printf("qser_voice_call_client_init FAIL\n");
+ return -1;
+ }
+
+ ret = qser_voice_call_addstatehandler(h_voice, yk_voice_call_cb_func, &voice_call_id);
+ if(ret != 0)
+ {
+ printf("qser_voice_call_addstatehandler FAIL\n");
+ return -1;
+ }
+
+
+ print_help();
+ while(1)
+ {
+ printf("\nplease input cmd index(-1 exit): ");
+ scanf("%d", &cmdIdx);
+ if(cmdIdx == -1)
+ {
+ break;
+ }
+
+ switch(cmdIdx)
+ {
+ //"print_help
+ case 0:
+ print_help();
+ break;
+
+ //"qser_voice_call_start"
+ case 1:
+ {
+ char PhoneNum[32] = {0};
+
+ printf("please input dest phone number: \n");
+ scanf("%s", PhoneNum);
+
+ ret = qser_voice_call_start(h_voice, E_QSER_VCALL_EXTERNAL_SLOT_1, PhoneNum, &voice_call_id);
+ printf("qser_voice_call_start ret = %d, with voice_call_id=%d\n", ret, voice_call_id);
+ break;
+ }
+
+ //"qser_voice_call_end"
+ case 2:
+ {
+ int call_id = -1;
+ printf("please input end call id: \n");
+ scanf("%d", &call_id);
+ ret = qser_voice_call_end(h_voice, call_id);
+ printf(" ret = %d\n", ret);
+ break;
+ }
+
+ //"qser_voice_call_answer"
+ case 3:
+ {
+ int call_id = -1;
+ printf(" please input answer call id\n");
+ scanf("%d", &call_id);
+ ret = qser_voice_call_answer(h_voice, call_id);
+ printf(" ret = %d\n", ret);
+ break;
+ }
+
+ case 4:
+ {
+ int volume = 0;
+ printf("Please set speech volume:0-5 level\n");
+ scanf("%d",&volume);
+ ret = qser_voice_set_speech_volume(volume);
+ printf("ret is %d\n",ret);
+ break;
+
+ }
+
+ case 5:
+ {
+ int volume = -1;
+ printf("Enter get speech volume\n");
+ ret = qser_voice_get_speech_volume(&volume);
+ printf("ret is %d,get volume is %d\n",ret,volume);
+ break;
+
+ }
+ case 6:
+ {
+
+ int ret;
+ char inputChar;
+
+ printf("Enter set dtmf\n");
+ scanf(" %c", &inputChar);
+ printf("inputChar is %c\n", inputChar);
+ ret = qser_voice_set_dtmf(inputChar);
+
+ if (ret != 0)
+ {
+ printf("qser set voice dtmf failed\n");
+ return -1;
+ }
+ break;
+ }
+
+ default:
+ print_help();
+ break;
+ }
+
+ }
+
+ ret = qser_voice_call_removestatehandle(h_voice);
+ if(ret != 0 && ret != 1)
+ {
+ printf("qser_voice_call_removestatehandle FAIL!!!\n");
+ return -1;
+ }
+ printf("qser_voice_call_removestatehandle ret = %d\n", ret);
+
+
+ ret = qser_voice_call_client_deinit(h_voice);
+ if(ret != 0)
+ {
+ printf("qser_voice_call_client_deinit FAIL\n");
+ return -1;
+ }
+ printf("qser_voice_call_client_deinit ret = %d, with h_voice=%d\n", ret, h_voice);
+
+ return 0;
+
+
+}
+
+