void set_receive_time(guu_is_wilddog_t *gwd) { //set the unix time stamp in the tree we got char time_buf[14]; int len; Wilddog_Node_T *node; node = wilddog_node_find(gwd->snapshot_clone,"received"); if(node !=NULL) { gettimeofday(&tv, NULL); len = sprintf(time_buf,"%ld", tv.tv_sec); //printf("%s %d\n",time_buf,len); if( wilddog_node_setValue(node,time_buf,len) != 0) { wilddog_debug("setValue failed\n"); } } wilddog_setValue(gwd->wd,gwd->snapshot_clone,setvalue_cb,(void*)gwd); }
STATIC void stab_settest_serialSet_send(void) { int i,res; stab_settest_setsuccess = 0; for(i=0;i<10;i++) { res = wilddog_setValue(stab_setdata[i].client,\ stab_setdata[i].p_node,stab_settest_serialSetValueFunc,\ (void*)&stab_setdata[i]); stab_get_requestRes(res); if(res>=0) { stab_setdata[i].setfault = 0; //stab_settest_request++; stab_settest_setsuccess++; } else stab_setdata[i].setfault=1; } while(1) { if(stab_settest_setsuccess ==0 ) break; stab_trysync(); } }
STATIC int multipletest_request(MULTIPLETEST_CMD_TYPE type, Wilddog_T client,Multiple_client_T *p_mul_client) { Wilddog_Node_T *p_head = NULL,*p_node = NULL; int res = 0; /*Create an node which type is an object*/ p_head = wilddog_node_createObject(NULL); /*Create an node which type is UTF-8 Sring*/ p_node = wilddog_node_createUString((Wilddog_Str_T *)MULTIPLETEST_KEY,(Wilddog_Str_T *)p_mul_client->p_host); /*Add p_node to p_head, then p_node is the p_head's child node*/ wilddog_node_addChild(p_head, p_node); p_mul_client->d_cmd= type; p_mul_client->d_recvFlag = 0; p_mul_client->d_sendFault = 1; switch(type) { case MULTIPLETEST_CMD_GET: /*Send the query method*/ res = wilddog_getValue(client, (onQueryFunc)multiple_getValueFunc, (void*)p_mul_client); break; case MULTIPLETEST_CMD_SET: /*Send the set method*/ res = wilddog_setValue(client,p_head,multiple_setValueFunc,(void*)p_mul_client); break; case MULTIPLETEST_CMD_PUSH: /*Send the push method*/ res = wilddog_push(client, p_head, multiple_pushFunc, (void *)p_mul_client); break; case MULTIPLETEST_CMD_DELE: /*Send the remove method*/ res = wilddog_removeValue(client, multiple_removeValueFunc, (void*)p_mul_client); break; case MULTIPLETEST_CMD_ON: /*Observe on*/ res = wilddog_addObserver(client, WD_ET_VALUECHANGE, multiple_addObserverFunc, (void*)p_mul_client); break; case MULTIPLETEST_CMD_OFF: res = wilddog_removeObserver(client, WD_ET_VALUECHANGE); break; case MULTIPLETEST_CMD_NON: default: break; } /*Delete the node*/ wilddog_node_delete(p_head); /* fautl to request then do not getValue */ if(res >= 0) p_mul_client->d_sendFault = 0; return res; }
int stabtest_reques(STABTEST_CMD_TYPE type,Wilddog_T client,BOOL *p_finishFlag) { Wilddog_Node_T *p_head = NULL,*p_node = NULL; int res = 0; /*Create an node which type is an object*/ p_head = wilddog_node_createObject(NULL); /*Create an node which type is UTF-8 Sring*/ p_node = wilddog_node_createUString((Wilddog_Str_T *)STABTEST_KEY,(Wilddog_Str_T *)STABTEST_VALUE); /*Add p_node to p_head, then p_node is the p_head's child node*/ wilddog_node_addChild(p_head, p_node); stab_cmd = type; switch(type) { case STABTEST_CMD_GET: /*Send the query method*/ res = wilddog_getValue(client, (onQueryFunc)stab_getValueFunc, (void*)p_finishFlag); break; case STABTEST_CMD_SET: /*Send the set method*/ res = wilddog_setValue(client,p_head,stab_setValueFunc,(void*)p_finishFlag); break; case STABTEST_CMD_PUSH: /*Send the push method*/ res = wilddog_push(client, p_head, stab_pushFunc, (void *)p_finishFlag); break; case STABTEST_CMD_DELE: /*Send the remove method*/ res = wilddog_removeValue(client, stab_removeValueFunc, (void*)p_finishFlag); break; case STABTEST_CMD_ON: /*Observe on*/ res = wilddog_addObserver(client, WD_ET_VALUECHANGE, stab_addObserverFunc, (void*)p_finishFlag); break; case STABTEST_CMD_OFF: res = wilddog_removeObserver(client, WD_ET_VALUECHANGE); break; case STABTEST_CMD_NON: default: break; } /*Delete the node*/ wilddog_node_delete(p_head); return res; }
STATIC int test_buildtreeFunc(void) { int m = 0; u8 url[strlen(TEST_URL)+20]; Wilddog_Node_T *p_head = NULL; //Wilddog_Node_T *p1 = NULL, *p2 = NULL, *p3 = NULL; Wilddog_Node_T *L1[2]; Wilddog_Node_T *L2[4]; Wilddog_Node_T *L3[8]; Wilddog_Node_T *L4[16]; Wilddog_Node_T *L5[32]; Wilddog_Node_T *L6[64]; Wilddog_Node_T *L7[128]; memset(key,0,20); p_head = wilddog_node_createObject(NULL); for(m = 0; m < 2; m++) { snprintf((char*)key, 20 , "%s%d", "L1",m); L1[m] = wilddog_node_createUString( key,(u8*)"L1L"); } for(m = 0; m < 4; m++) { snprintf((char*)key, 20 , "%s%d", "L2",m); L2[m] = wilddog_node_createUString( key,(u8*)"L2L"); } for(m = 0; m < 8; m++) { snprintf((char*)key, 20 , "%s%d", "L3",m); L3[m] = wilddog_node_createUString( key,(u8*)"L3L"); } for(m = 0; m < 16; m++) { snprintf((char*)key, 20 , "%s%d", "L4",m%10); L4[m] = wilddog_node_createUString( key,(u8*)"L4L"); } for(m = 0; m < 32; m++) { snprintf((char*)key, 20 , "%s%d", "L5",m%10); L5[m] = wilddog_node_createUString( key,(u8*)"L5L"); } for(m = 0; m < 64; m++) { snprintf((char*)key, 20 , "%s%d", "L6",m%10); L6[m] = wilddog_node_createUString( key,(u8*)"L6L"); } for(m = 0; m < 128; m++) { snprintf((char*)key, 20 , "%s%d", "L7",m%10); L7[m] = wilddog_node_createUString( key,(u8*)"L7L"); } for(m = 0; m < 2; m++) { wilddog_node_addChild(p_head, L1[m]); } for(m=0; m < 4; m++) { wilddog_node_addChild(L1[m/2], L2[m]); } for(m=0; m < 8; m++) { wilddog_node_addChild(L2[m/2], L3[m]); } for(m=0; m < 16; m++) { wilddog_node_addChild(L3[m/2], L4[m]); } for(m=0; m < 32; m++) { wilddog_node_addChild(L4[m/2], L5[m]); } for(m=0; m < 64; m++) { wilddog_node_addChild(L5[m/2], L6[m]); } for(m=0; m < 128; m++) { wilddog_node_addChild(L6[m/2], L7[m]); } /*3*/ isFinished = FALSE; memset((void*)url,0,sizeof(url)); sprintf((char*)url,"%s%s",TEST_URL,TEST_TREE_T_127); wilddog = wilddog_initWithUrl(url); if(0 == wilddog) { wilddog_debug("new wilddog error"); wilddog_node_delete(p_head); return -1; } wilddog_setValue(wilddog,L5[0],test_onSetFunc,(void*)TEST_TREE_T_127); //wilddog_node_delete(p_head); while(1) { if(TRUE == isFinished) { printf("\t set success! \n"); break; } wilddog_trySync(); } wilddog_destroy(&wilddog); /*4*/ if(TEST_TREE_ITEMS < 2) { wilddog_node_delete(p_head); return 0; } isFinished = FALSE; memset((void*)url,0,sizeof(url)); sprintf((char*)url,"%s%s",TEST_URL,TEST_TREE_T_256); wilddog = wilddog_initWithUrl(url); if(0 == wilddog) { wilddog_debug("new wilddog error"); wilddog_node_delete(p_head); return -1; } wilddog_setValue(wilddog,L4[0],test_onSetFunc,(void*)TEST_TREE_T_256); //wilddog_node_delete(p_head); while(1) { if(TRUE == isFinished) { printf("\t set success! \n"); break; } wilddog_trySync(); } wilddog_destroy(&wilddog); /*5*/ if(TEST_TREE_ITEMS < 3) { wilddog_node_delete(p_head); return 0; } isFinished = FALSE; memset((void*)url,0,sizeof(url)); sprintf((char*)url,"%s%s",TEST_URL,TEST_TREE_T_576); wilddog = wilddog_initWithUrl(url); if(0 == wilddog) { wilddog_debug("new wilddog error"); wilddog_node_delete(p_head); return -1; } wilddog_setValue(wilddog,L3[0],test_onSetFunc,(void*)TEST_TREE_T_576); //wilddog_node_delete(p_head); while(1) { if(TRUE == isFinished) { printf("\t set success! \n"); break; } wilddog_trySync(); } wilddog_destroy(&wilddog); /*6*/ if(TEST_TREE_ITEMS < 4) { wilddog_node_delete(p_head); return 0; } isFinished = FALSE; memset((void*)url,0,sizeof(url)); sprintf((char*)url,"%s%s",TEST_URL,TEST_TREE_T_810); wilddog = wilddog_initWithUrl(url); if(0 == wilddog) { wilddog_debug("new wilddog error"); wilddog_node_delete(p_head); return -1; } wilddog_setValue(wilddog,L2[0],test_onSetFunc,(void*)TEST_TREE_T_810); //wilddog_node_delete(p_head); while(1) { if(TRUE == isFinished) { printf("\t set success! \n"); break; } wilddog_trySync(); } wilddog_destroy(&wilddog); /*7*/ if(TEST_TREE_ITEMS < 5) { wilddog_node_delete(p_head); return 0; } isFinished = FALSE; memset((void*)url,0,sizeof(url)); sprintf((char*)url,"%s%s",TEST_URL,TEST_TREE_T_1044); wilddog = wilddog_initWithUrl(url); if(0 == wilddog) { wilddog_debug("new wilddog error"); wilddog_node_delete(p_head); return -1; } wilddog_setValue(wilddog,L1[0],test_onSetFunc,(void*)TEST_TREE_T_1044); //wilddog_node_delete(p_head); while(1) { if(TRUE == isFinished) { printf("\t set success! \n"); break; } wilddog_trySync(); } wilddog_destroy(&wilddog); /*8*/ if(TEST_TREE_ITEMS < 6) { wilddog_node_delete(p_head); return 0; } isFinished = FALSE; memset((void*)url,0,sizeof(url)); sprintf((char*)url,"%s%s",TEST_URL,TEST_TREE_T_1280); wilddog = wilddog_initWithUrl(url); if(0 == wilddog) { wilddog_debug("new wilddog error"); return -1; } wilddog_setValue(wilddog,p_head,test_onSetFunc,(void*)TEST_TREE_T_1280); wilddog_node_delete(p_head); while(1) { if(TRUE == isFinished) { printf("\t set success! \n"); break; } wilddog_trySync(); } wilddog_destroy(&wilddog); if(l_res < 0) printf("build tree error !!\n"); else printf("\n\ttest_buildtree finished\n"); return l_res; }
int main(int argc, char **argv) { char url[1024]; char value[1024]; char keys[256]; char host[512]; char authData[512]; BOOL authFlag = FALSE; memset(url,0,sizeof(url)); memset(value,0,sizeof(value)); memset(keys,0,sizeof(keys)); memset(host,0,sizeof(host)); memset(authData,0,sizeof(authData)); int type = 0; int opt,i,res = 0,cnt=0,cntmax=0; int option_index = 0; BOOL isFinish = FALSE,authFinish; Wilddog_T wilddog = 0; Wilddog_Node_T * p_node = NULL,*p_head = NULL; static struct option long_options[] = { {"auth", required_argument, 0, 0 }, {"value", required_argument, 0, 0 }, {"key", required_argument, 0, 0 }, {0, 0, 0, 0 } }; while((opt=getopt_long(argc,argv,"hl:",long_options,&option_index)) != -1) { switch (opt) { case 0: //printf("option %s", long_options[option_index].name); if (optarg) { if(strcmp(long_options[option_index].name,"key")==0) memcpy(keys, optarg,strlen(optarg)); if(strcmp(long_options[option_index].name,"value")==0) memcpy(value, optarg,strlen(optarg)); if(strcmp(long_options[option_index].name,"auth")==0) { authFlag = TRUE; memcpy(authData, optarg,strlen(optarg)); } } break; case 'h': fprintf(stderr, \ "Usage: %s setAuth|getValue|setValue|push|removeValue|addObser\n" "\t|disSetValue|disPush|disRemove|cacelDis|offLine|onLine\n" "\tver -l coap://<your appid>.wilddogio.com/ [ --auth=<auth data> " "--key=<key> --value=<value>]\n", argv[0]); return 0; case 'l': strcpy(url, (const char*)optarg); getHostFromAppid(host,url); sprintf(&host[strlen(host)],".wilddogio.com"); break; default: /* '?' */ fprintf(stderr, \ "Usage: %s setAuth|getValue|setValue|push|removeValue|addObser\n" "\t|disSetValue|disPush|disRemove|cacelDis|offLine|onLine\n" "\tver -l coap://<your appid>.wilddogio.com/ [ --auth=<auth data> " "--key=<key> --value=<value>]\n", argv[0]); return 0; } } for (i = 0; optind < argc; i++, optind++) { if(i == 0) { if(strcmp(argv[optind],"getValue")==0) { type= TEST_CMD_GET; cntmax = 0; } else if(strcmp(argv[optind],"setValue")==0) { type= TEST_CMD_SET; cntmax = 0; } else if(strcmp(argv[optind],"push")==0) { type=TEST_CMD_PUSH; cntmax = 0; } else if(strcmp(argv[optind],"removeValue")==0) { type=TEST_CMD_DELE; cnt =0; } else if(strcmp(argv[optind],"addObserver")==0) { type= TEST_CMD_ON; cntmax = 10; } else if(strcmp(argv[optind],"setAuth")==0) { type= TEST_CMD_SETAUTH; cntmax = 0; } else if(strcmp(argv[optind],"disSetValue")==0) { type= TEST_CMD_ONDISSET; cntmax = 0; } else if(strcmp(argv[optind],"disPush")==0) { type= TEST_CMD_ONDISPUSH; cntmax = 0; } else if(strcmp(argv[optind],"disRemove")==0) { type= TEST_CMD_ONDISREMOVE; cntmax = 0; } else if(strcmp(argv[optind],"cacelDis")==0) { type= TEST_CMD_CANCELDIS; cntmax = 0; } else if(strcmp(argv[optind],"offLine")==0) { type= TEST_CMD_OFFLINE; cntmax = 0; } else if(strcmp(argv[optind],"onLine")==0) { type= TEST_CMD_ONLINE; cntmax = 0; } } } if( !type) { printf("Usage: %s setAuth|getValue|setValue|push|removeValue|addObser\n" "\t|disSetValue|disPush|disRemove|cacelDis|offLine|onLine\n" "\tver -l coap://<your appid>.wilddogio.com/ [ --auth=<auth data> " "--key=<key> --value=<value>]\n", argv[0]); return 0; } /*Create an node which type is an object*/ p_head = wilddog_node_createObject(NULL); /*Create an node which type is UTF-8 Sring*/ p_node = wilddog_node_createUString((Wilddog_Str_T *)keys, \ (Wilddog_Str_T *)value); /*Add p_node to p_head, then p_node is the p_head's child node*/ wilddog_node_addChild(p_head, p_node); /*Init a wilddog client*/ wilddog = wilddog_initWithUrl((Wilddog_Str_T *)url); if(authFlag == TRUE) res = wilddog_auth((u8*)host,(u8*)authData, \ strlen((const char *)authData), auth_callback,(void*)&authFinish); switch(type) { case TEST_CMD_GET: /*Send the query method*/ res = wilddog_getValue(wilddog, (onQueryFunc)getValue_callback, \ (void*)&isFinish); break; case TEST_CMD_SET: /*Send the set method*/ res = wilddog_setValue(wilddog,p_head,setValue_callback, \ (void*)&isFinish); break; case TEST_CMD_PUSH: /*Send the push method*/ res = wilddog_push(wilddog, p_head, push_callback, \ (void *)&isFinish); break; case TEST_CMD_DELE: /*Send the remove method*/ res = wilddog_removeValue(wilddog, removeValue_callback, \ (void*)&isFinish); break; case TEST_CMD_ON: /*Observe on*/ res = wilddog_addObserver(wilddog, WD_ET_VALUECHANGE,\ addObserver_callback, \ (void*)&isFinish); break; case TEST_CMD_SETAUTH: wilddog_debug("TEST_CMD_SETAUTH token = %s",value); res = wilddog_auth((u8*)host,(u8*)value, \ strlen((const char *)value), auth_callback,(void*)&isFinish); case TEST_CMD_ONDISSET: /*Send the remove method*/ res = wilddog_onDisconnectSetValue(wilddog,p_head,onDis_callback, \ (void*)&isFinish); break; case TEST_CMD_ONDISPUSH: /*Send the remove method*/ res = wilddog_onDisconnectPush(wilddog,p_head,onDis_callback, \ (void*)&isFinish); break; case TEST_CMD_ONDISREMOVE: /*Send the remove method*/ res = wilddog_onDisconnectRemoveValue(wilddog, onDis_callback, \ (void*)&isFinish); break; case TEST_CMD_CANCELDIS: /*Send the remove method*/ res = wilddog_cancelDisconnectOperations(wilddog, onDis_callback, \ (void*)&isFinish); break; case TEST_CMD_OFFLINE: /*Send the remove method*/ res = wilddog_goOffline(); break; case TEST_CMD_ONLINE: /*Send the remove method*/ res = wilddog_goOnline(); break; } /*Delete the node*/ wilddog_node_delete(p_head); while(1) { if(TRUE == isFinish) { if(type == TEST_CMD_ON) wilddog_debug("get new data %d times! after %d times, will " \ "remove Observer.", cnt, cntmax); cnt++; isFinish = FALSE; if(cnt > cntmax)/*force break when received new data.*/ { if(type == TEST_CMD_ON) { wilddog_debug("off the data!"); /*Observe off*/ wilddog_removeObserver(wilddog, WD_ET_VALUECHANGE); } break; } } /* * Handle the event and callback function, it must be called in a * special frequency */ wilddog_trySync(); } /*Destroy the wilddog clent and release the memory*/ wilddog_destroy(&wilddog); return res; }
int demo(char* url, int* isUnConnected) { BOOL isFinish = FALSE; Wilddog_T wilddog = 0; Wilddog_Node_T * p_node = NULL, *p_head = NULL, *p_node_query = NULL; p_head = wilddog_node_createObject(NULL); /* create a new child to "wilddog" , key is "1", value is "1" */ p_node = wilddog_node_createUString((Wilddog_Str_T*)"led1",(Wilddog_Str_T*)"1"); /*p_node was p_head's child */ wilddog_node_addChild(p_head, p_node); /*creat new a client*/ wilddog = wilddog_initWithUrl((Wilddog_Str_T*)url); if(0 == wilddog) { wilddog_debug("new wilddog error"); return 0; } printf("\n\t seting led1=1 to %s\n",url); /* expect <appId>.wilddogio.com/ has a new node "1" * test_onSetFunc : handle recv data while response * */ wilddog_setValue(wilddog,p_head,test_onSetFunc,(void*)&isFinish); /* dele node */ wilddog_node_delete(p_head); while(1) { if(*isUnConnected) { wilddog_debug("wlan off!"); break; } if(TRUE == isFinish) { wilddog_debug("\tset led1=1 success!"); break; } /*retransmit¡¢ received and handle response * */ wilddog_trySync(); } printf("\n\t send query to %s \n",url); /* send query */ wilddog_getValue(wilddog, test_onQueryFunc, (void*)(&p_node_query)); while(1) { if(p_node_query) { printf("\t get %s data: \n",url); /* printf recv node as json */ wilddog_debug_printnode(p_node_query); /* free p_node_query */ wilddog_node_delete(p_node_query); printf("\n"); break; } wilddog_trySync(); } /* free wilddog*/ wilddog_destroy(&wilddog); return 0; }
int test(char *uid) { char url[1024]; char en_key = 0; BOOL isFinished = FALSE; Wilddog_T wilddog; Wilddog_Handle_T s_handle; Wilddog_Node_T *p_head = NULL, *p_node = NULL/*, *p_snapshot = NULL*/; u8 value1[5] = {246,12,0,0,6}; /*u8 value2[4] = {23,67,98,1};*/ wFloat f = 2.3; Wilddog_Node_T *root; Wilddog_Node_T *L1c1,*L1c2; Wilddog_Node_T *L2c1,*L2c2,*L2c3; Wilddog_Node_T *L3c1,*L3c2,*L3c3,*L3c4,*L3c5; Wilddog_Node_T *L4c1,*L4c2,*L4c3,*L4c4,*L4c5; int count = 0; sprintf(url,"%s%s%s",TEST_URL_HEAD,uid,TEST_URL_END); memset(&s_handle, 0, sizeof(s_handle)); s_handle.isFinished = FALSE; printf("*******************************************\n"); printf("First Step: Build the data tree \n"); printf("Please press enter key to continue!\n"); printf("*******************************************\n"); printf("*******************************************\n"); printf("\n\n"); #ifndef WILDDOG_PORT_TYPE_WICED while(1) { en_key= getchar(); if(en_key == '\n') break; } en_key = 0; #endif root = wilddog_node_createNum((Wilddog_Str_T *)"root",9999); L1c1 = wilddog_node_createFalse((Wilddog_Str_T *)"L1c1"); L1c2 = wilddog_node_createTrue((Wilddog_Str_T *)"L1c2"); L2c1 = wilddog_node_createNum((Wilddog_Str_T *)"L2c1",-10000); L2c2 = wilddog_node_createFloat((Wilddog_Str_T *)"L2c2",f); L2c3 = wilddog_node_createTrue((Wilddog_Str_T *)"L2c3"); //true L3c1 = wilddog_node_createBString((Wilddog_Str_T *)"L3c1",value1,sizeof(value1)/sizeof(u8)); //BString L3c2 = wilddog_node_createTrue((Wilddog_Str_T *)"L3c2"); L3c3 = wilddog_node_createTrue((Wilddog_Str_T *)"L3c3"); L3c4 = wilddog_node_createNull((Wilddog_Str_T *)"L3c4"); //NULL L3c5 = wilddog_node_createTrue((Wilddog_Str_T *)"L3c5"); L4c1 = wilddog_node_createNum((Wilddog_Str_T *)"L4c1",875);// +Num L4c2 = wilddog_node_createNum((Wilddog_Str_T *)"L4c2",-5693); // -Num L4c3 = wilddog_node_createFloat((Wilddog_Str_T *)"L4c3",f); //float L4c4 = wilddog_node_createFalse((Wilddog_Str_T *)"L4c4"); //false L4c5 = wilddog_node_createUString((Wilddog_Str_T *)"L4c5",(Wilddog_Str_T *)"string"); //UString if(WILDDOG_ERR_NOERR != wilddog_node_addChild(root,L1c1)) { wilddog_debug_level(WD_DEBUG_ERROR,"node add error"); } if(WILDDOG_ERR_NOERR != wilddog_node_addChild(root,L1c2)) { wilddog_debug_level(WD_DEBUG_ERROR,"node add error"); } if(WILDDOG_ERR_NOERR != wilddog_node_addChild(L1c1,L2c1)) { wilddog_debug_level(WD_DEBUG_ERROR,"node add error"); } if(WILDDOG_ERR_NOERR != wilddog_node_addChild(L1c1,L2c2)) { wilddog_debug_level(WD_DEBUG_ERROR,"node add error"); } if(WILDDOG_ERR_NOERR != wilddog_node_addChild(L1c2,L2c3)) { wilddog_debug_level(WD_DEBUG_ERROR,"node add error"); } if(WILDDOG_ERR_NOERR != wilddog_node_addChild(L2c1,L3c1)) { wilddog_debug_level(WD_DEBUG_ERROR,"node add error"); } if(WILDDOG_ERR_NOERR != wilddog_node_addChild(L2c1,L3c2)) { wilddog_debug_level(WD_DEBUG_ERROR,"node add error"); } if(WILDDOG_ERR_NOERR != wilddog_node_addChild(L2c2,L3c3)) { wilddog_debug_level(WD_DEBUG_ERROR,"node add error"); } if(WILDDOG_ERR_NOERR != wilddog_node_addChild(L2c2,L3c4)) { wilddog_debug_level(WD_DEBUG_ERROR,"node add error"); } if(WILDDOG_ERR_NOERR != wilddog_node_addChild(L2c2,L3c5)) { wilddog_debug_level(WD_DEBUG_ERROR,"node add error"); } if(WILDDOG_ERR_NOERR != wilddog_node_addChild(L3c2,L4c1)) { wilddog_debug_level(WD_DEBUG_ERROR,"node add error"); } if(WILDDOG_ERR_NOERR != wilddog_node_addChild(L3c3,L4c2)) { wilddog_debug_level(WD_DEBUG_ERROR,"node add error"); } if(WILDDOG_ERR_NOERR != wilddog_node_addChild(L3c3,L4c3)) { wilddog_debug_level(WD_DEBUG_ERROR,"node add error"); } if(WILDDOG_ERR_NOERR != wilddog_node_addChild(L3c5,L4c4)) { wilddog_debug_level(WD_DEBUG_ERROR,"node add error"); } if(WILDDOG_ERR_NOERR != wilddog_node_addChild(L3c5,L4c5)) { wilddog_debug_level(WD_DEBUG_ERROR,"node add error"); } printf("*******************************************\n"); printf("The data is built as below:\n"); wilddog_debug_printnode(root); printf("\n"); printf("*******************************************\n"); printf("\n\n"); /* printf("*******************************************\n"); printf("Second Step: Use the Node API to change the data tree\n"); printf("Change the L1c1 node's key from \"L1c1\" to \"L1c1New\" \n"); wilddog_node_setKey(L1c1,(Wilddog_Str_T *)"L1c1New"); printf("Change the L3c1 node's value from Bytestring \"{0xf6,0x0c,0x00,0x00,0x06}\" to Bytestring \"{0x17,0x43,0x62,0x01}\"\n "); wilddog_node_setValue(L3c1,value2,sizeof(value2)/sizeof(u8)); printf("Please press enter key to continue!\n"); printf("*******************************************\n"); printf("\n\n"); #ifndef WILDDOG_PORT_TYPE_WICED while(1) { en_key= getchar(); if(en_key == '\n') break; } en_key = 0; #endif printf("*******************************************\n"); printf("The data tree had changed as below:\n"); wilddog_debug_printnode(root); printf("\n"); printf("*******************************************\n"); printf("\n\n"); */ /* printf("*******************************************\n"); printf("Clone the data tree from L2c2 node\n"); printf("Print the L2c2 data tree\n"); p_snapshot = wilddog_node_clone(L2c2); wilddog_debug_printnode(p_snapshot); wilddog_node_delete(p_snapshot); printf("\n"); printf("*******************************************\n"); printf("\n\n"); */ /*************************************************************/ wilddog = wilddog_initWithUrl((Wilddog_Str_T *)url); printf("*******************************************\n"); printf("Third step: Remove the %s's data\n",uid); printf("Please press enter key to continue!\n"); printf("*******************************************\n"); printf("\n\n"); #ifndef WILDDOG_PORT_TYPE_WICED while(1) { en_key= getchar(); if(en_key == '\n') break; } en_key = 0; #endif wilddog_removeValue(wilddog, test_onDeleteFunc, (void*)&isFinished); while(1) { if(TRUE == isFinished) { wilddog_debug("remove success!"); break; } wilddog_trySync(); } isFinished = FALSE; /*************************************************************/ printf("*******************************************\n"); printf("It has removed all data in %s!\n",uid); printf("Please check the data on %s page\n",url); printf("*******************************************\n"); printf("\n\n"); printf("*******************************************\n"); printf("Fourth step: Set the root node to the %s's data tree\n",uid); printf("Please press enter key to continue!\n"); printf("*******************************************\n"); printf("\n\n"); #ifndef WILDDOG_PORT_TYPE_WICED while(1) { en_key= getchar(); if(en_key == '\n') break; } en_key = 0; #endif wilddog_setValue(wilddog,root,test_onSetFunc,(void*)&isFinished); wilddog_node_delete(root); while(1) { if(TRUE == isFinished) { wilddog_debug("set success!"); break; } wilddog_trySync(); } isFinished = FALSE; printf("*******************************************\n"); printf("It has set the data in %s!\n",uid); printf("Please check the data tree on %s page\n",url); printf("*******************************************\n"); printf("\n\n"); /*****************************************************************/ printf("*******************************************\n"); printf("Fifth step: Get the %s's data\n",uid); printf("Please press enter key to continue!\n"); printf("*******************************************\n"); printf("\n\n"); #ifndef WILDDOG_PORT_TYPE_WICED while(1) { en_key= getchar(); if(en_key == '\n') break; } en_key = 0; #endif s_handle.p_node = NULL; wilddog_getValue(wilddog, test_onQueryFunc, (void*)(&s_handle)); while(1) { if(s_handle.isFinished) { if(s_handle.p_node) { wilddog_debug("print node:"); wilddog_debug_printnode(s_handle.p_node); wilddog_node_delete(s_handle.p_node); s_handle.p_node= NULL; printf("\n"); break; } } wilddog_trySync(); } isFinished = FALSE; printf("*******************************************\n"); printf("It has get the data in %s!\n",uid); printf("Please check the data tree!\n"); printf("*******************************************\n"); printf("\n\n"); /*****************************************************************/ p_head = wilddog_node_createObject((Wilddog_Str_T *)"3"); p_node = wilddog_node_createNum((Wilddog_Str_T *)"2",1234); wilddog_node_addChild(p_head, p_node); printf("*******************************************\n"); printf("Sixth step: Build a node as \"{\"2\":1234}\"\n"); printf("Push the new node to the %s's data tree's root node\n",uid); printf("Please press enter key to continue!\n"); printf("*******************************************\n"); printf("\n\n"); #ifndef WILDDOG_PORT_TYPE_WICED while(1) { en_key= getchar(); if(en_key == '\n') break; } en_key = 0; #endif wilddog_push(wilddog, p_head, test_onPushFunc, (void *)&isFinished); wilddog_node_delete(p_head); while(1) { if(isFinished) { wilddog_debug("push success!"); break; } wilddog_trySync(); } printf("*******************************************\n"); printf("It has pushed the data in %s!\n",uid); printf("Please check the data tree on %s page\n",url); printf("\{\"2\":1234}\" will have a parent which have a long number\n");