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;
}
Ejemplo n.º 2
0
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;
}
Ejemplo n.º 3
0
Wilddog_T  check_finished( guu_is_wilddog_t* gwd) // in a while(1) loop
{
	if(TRUE == gwd->observer_finished) 
	{
		//wilddog_debug("get new data %d times!", count++);
		gwd->observer_finished = FALSE;
		set_receive_time(gwd);
    if(gwd->count > 0)
    {
      //wilddog_debug("off the data!");
      wilddog_removeObserver(gwd->wd, WD_ET_VALUECHANGE);                                 
      return 0;
    }
  }

	if(TRUE == gwd->setvalue_finished)
	{
		gwd->setvalue_finished = FALSE;
		wilddog_debug("set success");
	}
	return 1;
}
Ejemplo n.º 4
0
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;
}