1 /******************************************************************
3 * Copyright 2014 Samsung Electronics All Rights Reserved.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 ******************************************************************/
31 #include "caadapterinterface.h"
32 #include "uthreadpool.h"
34 #define MOD_NAME "TizenSample"
37 * Enable/disable one or more of the following macros to enable/disable
38 * functionality of that particular adapter type in the interfacesample.
40 //#define WIFI_ADAPTER_TEST
41 #define BT_ADAPTER_TEST
42 //#define BLE_ADAPTER_TEST
44 #if defined(WIFI_ADAPTER_TEST)
45 #include "cawifiadapter.h"
46 #include "caethernetadapter.h"
47 static u_thread_pool_t gWiFiThreadPool = NULL;
48 #elif defined(BT_ADAPTER_TEST)
49 #include "caedradapter.h"
50 static u_thread_pool_t gBTThreadPool = NULL;
51 #elif defined(BLE_ADAPTER_TEST)
52 #include "caleadapter.h"
53 static u_thread_pool_t gLEThreadPool = NULL;
56 static GMainLoop *mainloop;
57 static GIOChannel *channel;
58 static guint g_test_io_watch_id;
59 static GError *g_err_Sample;
61 static CALocalConnectivity_t *localWifiEndpoint = NULL;
62 //Hardcoded coap data for Test
63 static char coapData[500] =
64 "{\"oc:\[{href\":\"/a/light\",\"ref\":{\"power\":\"20\",\"state\":\"true\"}}]}";
66 void testInitializeBTInterface(void);
67 void testTerminateBTInterface(void);
68 void testInitializeWIFIInterface(void);
69 void testTerminateWIFIInterface(void);
70 void testInitializeBLEInterface(void);
71 void testTerminateBLEInterface(void);
73 typedef struct ConnectivityHandlerList
75 CAConnectivityType_t type;
76 CAConnectivityHandler_t handler;
77 struct ConnectivityHandlerList *nextHandler;
78 } ConnectivityHandlerList;
80 static ConnectivityHandlerList *gConnectivityHandlers = NULL;
82 void initializeThreadPool(CAConnectivityType_t type)
84 #ifdef BT_ADAPTER_TEST
85 if (CA_EDR == type && NULL == gBTThreadPool)
87 if (CA_STATUS_OK != u_thread_pool_init(3, &gBTThreadPool))
89 printf("Failed to create thread pool for BT adapter!\n");
94 #ifdef WIFI_ADAPTER_TEST
95 if (CA_WIFI == type && NULL == gWiFiThreadPool)
97 if (CA_STATUS_OK != u_thread_pool_init(3, &gWiFiThreadPool))
99 printf("Failed to create thread pool for BT adapter!\n");
104 #ifdef BLE_ADAPTER_TEST
105 if (CA_LE == type && NULL == gLEThreadPool)
107 if (CA_STATUS_OK != u_thread_pool_init(3, &gLEThreadPool))
109 printf("Failed to create thread pool for BT adapter!\n");
117 void storeInterfaceCallbacks(ConnectivityHandlerList *newHandler)
119 printf("storeInterfaceCallbacks Entry in Sample\n");
120 newHandler->nextHandler = NULL;
121 ConnectivityHandlerList *tempConnectivityHandlers = gConnectivityHandlers;
123 if (!tempConnectivityHandlers)
125 gConnectivityHandlers = newHandler;
126 printf("storeInterfaceCallbacks Exit in Sample\n");
130 while (tempConnectivityHandlers->nextHandler)
132 tempConnectivityHandlers = tempConnectivityHandlers->nextHandler;
135 tempConnectivityHandlers->nextHandler = newHandler;
136 printf("storeInterfaceCallbacks Exit in Sample\n");
139 void interfaceRegisterCallback(CAConnectivityHandler_t handler,
140 CAConnectivityType_t connType)
142 printf("interfaceRegisterCallback Entry in Sample\n");
143 ConnectivityHandlerList *newConnectivityHandler = (ConnectivityHandlerList *) malloc(sizeof(
144 ConnectivityHandlerList));
145 if (NULL == newConnectivityHandler)
147 printf("Memory allocation failed\n");
151 newConnectivityHandler->type = connType;
152 newConnectivityHandler->handler = handler;
153 storeInterfaceCallbacks(newConnectivityHandler);
154 printf("interfaceRegisterCallback Exit in Sample\n");
157 void networkPacketHandler(CARemoteEndpoint_t *object, void *data, uint32_t dataLength)
159 printf("networkPacketHandler Entry in Sample\n");
160 if (object == NULL || data == NULL)
162 printf("NULL Object\n");
166 printf("Data Received from: ");
167 if (CA_EDR == object->connectivityType)
169 printf(object->addressInfo.BT.btMacAddress);
171 else if (CA_LE == object->connectivityType)
173 printf(object->addressInfo.LE.leMacAddress);
175 else if (CA_WIFI == object->connectivityType || CA_ETHERNET == object->connectivityType)
177 printf(object->addressInfo.IP.ipAddress);
180 printf("\nReceived Data [Length: %d]: %s\n", dataLength, (char *)data);
181 printf("networkPacketHandler Exit in Sample\n");
184 void networkInterfaceCallback(CALocalConnectivity_t *localEndPoint,
185 CANetworkStatus_t networkConnectivityState)
187 printf("networkInterfaceCallback Entry in Sample\n");
188 if (localEndPoint == NULL)
190 printf("NULL Object\n");
194 if (networkConnectivityState == CA_INTERFACE_UP)
196 printf("Network Status is UP\n");
200 printf("Network Status is DOWN\n");
204 if (CA_EDR == localEndPoint->type)
206 printf("%s\n", localEndPoint->addressInfo.BT.btMacAddress);
208 else if (CA_LE == localEndPoint->type)
210 printf("%s\n", localEndPoint->addressInfo.LE.leMacAddress);
212 else if (CA_WIFI == localEndPoint->type || CA_ETHERNET == localEndPoint->type)
214 printf("%s\n", localEndPoint->addressInfo.IP.ipAddress);
217 printf("networkInterfaceCallback Exit in Sample\n");
221 void freeData(void *data)
223 printf("freeData Entry in Sample\n");
228 printf("freeData Exit in Sample\n");
231 int16_t selectConnectivityType()
234 printf("*******Select the Connectivity Type*******\n");
235 printf(" [1] WIFI \n");
236 printf(" [2] BT \n");
237 printf(" [3] BLE \n");
241 if (cType < 1 && cType > 3)
243 printf("Invalid Selection!!!!\n");
246 return (int16_t)cType;
249 int16_t interfaceStartAdapter(CAConnectivityType_t connType)
251 ConnectivityHandlerList *tempConnectivityHandlers = gConnectivityHandlers;
252 if (NULL == tempConnectivityHandlers)
254 printf("None of the interface is initialized\n");
258 while (tempConnectivityHandlers && tempConnectivityHandlers->type != connType)
260 tempConnectivityHandlers = tempConnectivityHandlers->nextHandler;
263 if (NULL == tempConnectivityHandlers)
265 printf( "No interface handler for type %d", connType);
269 if (CA_STATUS_OK != tempConnectivityHandlers->handler.startAdapter())
271 printf("Failed to Start adapter\n");
278 int16_t interfaceMulticastStartServer(CAConnectivityType_t connType, int serverType)
280 printf("interfaceMulticastStartServer Starting...\n");
281 ConnectivityHandlerList *tempConnectivityHandlers = gConnectivityHandlers;
282 if (NULL == tempConnectivityHandlers)
284 printf("None of the interface is initialized\n");
288 while (tempConnectivityHandlers && tempConnectivityHandlers->type != connType)
290 tempConnectivityHandlers = tempConnectivityHandlers->nextHandler;
293 if (NULL == tempConnectivityHandlers)
295 printf( "No interface handler for type %d", connType);
299 CAAdapterStartDiscoveryServer startServer = NULL;
302 case 1: //Discovery server
303 startServer = tempConnectivityHandlers->handler.startDiscoverServer;
305 case 2: //Listening server
306 startServer = tempConnectivityHandlers->handler.startListenServer;
312 printf("Invoking start server method\n");
317 int16_t interfaceSendUnicastData(CAConnectivityType_t connType)
319 ConnectivityHandlerList *tempConnectivityHandlers = gConnectivityHandlers;
320 if (NULL == tempConnectivityHandlers)
322 printf(" None of the interface is initialized \n");
326 while (tempConnectivityHandlers && tempConnectivityHandlers->type != connType)
328 tempConnectivityHandlers = tempConnectivityHandlers->nextHandler;
331 if (NULL == tempConnectivityHandlers)
333 printf( "No interface handler for type %d", connType);
337 if (CA_WIFI == connType)
339 CARemoteEndpoint_t endpoint;
340 char remoteIPAddress[CA_IPADDR_SIZE] = {0};
341 printf("\nEnter the Remote Endpoint IP: ");
342 scanf("%s", remoteIPAddress);
343 if (strlen(remoteIPAddress) == 0)
345 printf("Invalid device address\n");
348 endpoint.connectivityType = CA_WIFI;
349 strncpy(endpoint.addressInfo.IP.ipAddress, remoteIPAddress, CA_IPADDR_SIZE);
350 endpoint.addressInfo.IP.port = 5283; /* Send the corresponding port here */
352 int sdatalen = tempConnectivityHandlers->handler.sendData(&endpoint, coapData,
354 if (sdatalen == strlen(coapData))
356 printf("Send Unicast data success\n");
360 printf("Send Unicast data failed\n");
363 else if (CA_EDR == connType)
366 CARemoteEndpoint_t endpoint;
368 //Get the device address from user
369 char deviceaddress[100] = {0};
370 printf("Enter the device address: \n");
371 scanf("%s", deviceaddress);
373 if (strlen(deviceaddress) == 0)
375 printf("Invlaid device address\n");
379 endpoint.connectivityType = CA_EDR;
380 strncpy(endpoint.addressInfo.BT.btMacAddress, deviceaddress, CA_MACADDR_SIZE - 1);
381 endpoint.addressInfo.BT.btMacAddress[CA_MACADDR_SIZE - 1] = '\0';
382 endpoint.resourceUri = NULL;
384 printf("Sent Unicast data to device: %s\n", endpoint.addressInfo.BT.btMacAddress);
385 tempConnectivityHandlers->handler.sendData(&endpoint, coapData, strlen(coapData) + 1);
387 else if (CA_LE == connType)
390 CARemoteEndpoint_t endpoint;
392 //Get the device address from user
393 char deviceaddress[100] = {0};
394 printf("Enter the device address: \n");
395 scanf("%s", deviceaddress);
397 if (strlen(deviceaddress) == 0)
399 printf("Invlaid device address\n");
403 //Get the service uuid from user
404 char uuid[100] = {0};
405 printf("Enter the service uuid: \n");
408 if (strlen(uuid) == 0)
410 printf("Invlaid service uuid\n");
414 endpoint.connectivityType = CA_LE;
415 strncpy(endpoint.addressInfo.BT.btMacAddress, deviceaddress, CA_MACADDR_SIZE - 1);
416 endpoint.addressInfo.BT.btMacAddress[CA_MACADDR_SIZE - 1] = '\0';
417 endpoint.resourceUri = strdup(uuid);
419 tempConnectivityHandlers->handler.sendData(&endpoint, coapData, strlen(coapData));
420 printf("Sent Unicast data \n");
421 free(endpoint.resourceUri);
427 int16_t interfaceSendMulticastData(CAConnectivityType_t connType)
429 ConnectivityHandlerList *tempConnectivityHandlers = gConnectivityHandlers;
430 if (NULL == tempConnectivityHandlers)
432 printf("None of the interface is initialized\n");
436 while (tempConnectivityHandlers && tempConnectivityHandlers->type != connType)
438 tempConnectivityHandlers = tempConnectivityHandlers->nextHandler;
441 if (NULL == tempConnectivityHandlers)
443 printf( "No interface handler for type %d", connType);
447 if (connType == CA_WIFI)
449 tempConnectivityHandlers->handler.sendDataToAll(coapData,
450 strlen(coapData) + 1);
452 else if (connType == CA_EDR || connType == CA_LE)
454 tempConnectivityHandlers->handler.sendDataToAll(coapData, strlen(coapData));
458 void interfaceReadData(CAConnectivityType_t connType)
460 ConnectivityHandlerList *tempConnectivityHandlers = gConnectivityHandlers;
461 if (NULL == tempConnectivityHandlers)
463 printf("None of the interface is initialized\n");
467 while (tempConnectivityHandlers && tempConnectivityHandlers->type != connType)
469 tempConnectivityHandlers = tempConnectivityHandlers->nextHandler;
472 if (NULL == tempConnectivityHandlers)
474 printf( "No interface handler for type %d", connType);
478 if (CA_STATUS_OK != tempConnectivityHandlers->handler.readData())
480 printf("Failed to Read Data\n");
484 printf("Read Data is successfull\n");
488 void interfaceGetNetworkInfo(CAConnectivityType_t connType)
492 ConnectivityHandlerList *tempConnectivityHandlers = gConnectivityHandlers;
493 if (NULL == tempConnectivityHandlers)
495 printf("None of the interface is initialized\n");
499 while (tempConnectivityHandlers && tempConnectivityHandlers->type != connType)
501 tempConnectivityHandlers = tempConnectivityHandlers->nextHandler;
504 if (NULL == tempConnectivityHandlers)
506 printf( "No interface handler for type %d", connType);
510 //Get the network interface info
511 CALocalConnectivity_t *info = NULL;
513 if (CA_STATUS_OK != tempConnectivityHandlers->handler.GetnetInfo(&info, &size))
515 printf("Failed to get network info\n");
519 if (0 >= size || info == NULL)
521 printf("No network found !!!\n");
525 printf("Network Information: \n");
526 for (; i < size; i++)
528 if (connType == CA_WIFI)
530 printf("Type : %s\n", (connType == CA_ETHERNET) ? "CA_ETHERNET" : "CA_WIFI");
531 printf("Address : %s\n", info[i].addressInfo.IP.ipAddress);
535 printf("Type : %s\n", (connType == CA_EDR) ? "CA_EDR" : "CA_LE");
536 printf("Address : %s\n\n", info[i].addressInfo.BT.btMacAddress);
541 int16_t interfaceStopAdapter(CAConnectivityType_t connType)
543 ConnectivityHandlerList *tempConnectivityHandlers = gConnectivityHandlers;
544 if (NULL == tempConnectivityHandlers)
546 printf("None of the interface is initialized\n");
550 while (tempConnectivityHandlers && tempConnectivityHandlers->type != connType)
552 tempConnectivityHandlers = tempConnectivityHandlers->nextHandler;
555 if (NULL == tempConnectivityHandlers)
557 printf( "No interface handler for type %d", connType);
561 if (CA_STATUS_OK != tempConnectivityHandlers->handler.stopAdapter())
563 printf("Failed to Stop adapter\n");
567 printf("Stopped the adapter\n");
571 void testInitializeInterface()
573 printf("testInitializeInterface Entry\n");
575 int16_t type = selectConnectivityType();
576 if (0 >= type || 3 < type)
578 printf("Invalid selection...\n");
584 #ifdef WIFI_ADAPTER_TEST
587 testInitializeWIFIInterface();
591 #ifdef BT_ADAPTER_TEST
594 testInitializeBTInterface();
598 #ifdef BLE_ADAPTER_TEST
601 testInitializeBLEInterface();
606 printf("Feature is not enabled or not implemented\n");
610 void testTerminateInterface()
612 int16_t type = selectConnectivityType();
613 if (0 >= type || 3 < type)
615 printf("Invalid selection...\n");
619 #ifdef WIFI_ADAPTER_TEST
620 if (1 == type) /* WIFI */
622 testTerminateWIFIInterface();
625 #ifdef BT_ADAPTER_TEST
626 if (2 == type) /*BT*/
628 testTerminateBTInterface();
631 #ifdef BLE_ADAPTER_TEST
632 if (3 == type) /*BLE*/
634 testTerminateBLEInterface();
638 ConnectivityHandlerList *currentConnectivityHandler = gConnectivityHandlers;
639 ConnectivityHandlerList *prevConnectivityHandler = NULL;
641 printf("Linked list delete start\n");
642 while (currentConnectivityHandler != NULL)
644 printf("Iterating through the list to find the matching interface\n");
645 if (currentConnectivityHandler->type == type)
647 printf("Matching interface found\n");
648 if (prevConnectivityHandler == NULL)
650 currentConnectivityHandler = currentConnectivityHandler->nextHandler;
651 freeData(gConnectivityHandlers);
652 gConnectivityHandlers = NULL;
653 printf( "Node deleted with interface type %d", type);
657 prevConnectivityHandler->nextHandler = currentConnectivityHandler->nextHandler;
658 freeData(currentConnectivityHandler);
659 currentConnectivityHandler = prevConnectivityHandler->nextHandler;
660 printf( "Node deleted with interface type %d from linked list", type);
665 prevConnectivityHandler = currentConnectivityHandler;
666 currentConnectivityHandler = currentConnectivityHandler->nextHandler;
669 gConnectivityHandlers = NULL;
673 void testStartAdapter()
675 int type = selectConnectivityType();
676 if (0 >= type || 3 < type)
678 printf("Invalid selection...\n");
684 #ifdef WIFI_ADAPTER_TEST
687 interfaceStartAdapter(CA_WIFI);
691 #ifdef BT_ADAPTER_TEST
694 interfaceStartAdapter(CA_EDR);
698 #ifdef BLE_ADAPTER_TEST
701 interfaceStartAdapter(CA_LE);
706 printf("Feature is not enabled or not implemented\n");
710 void testStartServer(int serverType)
712 int type = selectConnectivityType();
713 if (0 >= type || 3 < type)
715 printf("Invalid selection...\n");
721 #ifdef WIFI_ADAPTER_TEST
724 interfaceMulticastStartServer(CA_WIFI, serverType);
728 #ifdef BT_ADAPTER_TEST
731 interfaceMulticastStartServer(CA_EDR, serverType);
735 #ifdef BLE_ADAPTER_TEST
738 interfaceMulticastStartServer(CA_LE, serverType);
743 printf("Feature is not enabled or not implemented\n");
747 void testSendUnicastData()
749 int16_t type = selectConnectivityType();
750 if (0 >= type || 3 < type)
752 printf("Invalid selection...\n");
758 #ifdef WIFI_ADAPTER_TEST
761 interfaceSendUnicastData(CA_WIFI);
765 #ifdef BT_ADAPTER_TEST
768 interfaceSendUnicastData(CA_EDR);
772 #ifdef BLE_ADAPTER_TEST
775 interfaceSendUnicastData(CA_LE);
780 printf("Feature is not enabled or not implemented\n");
784 void testSendMulticastData()
786 int16_t type = selectConnectivityType();
787 if (0 >= type || 3 < type)
789 printf("Invalid selection...\n");
795 #ifdef WIFI_ADAPTER_TEST
798 interfaceSendMulticastData(CA_WIFI);
802 #ifdef BT_ADAPTER_TEST
805 interfaceSendMulticastData(CA_EDR);
809 #ifdef BLE_ADAPTER_TEST
812 interfaceSendMulticastData(CA_LE);
817 printf("Feature is not enabled or not implemented\n");
821 void testReadData(void)
823 int16_t type = selectConnectivityType();
824 if (0 >= type || 3 < type)
826 printf("Invalid selection...\n");
832 #ifdef WIFI_ADAPTER_TEST
835 interfaceReadData(CA_WIFI);
839 #ifdef BT_ADAPTER_TEST
842 interfaceReadData(CA_EDR);
846 #ifdef BLE_ADAPTER_TEST
849 interfaceReadData(CA_LE);
854 printf("Feature is not enabled or not implemented\n");
858 void testGetNetworkInfo(void)
860 int16_t type = selectConnectivityType();
861 if (0 >= type || 3 < type)
863 printf("Invalid selection...\n");
869 #ifdef WIFI_ADAPTER_TEST
872 interfaceGetNetworkInfo(CA_WIFI);
876 #ifdef BT_ADAPTER_TEST
879 interfaceGetNetworkInfo(CA_EDR);
883 #ifdef BLE_ADAPTER_TEST
886 interfaceGetNetworkInfo(CA_LE);
891 printf("Feature is not enabled or not implemented\n");
895 void testStopAdapter()
897 int16_t type = selectConnectivityType();
898 if (0 >= type || 3 < type)
900 printf("Invalid selection...\n");
906 #ifdef WIFI_ADAPTER_TEST
909 interfaceStopAdapter(CA_WIFI);
913 #ifdef BT_ADAPTER_TEST
916 interfaceStopAdapter(CA_EDR);
920 #ifdef BLE_ADAPTER_TEST
923 interfaceStopAdapter(CA_LE);
928 printf("Feature is not enabled or not implemented\n");
932 #ifdef BT_ADAPTER_TEST
933 void testInitializeBTInterface(void)
935 printf("Initiazing EDR\n");
937 printf("Initializing BT Adapter threadpool\n");
938 initializeThreadPool(CA_EDR);
940 //Start bluetooth communication adapter
941 CAResult_t err = CAInitializeEDR(interfaceRegisterCallback, networkPacketHandler,
942 networkInterfaceCallback, gBTThreadPool);
943 if (CA_STATUS_OK != err && CA_ADAPTER_NOT_ENABLED != err)
945 printf("Failed to initialize bluetooth communication adapter!\n");
949 void testTerminateBTInterface(void)
951 printf("Terminating EDR\n");
953 //Terminate the Bluetooth communication adapter
956 printf( "Terminating BT Adapter thread pool");
957 u_thread_pool_free(gBTThreadPool);
959 #endif //BT_ADAPTER_TEST
961 #ifdef WIFI_ADAPTER_TEST
962 void testInitializeWIFIInterface(void)
964 printf("testInitializeWIFIInterface IN\n");
966 printf("Initializing WIFI adapter threadpool\n");
967 initializeThreadPool(CA_WIFI);
969 //Start Wifi communication adapter
970 if (0 != CAInitializeWifi(interfaceRegisterCallback, networkPacketHandler,
971 networkInterfaceCallback, gWiFiThreadPool))
973 printf("testInitializeWIFIInterface Failed to initialize bluetooth communication adapter\n");
977 printf("testInitializeWIFIInterface OUT\n");
980 void testTerminateWIFIInterface(void)
982 printf("testTerminateWIFIInterface IN\n");
984 // Stop if Wifi communication adapter is running
985 interfaceStopAdapter(CA_WIFI);
987 // Freeing threadpool for wifi communication adapter
988 printf( "Terminating WIFI Adapter thread pool");
989 u_thread_pool_free(gWiFiThreadPool);
991 //Terminate the Wifi communication adapter
995 printf("testTerminateWIFIInterface OUT\n");
997 #endif //WIFI_ADAPTER_TEST
999 #ifdef BLE_ADAPTER_TEST
1000 void testInitializeBLEInterface(void)
1002 printf("testInitializeBLEInterface IN\n");
1004 printf("Initializing BLE adapter threadpool\n");
1005 initializeThreadPool(CA_LE);
1007 //Start bluetooth communication adapter
1008 if (0 != CAInitializeLE(interfaceRegisterCallback, networkPacketHandler,
1009 networkInterfaceCallback, gLEThreadPool))
1011 printf("testInitializeBLEInterface Failed due to CAInitializeLE\n");
1015 printf("testInitializeBLEInterface OUT\n");
1018 void testTerminateBLEInterface(void)
1020 printf("testTerminateBLEInterface IN\n");
1022 //Terminate the BLE server & Client
1025 printf( "Terminating BLE Adapter thread pool");
1026 u_thread_pool_free(gLEThreadPool);
1028 printf("testTerminateBLEInterface OUT\n");
1030 #endif //BLE_ADAPTER_TEST
1032 static void testPrintHelp(void)
1034 printf(" =====================================================================\n");
1035 printf("| Welcome to Connectivity Abstraction |\n");
1036 printf("| - CA Unit Test v1.0 - |\n");
1037 printf("|---------------------------------------------------------------------|\n");
1038 printf("| ** Options ** |\n");
1039 printf("| i - Initialize the Interface |\n");
1040 printf("| d - Terminate the Interface |\n");
1041 printf("| a - Start adapter |\n");
1042 printf("| b - Stop adapter |\n");
1043 printf("| sd- Start Discovery Server |\n");
1044 printf("| sl- Start Listening Server |\n");
1045 printf("| u - Send Unicast Data |\n");
1046 printf("| m - Send Multicast Data |\n");
1047 printf("| g - Get Network Info |\n");
1048 printf("| r - Read data synchronously |\n");
1049 printf("| x - quit the test. |\n");
1050 printf("| h - Help menu. |\n");
1051 printf(" =====================================================================\n");
1054 static gboolean testThread(GIOChannel *source, GIOCondition condition , gpointer data)
1056 gchar buf[10] = {'\0'};
1060 if (g_io_channel_read(channel, buf, 10, &read) != G_IO_ERROR_NONE)
1062 printf("g_io_channel_read error!!!\n");
1068 /*if ((!has_register) && (((buf[0]!= 'i') && (buf[0]!= 'h') && (buf[0]!= 'q')) || (read != 2))) {
1070 printf("***Warning***: You should Register firstly!\n");
1076 testInitializeInterface();
1079 testTerminateInterface();
1080 if (g_source_remove(g_test_io_watch_id))
1082 printf("g_source_remove() OK!!!\n");
1083 g_io_channel_shutdown(channel, TRUE, &g_err_Sample);
1084 g_io_channel_unref(channel);
1085 g_main_loop_quit(mainloop);
1089 testTerminateInterface();
1111 testSendUnicastData();
1114 testSendMulticastData();
1120 testGetNetworkInfo();
1128 int main(int argc, char *argv[])
1130 printf("Starting sample\n");
1131 mainloop = g_main_loop_new(NULL, FALSE);
1132 channel = g_io_channel_unix_new(0);/* read from stdin */
1133 g_test_io_watch_id = g_io_add_watch(channel,
1134 (GIOCondition)(G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL), testThread,
1136 printf("CM Test Thread created...\n");
1138 g_main_loop_run(mainloop);