2 Replies Latest reply on Jul 17, 2017 1:48 AM by sreynaud RSS
    sreynaud Newbie

    SDK C Remote Service: Infotable inside Infotable

    Hi Everyone,

     

    I try to include infotable inside a infotable on a remote service. When I read it with sdk C, I have only the first infotable and the other has not row. someone know how to do it?

     

    Remote service structure:

    service name (testService)

    input:

         INFOTABLE (infotable1)

    String (stringvalue)

    Integer (intvalue)

    INFOTABLE (infotable2)

         String (stringvalue2)

     

    Code C:

    register_service(){

      twDataShape * ds = 0;

      ds = twDataShape_Create(twDataShapeEntry_Create("infotable1", NULL, TW_INFOTABLE));

      twApi_RegisterService(TW_THING, thing_name, "testService", NULL, ds, TW_NUMBER, NULL, sendDataService, NULL);

     

    //get parameter

    enum msgCodeEnum sendDataService(const char * entityName, const char * serviceName, twInfoTable * params, twInfoTable ** content, void * userdata) {

      int rc = 0;

      twPrimitive *infotable1_prim;

      twInfoTable *infotable1_info;

      (void) serviceName; (void) userdata;//remove warning compile

      if (!params || !content) {

      fprintf(stdout, "sendDataService - NULL params or content pointer\n");

      return TWX_BAD_REQUEST;

      }

      twInfoTable_GetPrimitive(params, "infotable1", 0, &infotable1_prim);

     

     

      if (dinfotable1_prim != NULL && infotable1prim->length > 0)

      infotable1_info = infotable1_prim->val.infotable;

      // init command to send

      if (infotable1_info != NULL && infotable1_info->length > 0){

      twList *rowsinfotable1 = infotable1_info->rows;

      if (rowsinfotable1 != NULL){

              char * stringvalue;

              int intvalue;

      twPrimitive *infotable2_prim;

      twInfoTable *infotable2_info;

      if (rowsinfotable1->count > 0){

      int i;

      for (i = 0; i < rowsinfotable1->count; i++){

      twInfoTable_GetPrimitive(infotable1_info, "infotable2", i, &infotable2_prim);

      if (infotable2_prim != NULL && infotable2_prim->length > 0)

          infotable2_info = infotable2_prim->val.infotable;

      // init command to send

      if (infotable2_info != NULL && infotable2_info->length > 0){

           twList *rowsinfotable2 = infotable2_info->rows;

           if (rowsinfotable2 != NULL){

                char *stringvalue2;

                if (rowsinfotable2->count > 0){

                     int i;

                     for (i = 0; i < rowsinfotable2->count; i++){

                          twInfoTable_GetString(infotable2_info, "stringvalue2", i, &stringvalue2);

                          fprintf(stdout,"stringvalue2: %s \n", stringvalue2);

                     }

                        }

                   }

              }

              twInfoTable_GetString(infotable1_info, "stringvalue", i, &stringvalue);

              fprintf(stdout,"stringvalue: %s \n", stringvalue);

              twInfoTable_GetInteger(infotable1_info, "intvalue", i, &intvalue);

              fprintf(stdout,"intvalue: %d \n", intvalue);

      }

    }

                }

      }