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"
36 #if defined(WIFI_ADAPTER_TEST)
37 #include "cawifiadapter.h"
38 static u_thread_pool_t gWiFiThreadPool = NULL;
40 #if defined(BT_ADAPTER_TEST)
41 #include "caedradapter.h"
42 static u_thread_pool_t gBTThreadPool = NULL;
44 #if defined(BLE_ADAPTER_TEST)
45 #include "caleadapter.h"
46 static u_thread_pool_t gLEThreadPool = NULL;
49 static GMainLoop *mainloop = NULL;
50 static GIOChannel *channel = NULL;
51 static guint g_test_io_watch_id = 0;
52 static GError *g_err_Sample = NULL;
54 static CALocalConnectivity_t *localWifiEndpoint = NULL;
55 //Hardcoded coap data for Test
56 static char coapData[500] =
57 "{\"oc:\[{href\":\"/a/light\",\"ref\":{\"power\":\"20\",\"state\":\"true\"}}]}";
59 void testInitializeBTInterface(void);
60 void testTerminateBTInterface(void);
61 void testInitializeWIFIInterface(void);
62 void testTerminateWIFIInterface(void);
63 void testInitializeBLEInterface(void);
64 void testTerminateBLEInterface(void);
66 typedef struct ConnectivityHandlerList
68 CAConnectivityType_t type;
69 CAConnectivityHandler_t handler;
70 struct ConnectivityHandlerList *nextHandler;
71 } ConnectivityHandlerList;
73 static ConnectivityHandlerList *gConnectivityHandlers = NULL;
75 void initializeThreadPool(CAConnectivityType_t type)
77 #ifdef BT_ADAPTER_TEST
78 if (CA_EDR == type && NULL == gBTThreadPool)
80 if (CA_STATUS_OK != u_thread_pool_init(3, &gBTThreadPool))
82 printf("Failed to create thread pool for BT adapter!\n");
87 #ifdef WIFI_ADAPTER_TEST
88 if (CA_WIFI == type && NULL == gWiFiThreadPool)
90 if (CA_STATUS_OK != u_thread_pool_init(3, &gWiFiThreadPool))
92 printf("Failed to create thread pool for WIFI adapter!\n");
97 #ifdef BLE_ADAPTER_TEST
98 if (CA_LE == type && NULL == gLEThreadPool)
100 if (CA_STATUS_OK != u_thread_pool_init(5, &gLEThreadPool))
102 printf("Failed to create thread pool for BLE adapter!\n");
110 void storeInterfaceCallbacks(ConnectivityHandlerList *newHandler)
112 printf("storeInterfaceCallbacks Entry in Sample\n");
113 newHandler->nextHandler = NULL;
114 ConnectivityHandlerList *tempConnectivityHandlers = gConnectivityHandlers;
116 if (!tempConnectivityHandlers)
118 gConnectivityHandlers = newHandler;
119 printf("storeInterfaceCallbacks Exit in Sample\n");
123 while (tempConnectivityHandlers->nextHandler)
125 tempConnectivityHandlers = tempConnectivityHandlers->nextHandler;
128 tempConnectivityHandlers->nextHandler = newHandler;
129 printf("storeInterfaceCallbacks Exit in Sample\n");
132 void interfaceRegisterCallback(CAConnectivityHandler_t handler,
133 CAConnectivityType_t connType)
135 printf("interfaceRegisterCallback Entry in Sample\n");
136 ConnectivityHandlerList *newConnectivityHandler = (ConnectivityHandlerList *) malloc(sizeof(
137 ConnectivityHandlerList));
138 if (NULL == newConnectivityHandler)
140 printf("Memory allocation failed\n");
144 newConnectivityHandler->type = connType;
145 newConnectivityHandler->handler = handler;
146 storeInterfaceCallbacks(newConnectivityHandler);
147 printf("interfaceRegisterCallback Exit in Sample\n");
150 void networkPacketHandler(CARemoteEndpoint_t *object, void *data, uint32_t dataLength)
152 printf("networkPacketHandler Entry in Sample\n");
153 if (object == NULL || data == NULL)
155 printf("NULL Object\n");
159 printf("Data Received from: ");
160 if (CA_EDR == object->connectivityType)
162 printf(object->addressInfo.BT.btMacAddress);
164 else if (CA_LE == object->connectivityType)
166 printf(object->addressInfo.LE.leMacAddress);
168 else if (CA_WIFI == object->connectivityType || CA_ETHERNET == object->connectivityType)
170 printf(object->addressInfo.IP.ipAddress);
173 printf("\nReceived Data [Length: %d]: %s\n", dataLength, (char *)data);
174 printf("networkPacketHandler Exit in Sample\n");
177 void networkInterfaceCallback(CALocalConnectivity_t *localEndPoint,
178 CANetworkStatus_t networkConnectivityState)
180 printf("networkInterfaceCallback Entry in Sample\n");
181 if (localEndPoint == NULL)
183 printf("NULL Object\n");
187 if (networkConnectivityState == CA_INTERFACE_UP)
189 printf("Network Status is UP\n");
193 printf("Network Status is DOWN\n");
197 if (CA_EDR == localEndPoint->type)
199 printf("%s\n", localEndPoint->addressInfo.BT.btMacAddress);
201 else if (CA_LE == localEndPoint->type)
203 printf("%s\n", localEndPoint->addressInfo.LE.leMacAddress);
205 else if (CA_WIFI == localEndPoint->type || CA_ETHERNET == localEndPoint->type)
207 printf("%s\n", localEndPoint->addressInfo.IP.ipAddress);
210 printf("networkInterfaceCallback Exit in Sample\n");
214 void freeData(void *data)
216 printf("freeData Entry in Sample\n");
221 printf("freeData Exit in Sample\n");
224 int16_t selectConnectivityType()
227 printf("*******Select the Connectivity Type*******\n");
228 printf(" [1] WIFI \n");
229 printf(" [2] BT \n");
230 printf(" [3] BLE \n");
234 if (cType < 1 && cType > 3)
236 printf("Invalid Selection!!!!\n");
239 return (int16_t)cType;
242 int16_t interfaceStartAdapter(CAConnectivityType_t connType)
244 ConnectivityHandlerList *tempConnectivityHandlers = gConnectivityHandlers;
245 if (NULL == tempConnectivityHandlers)
247 printf("None of the interface is initialized\n");
251 while (tempConnectivityHandlers && tempConnectivityHandlers->type != connType)
253 tempConnectivityHandlers = tempConnectivityHandlers->nextHandler;
256 if (NULL == tempConnectivityHandlers)
258 printf( "No interface handler for type %d", connType);
262 if (CA_STATUS_OK != tempConnectivityHandlers->handler.startAdapter())
264 printf("Failed to Start adapter\n");
271 int16_t interfaceMulticastStartServer(CAConnectivityType_t connType, int serverType)
273 printf("interfaceMulticastStartServer Starting...\n");
274 ConnectivityHandlerList *tempConnectivityHandlers = gConnectivityHandlers;
275 if (NULL == tempConnectivityHandlers)
277 printf("None of the interface is initialized\n");
281 while (tempConnectivityHandlers && tempConnectivityHandlers->type != connType)
283 tempConnectivityHandlers = tempConnectivityHandlers->nextHandler;
286 if (NULL == tempConnectivityHandlers)
288 printf( "No interface handler for type %d", connType);
292 CAAdapterStartDiscoveryServer startServer = NULL;
295 case 1: //Discovery server
296 startServer = tempConnectivityHandlers->handler.startDiscoverServer;
298 case 2: //Listening server
299 startServer = tempConnectivityHandlers->handler.startListenServer;
305 printf("Invoking start server method\n");
310 int16_t interfaceSendUnicastData(CAConnectivityType_t connType)
312 ConnectivityHandlerList *tempConnectivityHandlers = gConnectivityHandlers;
313 if (NULL == tempConnectivityHandlers)
315 printf(" None of the interface is initialized \n");
319 while (tempConnectivityHandlers && tempConnectivityHandlers->type != connType)
321 tempConnectivityHandlers = tempConnectivityHandlers->nextHandler;
324 if (NULL == tempConnectivityHandlers)
326 printf( "No interface handler for type %d", connType);
330 if (CA_WIFI == connType)
332 CARemoteEndpoint_t endpoint;
333 char remoteIPAddress[CA_IPADDR_SIZE] = {0};
334 printf("\nEnter the Remote Endpoint IP: ");
335 scanf("%s", remoteIPAddress);
336 if (strlen(remoteIPAddress) == 0)
338 printf("Invalid device address\n");
341 endpoint.connectivityType = CA_WIFI;
342 strncpy(endpoint.addressInfo.IP.ipAddress, remoteIPAddress, CA_IPADDR_SIZE);
343 endpoint.addressInfo.IP.port = 5683; /* Send the corresponding port here */
345 int sdatalen = tempConnectivityHandlers->handler.sendData(&endpoint, coapData,
347 if (sdatalen == strlen(coapData))
349 printf("Send Unicast data success\n");
353 printf("Send Unicast data failed\n");
356 else if (CA_EDR == connType)
359 CARemoteEndpoint_t endpoint;
361 //Get the device address from user
362 char deviceaddress[100] = {0};
363 printf("Enter the device address: \n");
364 scanf("%s", deviceaddress);
366 if (strlen(deviceaddress) == 0)
368 printf("Invlaid device address\n");
372 endpoint.connectivityType = CA_EDR;
373 strncpy(endpoint.addressInfo.BT.btMacAddress, deviceaddress, CA_MACADDR_SIZE - 1);
374 endpoint.addressInfo.BT.btMacAddress[CA_MACADDR_SIZE - 1] = '\0';
375 endpoint.resourceUri = NULL;
377 printf("Sent Unicast data to device: %s\n", endpoint.addressInfo.BT.btMacAddress);
378 tempConnectivityHandlers->handler.sendData(&endpoint, coapData, strlen(coapData) + 1);
380 else if (CA_LE == connType)
383 CARemoteEndpoint_t endpoint;
385 //Get the device address from user
386 char deviceaddress[100] = {0};
387 printf("Enter the device address: \n");
388 scanf("%s", deviceaddress);
390 if (strlen(deviceaddress) == 0)
392 printf("Invlaid device address\n");
396 //Get the service uuid from user
397 char uuid[100] = {0};
398 printf("Enter the service uuid: \n");
401 if (strlen(uuid) == 0)
403 printf("Invlaid service uuid\n");
407 endpoint.connectivityType = CA_LE;
408 strncpy(endpoint.addressInfo.LE.leMacAddress, deviceaddress, CA_MACADDR_SIZE - 1);
409 endpoint.addressInfo.LE.leMacAddress[CA_MACADDR_SIZE - 1] = '\0';
410 endpoint.resourceUri = strdup(uuid);
412 tempConnectivityHandlers->handler.sendData(&endpoint, coapData, strlen(coapData));
413 printf("Sent Unicast data \n");
414 free(endpoint.resourceUri);
420 int16_t interfaceSendMulticastData(CAConnectivityType_t connType)
422 ConnectivityHandlerList *tempConnectivityHandlers = gConnectivityHandlers;
423 if (NULL == tempConnectivityHandlers)
425 printf("None of the interface is initialized\n");
429 while (tempConnectivityHandlers && tempConnectivityHandlers->type != connType)
431 tempConnectivityHandlers = tempConnectivityHandlers->nextHandler;
434 if (NULL == tempConnectivityHandlers)
436 printf( "No interface handler for type %d", connType);
440 if (connType == CA_WIFI)
442 tempConnectivityHandlers->handler.sendDataToAll(coapData,
443 strlen(coapData) + 1);
445 else if (connType == CA_EDR || connType == CA_LE)
447 tempConnectivityHandlers->handler.sendDataToAll(coapData, strlen(coapData));
451 void interfaceReadData(CAConnectivityType_t connType)
453 ConnectivityHandlerList *tempConnectivityHandlers = gConnectivityHandlers;
454 if (NULL == tempConnectivityHandlers)
456 printf("None of the interface is initialized\n");
460 while (tempConnectivityHandlers && tempConnectivityHandlers->type != connType)
462 tempConnectivityHandlers = tempConnectivityHandlers->nextHandler;
465 if (NULL == tempConnectivityHandlers)
467 printf( "No interface handler for type %d", connType);
471 if (CA_STATUS_OK != tempConnectivityHandlers->handler.readData())
473 printf("Failed to Read Data\n");
477 printf("Read Data is successfull\n");
481 void interfaceGetNetworkInfo(CAConnectivityType_t connType)
485 ConnectivityHandlerList *tempConnectivityHandlers = gConnectivityHandlers;
486 if (NULL == tempConnectivityHandlers)
488 printf("None of the interface is initialized\n");
492 while (tempConnectivityHandlers && tempConnectivityHandlers->type != connType)
494 tempConnectivityHandlers = tempConnectivityHandlers->nextHandler;
497 if (NULL == tempConnectivityHandlers)
499 printf( "No interface handler for type %d", connType);
503 //Get the network interface info
504 CALocalConnectivity_t *info = NULL;
506 if (CA_STATUS_OK != tempConnectivityHandlers->handler.GetnetInfo(&info, &size))
508 printf("Failed to get network info\n");
512 if (0 >= size || info == NULL)
514 printf("No network found !!!\n");
518 printf("Network Information: \n");
519 for (; i < size; i++)
521 if (connType == CA_WIFI)
523 printf("Type : %s\n", (connType == CA_ETHERNET) ? "CA_ETHERNET" : "CA_WIFI");
524 printf("Address : %s\n", info[i].addressInfo.IP.ipAddress);
528 printf("Type : %s\n", (connType == CA_EDR) ? "CA_EDR" : "CA_LE");
529 printf("Address : %s\n\n", info[i].addressInfo.BT.btMacAddress);
534 int16_t interfaceStopAdapter(CAConnectivityType_t connType)
536 ConnectivityHandlerList *tempConnectivityHandlers = gConnectivityHandlers;
537 if (NULL == tempConnectivityHandlers)
539 printf("None of the interface is initialized\n");
543 while (tempConnectivityHandlers && tempConnectivityHandlers->type != connType)
545 tempConnectivityHandlers = tempConnectivityHandlers->nextHandler;
548 if (NULL == tempConnectivityHandlers)
550 printf( "No interface handler for type %d", connType);
554 if (CA_STATUS_OK != tempConnectivityHandlers->handler.stopAdapter())
556 printf("Failed to Stop adapter\n");
560 printf("Stopped the adapter\n");
564 void testInitializeInterface()
566 printf("testInitializeInterface Entry\n");
568 int16_t type = selectConnectivityType();
569 if (0 >= type || 3 < type)
571 printf("Invalid selection...\n");
577 #ifdef WIFI_ADAPTER_TEST
580 testInitializeWIFIInterface();
584 #ifdef BT_ADAPTER_TEST
587 testInitializeBTInterface();
591 #ifdef BLE_ADAPTER_TEST
594 testInitializeBLEInterface();
599 printf("Feature is not enabled or not implemented\n");
603 void testTerminateInterface()
605 int16_t type = selectConnectivityType();
606 if (0 >= type || 3 < type)
608 printf("Invalid selection...\n");
612 #ifdef WIFI_ADAPTER_TEST
613 if (1 == type) /* WIFI */
615 testTerminateWIFIInterface();
618 #ifdef BT_ADAPTER_TEST
619 if (2 == type) /*BT*/
621 testTerminateBTInterface();
624 #ifdef BLE_ADAPTER_TEST
625 if (3 == type) /*BLE*/
627 testTerminateBLEInterface();
631 ConnectivityHandlerList *currentConnectivityHandler = gConnectivityHandlers;
632 ConnectivityHandlerList *prevConnectivityHandler = NULL;
634 printf("Linked list delete start\n");
635 while (currentConnectivityHandler != NULL)
637 printf("Iterating through the list to find the matching interface\n");
638 if (currentConnectivityHandler->type == type)
640 printf("Matching interface found\n");
641 if (prevConnectivityHandler == NULL)
643 currentConnectivityHandler = currentConnectivityHandler->nextHandler;
644 freeData(gConnectivityHandlers);
645 gConnectivityHandlers = NULL;
646 printf( "Node deleted with interface type %d", type);
650 prevConnectivityHandler->nextHandler = currentConnectivityHandler->nextHandler;
651 freeData(currentConnectivityHandler);
652 currentConnectivityHandler = prevConnectivityHandler->nextHandler;
653 printf( "Node deleted with interface type %d from linked list", type);
658 prevConnectivityHandler = currentConnectivityHandler;
659 currentConnectivityHandler = currentConnectivityHandler->nextHandler;
662 gConnectivityHandlers = NULL;
666 void testStartAdapter()
668 int type = selectConnectivityType();
669 if (0 >= type || 3 < type)
671 printf("Invalid selection...\n");
677 #ifdef WIFI_ADAPTER_TEST
680 interfaceStartAdapter(CA_WIFI);
684 #ifdef BT_ADAPTER_TEST
687 interfaceStartAdapter(CA_EDR);
691 #ifdef BLE_ADAPTER_TEST
694 interfaceStartAdapter(CA_LE);
699 printf("Feature is not enabled or not implemented\n");
703 void testStartServer(int serverType)
705 int type = selectConnectivityType();
706 if (0 >= type || 3 < type)
708 printf("Invalid selection...\n");
714 #ifdef WIFI_ADAPTER_TEST
717 interfaceMulticastStartServer(CA_WIFI, serverType);
721 #ifdef BT_ADAPTER_TEST
724 interfaceMulticastStartServer(CA_EDR, serverType);
728 #ifdef BLE_ADAPTER_TEST
731 interfaceMulticastStartServer(CA_LE, serverType);
736 printf("Feature is not enabled or not implemented\n");
740 void testSendUnicastData()
742 int16_t type = selectConnectivityType();
743 if (0 >= type || 3 < type)
745 printf("Invalid selection...\n");
751 #ifdef WIFI_ADAPTER_TEST
754 interfaceSendUnicastData(CA_WIFI);
758 #ifdef BT_ADAPTER_TEST
761 interfaceSendUnicastData(CA_EDR);
765 #ifdef BLE_ADAPTER_TEST
768 interfaceSendUnicastData(CA_LE);
773 printf("Feature is not enabled or not implemented\n");
777 void testSendMulticastData()
779 int16_t type = selectConnectivityType();
780 if (0 >= type || 3 < type)
782 printf("Invalid selection...\n");
788 #ifdef WIFI_ADAPTER_TEST
791 interfaceSendMulticastData(CA_WIFI);
795 #ifdef BT_ADAPTER_TEST
798 interfaceSendMulticastData(CA_EDR);
802 #ifdef BLE_ADAPTER_TEST
805 interfaceSendMulticastData(CA_LE);
810 printf("Feature is not enabled or not implemented\n");
814 void testReadData(void)
816 int16_t type = selectConnectivityType();
817 if (0 >= type || 3 < type)
819 printf("Invalid selection...\n");
825 #ifdef WIFI_ADAPTER_TEST
828 interfaceReadData(CA_WIFI);
832 #ifdef BT_ADAPTER_TEST
835 interfaceReadData(CA_EDR);
839 #ifdef BLE_ADAPTER_TEST
842 interfaceReadData(CA_LE);
847 printf("Feature is not enabled or not implemented\n");
851 void testGetNetworkInfo(void)
853 int16_t type = selectConnectivityType();
854 if (0 >= type || 3 < type)
856 printf("Invalid selection...\n");
862 #ifdef WIFI_ADAPTER_TEST
865 interfaceGetNetworkInfo(CA_WIFI);
869 #ifdef BT_ADAPTER_TEST
872 interfaceGetNetworkInfo(CA_EDR);
876 #ifdef BLE_ADAPTER_TEST
879 interfaceGetNetworkInfo(CA_LE);
884 printf("Feature is not enabled or not implemented\n");
888 void testStopAdapter()
890 int16_t type = selectConnectivityType();
891 if (0 >= type || 3 < type)
893 printf("Invalid selection...\n");
899 #ifdef WIFI_ADAPTER_TEST
902 interfaceStopAdapter(CA_WIFI);
906 #ifdef BT_ADAPTER_TEST
909 interfaceStopAdapter(CA_EDR);
913 #ifdef BLE_ADAPTER_TEST
916 interfaceStopAdapter(CA_LE);
921 printf("Feature is not enabled or not implemented\n");
925 #ifdef BT_ADAPTER_TEST
926 void testInitializeBTInterface(void)
928 printf("Initiazing EDR\n");
930 printf("Initializing BT Adapter threadpool\n");
931 initializeThreadPool(CA_EDR);
933 //Start bluetooth communication adapter
934 CAResult_t err = CAInitializeEDR(interfaceRegisterCallback, networkPacketHandler,
935 networkInterfaceCallback, gBTThreadPool);
936 if (CA_STATUS_OK != err && CA_ADAPTER_NOT_ENABLED != err)
938 printf("Failed to initialize bluetooth communication adapter!\n");
942 void testTerminateBTInterface(void)
944 printf("Terminating EDR\n");
946 //Terminate the Bluetooth communication adapter
949 printf( "Terminating BT Adapter thread pool");
950 u_thread_pool_free(gBTThreadPool);
951 gBTThreadPool = NULL;
953 #endif //BT_ADAPTER_TEST
955 #ifdef WIFI_ADAPTER_TEST
956 void testInitializeWIFIInterface(void)
958 printf("testInitializeWIFIInterface IN\n");
960 printf("Initializing WIFI adapter threadpool\n");
961 initializeThreadPool(CA_WIFI);
963 //Start Wifi communication adapter
964 if (0 != CAInitializeWifi(interfaceRegisterCallback, networkPacketHandler,
965 networkInterfaceCallback, gWiFiThreadPool))
967 printf("testInitializeWIFIInterface Failed to initialize bluetooth communication adapter\n");
971 printf("testInitializeWIFIInterface OUT\n");
974 void testTerminateWIFIInterface(void)
976 printf("testTerminateWIFIInterface IN\n");
978 // Stop if Wifi communication adapter is running
979 interfaceStopAdapter(CA_WIFI);
981 // Freeing threadpool for wifi communication adapter
982 printf( "Terminating WIFI Adapter thread pool");
983 u_thread_pool_free(gWiFiThreadPool);
984 gWiFiThreadPool = NULL;
986 //Terminate the Wifi communication adapter
990 printf("testTerminateWIFIInterface OUT\n");
992 #endif //WIFI_ADAPTER_TEST
994 #ifdef BLE_ADAPTER_TEST
995 void testInitializeBLEInterface(void)
997 printf("testInitializeBLEInterface IN\n");
999 printf("Initializing BLE adapter threadpool\n");
1000 initializeThreadPool(CA_LE);
1002 //Start bluetooth communication adapter
1003 if (0 != CAInitializeLE(interfaceRegisterCallback, networkPacketHandler,
1004 networkInterfaceCallback, gLEThreadPool))
1006 printf("testInitializeBLEInterface Failed due to CAInitializeLE\n");
1010 printf("testInitializeBLEInterface OUT\n");
1013 void testTerminateBLEInterface(void)
1015 printf("testTerminateBLEInterface IN\n");
1017 //Terminate the BLE server & Client
1020 printf( "Terminating BLE Adapter thread pool");
1021 u_thread_pool_free(gLEThreadPool);
1022 gLEThreadPool = NULL;
1024 printf("testTerminateBLEInterface OUT\n");
1026 #endif //BLE_ADAPTER_TEST
1028 static void testPrintHelp(void)
1030 printf(" =====================================================================\n");
1031 printf("| Welcome to Connectivity Abstraction |\n");
1032 printf("| - CA Unit Test v1.0 - |\n");
1033 printf("|---------------------------------------------------------------------|\n");
1034 printf("| ** Options ** |\n");
1035 printf("| i - Initialize the Interface |\n");
1036 printf("| d - Terminate the Interface |\n");
1037 printf("| a - Start adapter |\n");
1038 printf("| b - Stop adapter |\n");
1039 printf("| sd- Start Discovery Server |\n");
1040 printf("| sl- Start Listening Server |\n");
1041 printf("| u - Send Unicast Data |\n");
1042 printf("| m - Send Multicast Data |\n");
1043 printf("| g - Get Network Info |\n");
1044 printf("| r - Read data synchronously |\n");
1045 printf("| x - quit the test. |\n");
1046 printf("| h - Help menu. |\n");
1047 printf(" =====================================================================\n");
1050 static gboolean testThread(GIOChannel *source, GIOCondition condition , gpointer data)
1052 gchar buf[10] = {'\0'};
1056 if (g_io_channel_read(channel, buf, 10, &read) != G_IO_ERROR_NONE)
1058 printf("g_io_channel_read error!!!\n");
1064 /*if ((!has_register) && (((buf[0]!= 'i') && (buf[0]!= 'h') && (buf[0]!= 'q')) || (read != 2))) {
1066 printf("***Warning***: You should Register firstly!\n");
1072 testInitializeInterface();
1075 testTerminateInterface();
1076 if (g_source_remove(g_test_io_watch_id))
1078 printf("g_source_remove() OK!!!\n");
1079 g_io_channel_shutdown(channel, TRUE, &g_err_Sample);
1080 g_io_channel_unref(channel);
1081 g_main_loop_quit(mainloop);
1085 testTerminateInterface();
1107 testSendUnicastData();
1110 testSendMulticastData();
1116 testGetNetworkInfo();
1124 int main(int argc, char *argv[])
1126 printf("Starting sample\n");
1127 mainloop = g_main_loop_new(NULL, FALSE);
1128 channel = g_io_channel_unix_new(0);/* read from stdin */
1129 g_test_io_watch_id = g_io_add_watch(channel,
1130 (GIOCondition)(G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL), testThread,
1132 printf("CM Test Thread created...\n");
1134 g_main_loop_run(mainloop);