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 //Hardcoded coap data for Test
55 static char coapData[500] =
56 "{\"oc:\[{href\":\"/a/light\",\"ref\":{\"power\":\"20\",\"state\":\"true\"}}]}";
58 void testInitializeBTInterface(void);
59 void testTerminateBTInterface(void);
60 void testInitializeWIFIInterface(void);
61 void testTerminateWIFIInterface(void);
62 void testInitializeBLEInterface(void);
63 void testTerminateBLEInterface(void);
65 typedef struct ConnectivityHandlerList
67 CAConnectivityType_t type;
68 CAConnectivityHandler_t handler;
69 struct ConnectivityHandlerList *nextHandler;
70 } ConnectivityHandlerList;
72 static ConnectivityHandlerList *gConnectivityHandlers = NULL;
74 void initializeThreadPool(CAConnectivityType_t type)
76 #ifdef BT_ADAPTER_TEST
77 if (CA_EDR == type && NULL == gBTThreadPool)
79 if (CA_STATUS_OK != u_thread_pool_init(3, &gBTThreadPool))
81 printf("Failed to create thread pool for BT adapter!\n");
86 #ifdef WIFI_ADAPTER_TEST
87 if (CA_WIFI == type && NULL == gWiFiThreadPool)
89 if (CA_STATUS_OK != u_thread_pool_init(3, &gWiFiThreadPool))
91 printf("Failed to create thread pool for WIFI adapter!\n");
96 #ifdef BLE_ADAPTER_TEST
97 if (CA_LE == type && NULL == gLEThreadPool)
99 if (CA_STATUS_OK != u_thread_pool_init(5, &gLEThreadPool))
101 printf("Failed to create thread pool for BLE adapter!\n");
109 void storeInterfaceCallbacks(ConnectivityHandlerList *newHandler)
111 printf("storeInterfaceCallbacks Entry in Sample\n");
112 newHandler->nextHandler = NULL;
113 ConnectivityHandlerList *tempConnectivityHandlers = gConnectivityHandlers;
115 if (!tempConnectivityHandlers)
117 gConnectivityHandlers = newHandler;
118 printf("storeInterfaceCallbacks Exit in Sample\n");
122 while (tempConnectivityHandlers->nextHandler)
124 tempConnectivityHandlers = tempConnectivityHandlers->nextHandler;
127 tempConnectivityHandlers->nextHandler = newHandler;
128 printf("storeInterfaceCallbacks Exit in Sample\n");
131 void interfaceRegisterCallback(CAConnectivityHandler_t handler,
132 CAConnectivityType_t connType)
134 printf("interfaceRegisterCallback Entry in Sample\n");
135 ConnectivityHandlerList *newConnectivityHandler = (ConnectivityHandlerList *) malloc(sizeof(
136 ConnectivityHandlerList));
137 if (NULL == newConnectivityHandler)
139 printf("Memory allocation failed\n");
143 newConnectivityHandler->type = connType;
144 newConnectivityHandler->handler = handler;
145 storeInterfaceCallbacks(newConnectivityHandler);
146 printf("interfaceRegisterCallback Exit in Sample\n");
149 void networkPacketHandler(CARemoteEndpoint_t *object, void *data, uint32_t dataLength)
151 printf("networkPacketHandler Entry in Sample\n");
152 if (object == NULL || data == NULL)
154 printf("NULL Object\n");
158 printf("Data Received from: ");
159 if (CA_EDR == object->connectivityType)
161 printf(object->addressInfo.BT.btMacAddress);
163 else if (CA_LE == object->connectivityType)
165 printf(object->addressInfo.LE.leMacAddress);
167 else if (CA_WIFI == object->connectivityType || CA_ETHERNET == object->connectivityType)
169 printf(object->addressInfo.IP.ipAddress);
172 printf("\nReceived Data [Length: %d]: %s\n", dataLength, (char *)data);
173 printf("networkPacketHandler Exit in Sample\n");
176 void networkInterfaceCallback(CALocalConnectivity_t *localEndPoint,
177 CANetworkStatus_t networkConnectivityState)
179 printf("networkInterfaceCallback Entry in Sample\n");
180 if (localEndPoint == NULL)
182 printf("NULL Object\n");
186 if (networkConnectivityState == CA_INTERFACE_UP)
188 printf("Network Status is UP\n");
192 printf("Network Status is DOWN\n");
196 if (CA_EDR == localEndPoint->type)
198 printf("%s\n", localEndPoint->addressInfo.BT.btMacAddress);
200 else if (CA_LE == localEndPoint->type)
202 printf("%s\n", localEndPoint->addressInfo.LE.leMacAddress);
204 else if (CA_WIFI == localEndPoint->type || CA_ETHERNET == localEndPoint->type)
206 printf("%s\n", localEndPoint->addressInfo.IP.ipAddress);
209 printf("networkInterfaceCallback Exit in Sample\n");
213 void freeData(void *data)
215 printf("freeData Entry in Sample\n");
220 printf("freeData Exit in Sample\n");
223 int16_t selectConnectivityType()
226 printf("*******Select the Connectivity Type*******\n");
227 printf(" [1] WIFI \n");
228 printf(" [2] BT \n");
229 printf(" [3] BLE \n");
233 if (cType < 1 && cType > 3)
235 printf("Invalid Selection!!!!\n");
238 return (int16_t)cType;
241 int16_t interfaceStartAdapter(CAConnectivityType_t connType)
243 ConnectivityHandlerList *tempConnectivityHandlers = gConnectivityHandlers;
244 if (NULL == tempConnectivityHandlers)
246 printf("None of the interface is initialized\n");
250 while (tempConnectivityHandlers && tempConnectivityHandlers->type != connType)
252 tempConnectivityHandlers = tempConnectivityHandlers->nextHandler;
255 if (NULL == tempConnectivityHandlers)
257 printf( "No interface handler for type %d", connType);
261 if (CA_STATUS_OK != tempConnectivityHandlers->handler.startAdapter())
263 printf("Failed to Start adapter\n");
270 int16_t interfaceMulticastStartServer(CAConnectivityType_t connType, int serverType)
272 printf("interfaceMulticastStartServer Starting...\n");
273 ConnectivityHandlerList *tempConnectivityHandlers = gConnectivityHandlers;
274 if (NULL == tempConnectivityHandlers)
276 printf("None of the interface is initialized\n");
280 while (tempConnectivityHandlers && tempConnectivityHandlers->type != connType)
282 tempConnectivityHandlers = tempConnectivityHandlers->nextHandler;
285 if (NULL == tempConnectivityHandlers)
287 printf( "No interface handler for type %d", connType);
291 CAAdapterStartDiscoveryServer startServer = NULL;
294 case 1: //Discovery server
295 startServer = tempConnectivityHandlers->handler.startDiscoverServer;
297 case 2: //Listening server
298 startServer = tempConnectivityHandlers->handler.startListenServer;
304 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));
452 void interfaceReadData(CAConnectivityType_t connType)
454 ConnectivityHandlerList *tempConnectivityHandlers = gConnectivityHandlers;
455 if (NULL == tempConnectivityHandlers)
457 printf("None of the interface is initialized\n");
461 while (tempConnectivityHandlers && tempConnectivityHandlers->type != connType)
463 tempConnectivityHandlers = tempConnectivityHandlers->nextHandler;
466 if (NULL == tempConnectivityHandlers)
468 printf( "No interface handler for type %d", connType);
472 if (CA_STATUS_OK != tempConnectivityHandlers->handler.readData())
474 printf("Failed to Read Data\n");
478 printf("Read Data is successfull\n");
482 void interfaceGetNetworkInfo(CAConnectivityType_t connType)
486 ConnectivityHandlerList *tempConnectivityHandlers = gConnectivityHandlers;
487 if (NULL == tempConnectivityHandlers)
489 printf("None of the interface is initialized\n");
493 while (tempConnectivityHandlers && tempConnectivityHandlers->type != connType)
495 tempConnectivityHandlers = tempConnectivityHandlers->nextHandler;
498 if (NULL == tempConnectivityHandlers)
500 printf( "No interface handler for type %d", connType);
504 //Get the network interface info
505 CALocalConnectivity_t *info = NULL;
507 if (CA_STATUS_OK != tempConnectivityHandlers->handler.GetnetInfo(&info, &size))
509 printf("Failed to get network info\n");
513 if (0 >= size || info == NULL)
515 printf("No network found !!!\n");
519 printf("Network Information: \n");
520 for (; i < size; i++)
522 if (connType == CA_WIFI)
524 printf("Type : %s\n", (connType == CA_ETHERNET) ? "CA_ETHERNET" : "CA_WIFI");
525 printf("Address : %s\n", info[i].addressInfo.IP.ipAddress);
529 printf("Type : %s\n", (connType == CA_EDR) ? "CA_EDR" : "CA_LE");
530 printf("Address : %s\n\n", info[i].addressInfo.BT.btMacAddress);
535 int16_t interfaceStopAdapter(CAConnectivityType_t connType)
537 ConnectivityHandlerList *tempConnectivityHandlers = gConnectivityHandlers;
538 if (NULL == tempConnectivityHandlers)
540 printf("None of the interface is initialized\n");
544 while (tempConnectivityHandlers && tempConnectivityHandlers->type != connType)
546 tempConnectivityHandlers = tempConnectivityHandlers->nextHandler;
549 if (NULL == tempConnectivityHandlers)
551 printf( "No interface handler for type %d", connType);
555 if (CA_STATUS_OK != tempConnectivityHandlers->handler.stopAdapter())
557 printf("Failed to Stop adapter\n");
561 printf("Stopped the adapter\n");
565 void testInitializeInterface()
567 printf("testInitializeInterface Entry\n");
569 int16_t type = selectConnectivityType();
570 if (0 >= type || 3 < type)
572 printf("Invalid selection...\n");
578 #ifdef WIFI_ADAPTER_TEST
581 testInitializeWIFIInterface();
585 #ifdef BT_ADAPTER_TEST
588 testInitializeBTInterface();
592 #ifdef BLE_ADAPTER_TEST
595 testInitializeBLEInterface();
600 printf("Feature is not enabled or not implemented\n");
604 void testTerminateInterface()
606 int16_t type = selectConnectivityType();
607 if (0 >= type || 3 < type)
609 printf("Invalid selection...\n");
613 #ifdef WIFI_ADAPTER_TEST
614 if (1 == type) /* WIFI */
616 testTerminateWIFIInterface();
619 #ifdef BT_ADAPTER_TEST
620 if (2 == type) /*BT*/
622 testTerminateBTInterface();
625 #ifdef BLE_ADAPTER_TEST
626 if (3 == type) /*BLE*/
628 testTerminateBLEInterface();
632 ConnectivityHandlerList *currentConnectivityHandler = gConnectivityHandlers;
633 ConnectivityHandlerList *prevConnectivityHandler = NULL;
635 printf("Linked list delete start\n");
636 while (currentConnectivityHandler != NULL)
638 printf("Iterating through the list to find the matching interface\n");
639 if (currentConnectivityHandler->type == type)
641 printf("Matching interface found\n");
642 if (prevConnectivityHandler == NULL)
644 currentConnectivityHandler = currentConnectivityHandler->nextHandler;
645 freeData(gConnectivityHandlers);
646 gConnectivityHandlers = NULL;
647 printf( "Node deleted with interface type %d", type);
651 prevConnectivityHandler->nextHandler = currentConnectivityHandler->nextHandler;
652 freeData(currentConnectivityHandler);
653 currentConnectivityHandler = prevConnectivityHandler->nextHandler;
654 printf( "Node deleted with interface type %d from linked list", type);
659 prevConnectivityHandler = currentConnectivityHandler;
660 currentConnectivityHandler = currentConnectivityHandler->nextHandler;
663 gConnectivityHandlers = NULL;
667 void testStartAdapter()
669 int type = selectConnectivityType();
670 if (0 >= type || 3 < type)
672 printf("Invalid selection...\n");
678 #ifdef WIFI_ADAPTER_TEST
681 interfaceStartAdapter(CA_WIFI);
685 #ifdef BT_ADAPTER_TEST
688 interfaceStartAdapter(CA_EDR);
692 #ifdef BLE_ADAPTER_TEST
695 interfaceStartAdapter(CA_LE);
700 printf("Feature is not enabled or not implemented\n");
704 void testStartServer(int serverType)
706 int type = selectConnectivityType();
707 if (0 >= type || 3 < type)
709 printf("Invalid selection...\n");
715 #ifdef WIFI_ADAPTER_TEST
718 interfaceMulticastStartServer(CA_WIFI, serverType);
722 #ifdef BT_ADAPTER_TEST
725 interfaceMulticastStartServer(CA_EDR, serverType);
729 #ifdef BLE_ADAPTER_TEST
732 interfaceMulticastStartServer(CA_LE, serverType);
737 printf("Feature is not enabled or not implemented\n");
741 void testSendUnicastData()
743 int16_t type = selectConnectivityType();
744 if (0 >= type || 3 < type)
746 printf("Invalid selection...\n");
752 #ifdef WIFI_ADAPTER_TEST
755 interfaceSendUnicastData(CA_WIFI);
759 #ifdef BT_ADAPTER_TEST
762 interfaceSendUnicastData(CA_EDR);
766 #ifdef BLE_ADAPTER_TEST
769 interfaceSendUnicastData(CA_LE);
774 printf("Feature is not enabled or not implemented\n");
778 void testSendMulticastData()
780 int16_t type = selectConnectivityType();
781 if (0 >= type || 3 < type)
783 printf("Invalid selection...\n");
789 #ifdef WIFI_ADAPTER_TEST
792 interfaceSendMulticastData(CA_WIFI);
796 #ifdef BT_ADAPTER_TEST
799 interfaceSendMulticastData(CA_EDR);
803 #ifdef BLE_ADAPTER_TEST
806 interfaceSendMulticastData(CA_LE);
811 printf("Feature is not enabled or not implemented\n");
815 void testReadData(void)
817 int16_t type = selectConnectivityType();
818 if (0 >= type || 3 < type)
820 printf("Invalid selection...\n");
826 #ifdef WIFI_ADAPTER_TEST
829 interfaceReadData(CA_WIFI);
833 #ifdef BT_ADAPTER_TEST
836 interfaceReadData(CA_EDR);
840 #ifdef BLE_ADAPTER_TEST
843 interfaceReadData(CA_LE);
848 printf("Feature is not enabled or not implemented\n");
852 void testGetNetworkInfo(void)
854 int16_t type = selectConnectivityType();
855 if (0 >= type || 3 < type)
857 printf("Invalid selection...\n");
863 #ifdef WIFI_ADAPTER_TEST
866 interfaceGetNetworkInfo(CA_WIFI);
870 #ifdef BT_ADAPTER_TEST
873 interfaceGetNetworkInfo(CA_EDR);
877 #ifdef BLE_ADAPTER_TEST
880 interfaceGetNetworkInfo(CA_LE);
885 printf("Feature is not enabled or not implemented\n");
889 void testStopAdapter()
891 int16_t type = selectConnectivityType();
892 if (0 >= type || 3 < type)
894 printf("Invalid selection...\n");
900 #ifdef WIFI_ADAPTER_TEST
903 interfaceStopAdapter(CA_WIFI);
907 #ifdef BT_ADAPTER_TEST
910 interfaceStopAdapter(CA_EDR);
914 #ifdef BLE_ADAPTER_TEST
917 interfaceStopAdapter(CA_LE);
922 printf("Feature is not enabled or not implemented\n");
926 #ifdef BT_ADAPTER_TEST
927 void testInitializeBTInterface(void)
929 printf("Initiazing EDR\n");
931 printf("Initializing BT Adapter threadpool\n");
932 initializeThreadPool(CA_EDR);
934 //Start bluetooth communication adapter
935 CAResult_t err = CAInitializeEDR(interfaceRegisterCallback, networkPacketHandler,
936 networkInterfaceCallback, gBTThreadPool);
937 if (CA_STATUS_OK != err && CA_ADAPTER_NOT_ENABLED != err)
939 printf("Failed to initialize bluetooth communication adapter!\n");
943 void testTerminateBTInterface(void)
945 printf("Terminating EDR\n");
947 //Terminate the Bluetooth communication adapter
950 printf( "Terminating BT Adapter thread pool");
951 u_thread_pool_free(gBTThreadPool);
952 gBTThreadPool = NULL;
954 #endif //BT_ADAPTER_TEST
956 #ifdef WIFI_ADAPTER_TEST
957 void testInitializeWIFIInterface(void)
959 printf("testInitializeWIFIInterface IN\n");
961 printf("Initializing WIFI adapter threadpool\n");
962 initializeThreadPool(CA_WIFI);
964 //Start Wifi communication adapter
965 if (0 != CAInitializeWifi(interfaceRegisterCallback, networkPacketHandler,
966 networkInterfaceCallback, gWiFiThreadPool))
968 printf("testInitializeWIFIInterface Failed to initialize bluetooth communication adapter\n");
972 printf("testInitializeWIFIInterface OUT\n");
975 void testTerminateWIFIInterface(void)
977 printf("testTerminateWIFIInterface IN\n");
979 // Stop if Wifi communication adapter is running
980 interfaceStopAdapter(CA_WIFI);
982 // Freeing threadpool for wifi communication adapter
983 printf( "Terminating WIFI Adapter thread pool");
984 u_thread_pool_free(gWiFiThreadPool);
985 gWiFiThreadPool = NULL;
987 //Terminate the Wifi communication adapter
991 printf("testTerminateWIFIInterface OUT\n");
993 #endif //WIFI_ADAPTER_TEST
995 #ifdef BLE_ADAPTER_TEST
996 void testInitializeBLEInterface(void)
998 printf("testInitializeBLEInterface IN\n");
1000 printf("Initializing BLE adapter threadpool\n");
1001 initializeThreadPool(CA_LE);
1003 //Start bluetooth communication adapter
1004 if (0 != CAInitializeLE(interfaceRegisterCallback, networkPacketHandler,
1005 networkInterfaceCallback, gLEThreadPool))
1007 printf("testInitializeBLEInterface Failed due to CAInitializeLE\n");
1011 printf("testInitializeBLEInterface OUT\n");
1014 void testTerminateBLEInterface(void)
1016 printf("testTerminateBLEInterface IN\n");
1018 //Terminate the BLE server & Client
1021 printf( "Terminating BLE Adapter thread pool");
1022 u_thread_pool_free(gLEThreadPool);
1023 gLEThreadPool = NULL;
1025 printf("testTerminateBLEInterface OUT\n");
1027 #endif //BLE_ADAPTER_TEST
1029 static void testPrintHelp(void)
1031 printf(" =====================================================================\n");
1032 printf("| Welcome to Connectivity Abstraction |\n");
1033 printf("| - CA Unit Test v1.0 - |\n");
1034 printf("|---------------------------------------------------------------------|\n");
1035 printf("| ** Options ** |\n");
1036 printf("| i - Initialize the Interface |\n");
1037 printf("| d - Terminate the Interface |\n");
1038 printf("| a - Start adapter |\n");
1039 printf("| b - Stop adapter |\n");
1040 printf("| sd- Start Discovery Server |\n");
1041 printf("| sl- Start Listening Server |\n");
1042 printf("| u - Send Unicast Data |\n");
1043 printf("| m - Send Multicast Data |\n");
1044 printf("| g - Get Network Info |\n");
1045 printf("| r - Read data synchronously |\n");
1046 printf("| x - quit the test. |\n");
1047 printf("| h - Help menu. |\n");
1048 printf(" =====================================================================\n");
1051 static gboolean testThread(GIOChannel *source, GIOCondition condition , gpointer data)
1053 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);