STATIC void test_onQueryFunc( const Wilddog_Node_T* p_snapshot, void* arg, Wilddog_Return_T err) { static u8 firstin = 0; if(firstin == 0 ) { firstin = 1; } count = (count <= 0)?0:count - 1; if(err < WILDDOG_HTTP_OK || err >= WILDDOG_HTTP_NOT_MODIFIED) { d_ramtest.d_recverr++; return; } #if 0 printf("\n"); if(p_snapshot) wilddog_debug_printnode(p_snapshot); printf("\n"); #endif return;
STATIC void multiple_getValueFunc ( const Wilddog_Node_T* p_snapshot, void* arg, Wilddog_Return_T err ) { Multiple_client_T *p_client = (Multiple_client_T*)arg; p_client->d_recvFlag = 1; printf("Get : error: %d %s %p\n",err,p_client->p_host, p_snapshot); if(p_snapshot) wilddog_debug_printnode(p_snapshot); if(err < WILDDOG_HTTP_OK || err >= WILDDOG_HTTP_NOT_MODIFIED) return; else p_client->d_getResult = (u8) multiple_judge(p_snapshot,p_client->p_host); wilddog_debug(); }
STATIC void addObserver_callback ( const Wilddog_Node_T* p_snapshot, void* arg, Wilddog_Return_T err ) { *(BOOL*)arg = TRUE; if(err < WILDDOG_HTTP_OK || err >= WILDDOG_HTTP_NOT_MODIFIED) { wilddog_debug("addObserver failed!"); return; } wilddog_debug("Observe new data!"); wilddog_debug_printnode(p_snapshot); printf("\n"); return; }
STATIC void getValue_callback ( const Wilddog_Node_T* p_snapshot, void* arg, Wilddog_Return_T err ) { if(err < WILDDOG_HTTP_OK || err >= WILDDOG_HTTP_NOT_MODIFIED) { wilddog_debug("getValue fail!"); return; } *(BOOL*)arg = TRUE; if(p_snapshot) wilddog_debug_printnode(p_snapshot); printf("\ngetValue success!\n"); return; }
STATIC void addObserver_callback_b ( const Wilddog_Node_T* p_snapshot, void* arg, Wilddog_Return_T err ) { *(BOOL*)arg = TRUE; if((err < WILDDOG_HTTP_OK || err >= WILDDOG_HTTP_NOT_MODIFIED ) && err != WILDDOG_ERR_RECONNECT) { wilddog_debug(" B addObserver_callback2 failed! error code = %d",err); return; } wilddog_debug(" get B Observe !"); wilddog_debug_printnode(p_snapshot); printf("\n"); return; }
STATIC void test_onObserveFunc( const Wilddog_Node_T* p_snapshot, void* arg, Wilddog_Return_T err) { *(BOOL*)arg = TRUE; if(err < WILDDOG_HTTP_OK || err >= WILDDOG_HTTP_NOT_MODIFIED) { wilddog_debug("observe failed! err = %d", err); return; } printf("*******************************************\n"); printf("Observe the data:\n"); wilddog_debug_printnode(p_snapshot); printf("\n"); printf("*******************************************\n"); printf("\n\n"); return; }
STATIC void WD_SYSTEM test_onQueryFunc( const Wilddog_Node_T* p_snapshot, void* arg, Wilddog_Return_T err) { performtest_getHandleRecvTime(); perform_count = (perform_count <= 0)?0:perform_count - 1; if(err < WILDDOG_HTTP_OK || err >= WILDDOG_HTTP_NOT_MODIFIED) { //wilddog_debug("query error = %d!",err); g_performtest.d_recv_err++; return; } #if 0 printf("\n"); if(p_snapshot) wilddog_debug_printnode(p_snapshot); printf("\n"); #endif // wilddog_debug("query success =%d!",perform_count); return; }
void Observer_CB( const Wilddog_Node_T* p_snapshot, void* arg,Wilddog_Return_T err) { guu_is_wilddog_t *ptr_gwd; ptr_gwd = (guu_is_wilddog_t*)arg; ptr_gwd->observer_finished = TRUE; if(err < WILDDOG_HTTP_OK || err >= WILDDOG_HTTP_NOT_MODIFIED) { wilddog_debug("addObserver failed!"); return; } ptr_gwd->snapshot_clone = wilddog_node_clone(p_snapshot); /* */ // wilddog_debug("addObserver data!"); ptr_gwd->node_val = wilddog_debug_n2jsonString(p_snapshot); //printf("%s\n",ptr_gwd->node_val); #ifdef INLISP if(ptr_gwd->node_val !=NULL) { strncpy(json_buff,ptr_gwd->node_val,JSON_BUFF_LEN); if(newlisp_process_json!=NULL) { newlisp_process_json(); } } #endif // simulate response wilddog_debug_printnode(p_snapshot); printf("\n"); fflush(stdout); wfree(ptr_gwd->node_val); return; }
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");