• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ LWM2M_URI_IS_SET_INSTANCE函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中LWM2M_URI_IS_SET_INSTANCE函数的典型用法代码示例。如果您正苦于以下问题:C++ LWM2M_URI_IS_SET_INSTANCE函数的具体用法?C++ LWM2M_URI_IS_SET_INSTANCE怎么用?C++ LWM2M_URI_IS_SET_INSTANCE使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了LWM2M_URI_IS_SET_INSTANCE函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: observe_findByUri

lwm2m_observed_t * observe_findByUri(lwm2m_context_t * contextP,
                                     lwm2m_uri_t * uriP)
{
    lwm2m_observed_t * targetP;

    LOG_URI(uriP);
    targetP = contextP->observedList;
    while (targetP != NULL)
    {
        if (targetP->uri.objectId == uriP->objectId)
        {
            if ((!LWM2M_URI_IS_SET_INSTANCE(uriP) && !LWM2M_URI_IS_SET_INSTANCE(&(targetP->uri)))
             || (LWM2M_URI_IS_SET_INSTANCE(uriP) && LWM2M_URI_IS_SET_INSTANCE(&(targetP->uri)) && (uriP->instanceId == targetP->uri.instanceId)))
             {
                 if ((!LWM2M_URI_IS_SET_RESOURCE(uriP) && !LWM2M_URI_IS_SET_RESOURCE(&(targetP->uri)))
                     || (LWM2M_URI_IS_SET_RESOURCE(uriP) && LWM2M_URI_IS_SET_RESOURCE(&(targetP->uri)) && (uriP->resourceId == targetP->uri.resourceId)))
                 {
                     LOG_ARG("Found one with%s observers.", targetP->watcherList ? "" : " no");
                     LOG_URI(&(targetP->uri));
                     return targetP;
                 }
             }
        }
        targetP = targetP->next;
    }

    LOG("Found nothing");
    return NULL;
}
开发者ID:davidgraeff,项目名称:wakaama,代码行数:29,代码来源:observe.c


示例2: observe_findByUri

lwm2m_observed_t * observe_findByUri(lwm2m_context_t * contextP,
                                     lwm2m_uri_t * uriP)
{
    lwm2m_observed_t * targetP;

    targetP = contextP->observedList;
    while (targetP != NULL)
    {
        if (targetP->uri.objectId == uriP->objectId)
        {
            if ((!LWM2M_URI_IS_SET_INSTANCE(uriP) && !LWM2M_URI_IS_SET_INSTANCE(&(targetP->uri)))
             || (LWM2M_URI_IS_SET_INSTANCE(uriP) && LWM2M_URI_IS_SET_INSTANCE(&(targetP->uri)) && (uriP->instanceId == targetP->uri.instanceId)))
             {
                 if ((!LWM2M_URI_IS_SET_RESOURCE(uriP) && !LWM2M_URI_IS_SET_RESOURCE(&(targetP->uri)))
                     || (LWM2M_URI_IS_SET_RESOURCE(uriP) && LWM2M_URI_IS_SET_RESOURCE(&(targetP->uri)) && (uriP->resourceId == targetP->uri.resourceId)))
                 {
                     return targetP;
                 }
             }
        }
        targetP = targetP->next;
    }

    return NULL;
}
开发者ID:JayanthSreenivasa,项目名称:wakaama,代码行数:25,代码来源:observe.c


示例3: lwm2m_dm_write

int lwm2m_dm_write(lwm2m_context_t * contextP,
                   uint16_t clientID,
                   lwm2m_uri_t * uriP,
                   lwm2m_media_type_t format,
                   uint8_t * buffer,
                   int length,
                   lwm2m_result_callback_t callback,
                   void * userData)
{
    LOG_ARG("clientID: %d, format: %s, length: %d", clientID, STR_MEDIA_TYPE(format), length);
    LOG_URI(uriP);
    if (!LWM2M_URI_IS_SET_INSTANCE(uriP)
     || length == 0)
    {
        return COAP_400_BAD_REQUEST;
    }

    if (LWM2M_URI_IS_SET_RESOURCE(uriP))
    {
        return prv_makeOperation(contextP, clientID, uriP,
                                  COAP_PUT,
                                  format, buffer, length,
                                  callback, userData);
    }
    else
    {
        return prv_makeOperation(contextP, clientID, uriP,
                                  COAP_POST,
                                  format, buffer, length,
                                  callback, userData);
    }
}
开发者ID:bsinno,项目名称:wakaama,代码行数:32,代码来源:management.c


示例4: lwm2m_dm_write

int lwm2m_dm_write(lwm2m_context_t * contextP,
                   uint16_t clientID,
                   lwm2m_uri_t * uriP,
                   uint8_t * buffer,
                   int length,
                   lwm2m_result_callback_t callback,
                   void * userData)
{
    if (!LWM2M_URI_IS_SET_INSTANCE(uriP)
     || length == 0)
    {
        return COAP_400_BAD_REQUEST;
    }

    if (LWM2M_URI_IS_SET_RESOURCE(uriP))
    {
        return prv_make_operation(contextP, clientID, uriP,
                                  COAP_PUT,
                                  LWM2M_CONTENT_TEXT, buffer, length,
                                  callback, userData);
    }
    else
    {
        return prv_make_operation(contextP, clientID, uriP,
                                  COAP_POST,
                                  LWM2M_CONTENT_TLV, buffer, length,
                                  callback, userData);
    }
}
开发者ID:Jason-Gew,项目名称:wakaama,代码行数:29,代码来源:management.c


示例5: prv_result_callback

static void prv_result_callback(uint16_t clientID,
                                lwm2m_uri_t * uriP,
                                int status,
                                uint8_t * data,
                                int dataLength,
                                void * userData)
{
    fprintf(stdout, "\r\nClient #%d %d", clientID, uriP->objectId);
    if (LWM2M_URI_IS_SET_INSTANCE(uriP))
        fprintf(stdout, "/%d", uriP->instanceId);
    else if (LWM2M_URI_IS_SET_RESOURCE(uriP))
        fprintf(stdout, "/");
    if (LWM2M_URI_IS_SET_RESOURCE(uriP))
            fprintf(stdout, "/%d", uriP->resourceId);
    fprintf(stdout, " returned status %d.%2d\r\n", (status&0xE0)>>5, status&0x1F);

    if (data != NULL)
    {
        fprintf(stdout, "%d bytes received:\r\n", dataLength);
        prv_output_buffer(stdout, data, dataLength);
    }

    fprintf(stdout, "\r\n> ");
    fflush(stdout);
}
开发者ID:1248,项目名称:liblwm2m,代码行数:25,代码来源:lwm2mserver.c


示例6: lwm2m_resource_value_changed

void lwm2m_resource_value_changed(lwm2m_context_t * contextP,
                                  lwm2m_uri_t * uriP)
{
    lwm2m_observed_t * targetP;

    LOG("lwm2m_resource_value_changed(/%d/%d/%d)\n", uriP->objectId, uriP->instanceId, uriP->resourceId);
    targetP = contextP->observedList;
    while (targetP != NULL)
    {
        if (targetP->uri.objectId == uriP->objectId)
        {
            if (!LWM2M_URI_IS_SET_INSTANCE(uriP)
             || (targetP->uri.flag & LWM2M_URI_FLAG_INSTANCE_ID) == 0
             || uriP->instanceId == targetP->uri.instanceId)
            {
                if (!LWM2M_URI_IS_SET_RESOURCE(uriP)
                 || (targetP->uri.flag & LWM2M_URI_FLAG_RESOURCE_ID) == 0
                 || uriP->resourceId == targetP->uri.resourceId)
                {
                    lwm2m_watcher_t * watcherP;

                    for (watcherP = targetP->watcherList ; watcherP != NULL ; watcherP = watcherP->next)
                    {
                        if ( watcherP->active == true) watcherP->update = true;
                    }
                }
            }
        }
        targetP = targetP->next;
    }
}
开发者ID:JayanthSreenivasa,项目名称:wakaama,代码行数:31,代码来源:observe.c


示例7: prv_write

static uint8_t prv_write(lwm2m_uri_t * uriP,
                         char * buffer,
                         int length,
                         lwm2m_object_t * objectP)
{
    prv_instance_t * targetP;
    int64_t value;

    // for write, instance ID is always set
    targetP = (prv_instance_t *)lwm2m_list_find(objectP->instanceList, uriP->instanceId);
    if (NULL == targetP) return COAP_404_NOT_FOUND;

    if (!LWM2M_URI_IS_SET_INSTANCE(uriP)) return COAP_501_NOT_IMPLEMENTED;

    switch (uriP->resourceId)
    {
    case 1:
        if (1 == lwm2m_PlainTextToInt64(buffer, length, &value))
        {
            if (value >= 0 && value <= 0xFF)
            {
                targetP->test = value;
                return COAP_204_CHANGED;
            }
        }
        return COAP_400_BAD_REQUEST;
    default:
        return COAP_404_NOT_FOUND;
    }
}
开发者ID:fab13n,项目名称:liblwm2m,代码行数:30,代码来源:test_object.c


示例8: prv_firmware_execute

static uint8_t prv_firmware_execute(lwm2m_uri_t * uriP,
                                  char * buffer,
                                  int length,
                                  lwm2m_object_t * objectP)
{
    // this is a single instance object
    if (LWM2M_URI_IS_SET_INSTANCE(uriP) && uriP->instanceId != 0)
    {
        return COAP_404_NOT_FOUND;
    }

    if (length != 0) return COAP_400_BAD_REQUEST;

    firmware_data_t * data = (firmware_data_t*)(objectP->userData);

    // for execute callback, resId is always set.
    switch (uriP->resourceId)
    {
    case 2:
        if (data->state == 1)
        {
            fprintf(stdout, "\n\t FIRMWARE UPDATE\r\n\n");
            // trigger your firmware download and update logic
            data->state = 2;
            return COAP_204_CHANGED;
        } else {
            // firmware update already running
            return COAP_400_BAD_REQUEST;
        }
    default:
        return COAP_405_METHOD_NOT_ALLOWED;
    }
}
开发者ID:domedambrosio,项目名称:liblwm2m,代码行数:33,代码来源:object_firmware.c


示例9: object_checkReadable

uint8_t object_checkReadable(lwm2m_context_t * contextP,
                             lwm2m_uri_t * uriP)
{
    coap_status_t result;
    lwm2m_object_t * targetP;
    lwm2m_data_t * dataP = NULL;
    int size;

    targetP = (lwm2m_object_t *)LWM2M_LIST_FIND(contextP->objectList, uriP->objectId);
    if (NULL == targetP) return COAP_404_NOT_FOUND;
    if (NULL == targetP->readFunc) return COAP_405_METHOD_NOT_ALLOWED;

    if (!LWM2M_URI_IS_SET_INSTANCE(uriP)) return COAP_205_CONTENT;

    if (NULL == lwm2m_list_find(targetP->instanceList, uriP->instanceId)) return COAP_404_NOT_FOUND;

    if (!LWM2M_URI_IS_SET_RESOURCE(uriP)) return COAP_205_CONTENT;

    size = 1;
    dataP = lwm2m_data_new(1);
    if (dataP == NULL) return COAP_500_INTERNAL_SERVER_ERROR;

    dataP->id = uriP->resourceId;

    result = targetP->readFunc(uriP->instanceId, &size, &dataP, targetP);
    lwm2m_data_free(1, dataP);

    return result;
}
开发者ID:JayanthSreenivasa,项目名称:wakaama,代码行数:29,代码来源:objects.c


示例10: object_readData

coap_status_t object_readData(lwm2m_context_t * contextP,
                               lwm2m_uri_t * uriP,
                               int * sizeP,
                               lwm2m_data_t ** dataP)
{
    coap_status_t result;
    lwm2m_object_t * targetP;

    targetP = (lwm2m_object_t *)LWM2M_LIST_FIND(contextP->objectList, uriP->objectId);
    if (NULL == targetP) return COAP_404_NOT_FOUND;
    if (NULL == targetP->readFunc) return COAP_405_METHOD_NOT_ALLOWED;
    if (targetP->instanceList == NULL) return COAP_404_NOT_FOUND;

    if (LWM2M_URI_IS_SET_INSTANCE(uriP))
    {
        if (NULL == lwm2m_list_find(targetP->instanceList, uriP->instanceId)) return COAP_404_NOT_FOUND;

        // single instance read
        if (LWM2M_URI_IS_SET_RESOURCE(uriP))
        {
            *sizeP = 1;
            *dataP = lwm2m_data_new(*sizeP);
            if (*dataP == NULL) return COAP_500_INTERNAL_SERVER_ERROR;

            (*dataP)->id = uriP->resourceId;
        }

        result = targetP->readFunc(uriP->instanceId, sizeP, dataP, targetP);
    }
    else
    {
        // multiple object instances read
        lwm2m_list_t * instanceP;
        int i;

        *sizeP = 0;
        for (instanceP = targetP->instanceList; instanceP != NULL ; instanceP = instanceP->next)
        {
            (*sizeP)++;
        }

        *dataP = lwm2m_data_new(*sizeP);
        if (*dataP == NULL) return COAP_500_INTERNAL_SERVER_ERROR;

        result = COAP_205_CONTENT;
        instanceP = targetP->instanceList;
        i = 0;
        while (instanceP != NULL && result == COAP_205_CONTENT)
        {
            result = targetP->readFunc(instanceP->id, (int*)&((*dataP)[i].value.asChildren.count), &((*dataP)[i].value.asChildren.array), targetP);
            (*dataP)[i].type = LWM2M_TYPE_OBJECT_INSTANCE;
            (*dataP)[i].id = instanceP->id;
            i++;
            instanceP = instanceP->next;
        }
    }

    return result;
}
开发者ID:JayanthSreenivasa,项目名称:wakaama,代码行数:59,代码来源:objects.c


示例11: observe_handleRequest

coap_status_t observe_handleRequest(lwm2m_context_t * contextP,
                                    lwm2m_uri_t * uriP,
                                    lwm2m_server_t * serverP,
                                    int size,
                                    lwm2m_data_t * dataP,
                                    coap_packet_t * message,
                                    coap_packet_t * response)
{
    lwm2m_watcher_t * watcherP;
    uint32_t count;

    LOG("observe_handleRequest()\r\n");

    coap_get_header_observe(message, &count);

    switch (count)
    {
    case 0:
        if (!LWM2M_URI_IS_SET_INSTANCE(uriP) && LWM2M_URI_IS_SET_RESOURCE(uriP)) return COAP_400_BAD_REQUEST;
        if (message->token_len == 0) return COAP_400_BAD_REQUEST;

        watcherP = prv_getWatcher(contextP, uriP, serverP);
        if (watcherP == NULL) return COAP_500_INTERNAL_SERVER_ERROR;

        watcherP->tokenLen = message->token_len;
        memcpy(watcherP->token, message->token, message->token_len);
        watcherP->active = true;
        watcherP->lastTime = lwm2m_gettime();

        if (LWM2M_URI_IS_SET_RESOURCE(uriP))
        {
            switch (dataP->type)
            {
            case LWM2M_TYPE_INTEGER:
                if (1 != lwm2m_data_decode_int(dataP, &(watcherP->lastValue.asInteger))) return COAP_500_INTERNAL_SERVER_ERROR;
                break;
            case LWM2M_TYPE_FLOAT:
                if (1 != lwm2m_data_decode_float(dataP, &(watcherP->lastValue.asFloat))) return COAP_500_INTERNAL_SERVER_ERROR;
                break;
            default:
                break;
            }
        }

        coap_set_header_observe(response, watcherP->counter++);

        return COAP_205_CONTENT;

    case 1:
        // cancellation
        observe_cancel(contextP, LWM2M_MAX_ID, serverP->sessionH);
        return COAP_205_CONTENT;

    default:
        return COAP_400_BAD_REQUEST;
    }
}
开发者ID:JayanthSreenivasa,项目名称:wakaama,代码行数:57,代码来源:observe.c


示例12: transaction_new

lwm2m_transaction_t * transaction_new(coap_method_t method,
                                      lwm2m_uri_t * uriP,
                                      uint16_t mID,
                                      lwm2m_endpoint_type_t peerType,
                                      void * peerP)
{
    lwm2m_transaction_t * transacP;
    int result;

    transacP = (lwm2m_transaction_t *)lwm2m_malloc(sizeof(lwm2m_transaction_t));

    if (transacP == NULL) return NULL;
    memset(transacP, 0, sizeof(lwm2m_transaction_t));

    transacP->message = lwm2m_malloc(sizeof(coap_packet_t));
    if (transacP->message == NULL) goto error;

    coap_init_message(transacP->message, COAP_TYPE_CON, method, mID);

    transacP->mID = mID;
    transacP->peerType = peerType;
    transacP->peerP = peerP;

    if (uriP != NULL)
    {
        result = snprintf(transacP->objStringID, LWM2M_STRING_ID_MAX_LEN, "%hu", uriP->objectId);
        if (result < 0 || result > LWM2M_STRING_ID_MAX_LEN) goto error;

        coap_set_header_uri_path_segment(transacP->message, transacP->objStringID);

        if (LWM2M_URI_IS_SET_INSTANCE(uriP))
        {
            result = snprintf(transacP->instanceStringID, LWM2M_STRING_ID_MAX_LEN, "%hu", uriP->instanceId);
            if (result < 0 || result > LWM2M_STRING_ID_MAX_LEN) goto error;
            coap_set_header_uri_path_segment(transacP->message, transacP->instanceStringID);
        }
        else
        {
            if (LWM2M_URI_IS_SET_RESOURCE(uriP))
            {
                coap_set_header_uri_path_segment(transacP->message, NULL);
            }
        }
        if (LWM2M_URI_IS_SET_RESOURCE(uriP))
        {
            result = snprintf(transacP->resourceStringID, LWM2M_STRING_ID_MAX_LEN, "%hu", uriP->resourceId);
            if (result < 0 || result > LWM2M_STRING_ID_MAX_LEN) goto error;
            coap_set_header_uri_path_segment(transacP->message, transacP->resourceStringID);
        }
    }

    return transacP;

error:
    lwm2m_free(transacP);
    return NULL;
}
开发者ID:01org,项目名称:liblwm2m,代码行数:57,代码来源:transaction.c


示例13: uri_toString

int uri_toString(lwm2m_uri_t * uriP,
                 uint8_t * buffer,
                 size_t bufferLen,
                 uri_depth_t * depthP)
{
    size_t head;
    int res;

    LOG_ARG("bufferLen: %u", bufferLen);
    LOG_URI(uriP);

    buffer[0] = '/';

    if (uriP == NULL)
    {
        if (depthP) *depthP = URI_DEPTH_OBJECT;
        return 1;
    }

    head = 1;

    res = utils_intToText(uriP->objectId, buffer + head, bufferLen - head);
    if (res <= 0) return -1;
    head += res;
    if (head >= bufferLen - 1) return -1;
    if (depthP) *depthP = URI_DEPTH_OBJECT_INSTANCE;

    if (LWM2M_URI_IS_SET_INSTANCE(uriP))
    {
        buffer[head] = '/';
        head++;
        res = utils_intToText(uriP->instanceId, buffer + head, bufferLen - head);
        if (res <= 0) return -1;
        head += res;
        if (head >= bufferLen - 1) return -1;
        if (depthP) *depthP = URI_DEPTH_RESOURCE;
        if (LWM2M_URI_IS_SET_RESOURCE(uriP))
        {
            buffer[head] = '/';
            head++;
            res = utils_intToText(uriP->resourceId, buffer + head, bufferLen - head);
            if (res <= 0) return -1;
            head += res;
            if (head >= bufferLen - 1) return -1;
            if (depthP) *depthP = URI_DEPTH_RESOURCE_INSTANCE;
        }
    }

    buffer[head] = '/';
    head++;

    LOG_ARG("length: %u, buffer: \"%.*s\"", head, head, buffer);

    return head;
}
开发者ID:drashti304,项目名称:TizenRT,代码行数:55,代码来源:uri.c


示例14: object_server_read

coap_status_t object_server_read(lwm2m_context_t * contextP,
                                 lwm2m_uri_t * uriP,
                                 char ** bufferP,
                                 int * lengthP)
{
    if (!LWM2M_URI_IS_SET_INSTANCE(uriP))
    {
        return COAP_501_NOT_IMPLEMENTED;
    }
    else
    {
        lwm2m_server_t * serverP;

        serverP = (lwm2m_server_t *)lwm2m_list_find((lwm2m_list_t *)contextP->serverList, uriP->instanceId);
        if (serverP == NULL) return COAP_404_NOT_FOUND;

        if (!LWM2M_URI_IS_SET_RESOURCE(uriP))
        {
            return COAP_501_NOT_IMPLEMENTED;
        }
        else
        {
            switch (uriP->resourceId)
            {
            case RESOURCE_SHORTID_ID:
                *lengthP = lwm2m_int32ToPlainText(serverP->shortID, bufferP);
                if (0 != *lengthP)
                {
                    return COAP_205_CONTENT;
                }
                else
                {
                    return COAP_500_INTERNAL_SERVER_ERROR;
                }
                break;

            case RESOURCE_LIFETIME_ID:
                return COAP_501_NOT_IMPLEMENTED;
            case RESOURCE_MINPERIOD_ID:
                return COAP_404_NOT_FOUND;
            case RESOURCE_MAXPERIOD_ID:
                return COAP_404_NOT_FOUND;
            case RESOURCE_TIMEOUT_ID:
                return COAP_404_NOT_FOUND;
            case RESOURCE_STORING_ID:
                return COAP_501_NOT_IMPLEMENTED;
            case RESOURCE_BINDING_ID:
                return COAP_501_NOT_IMPLEMENTED;
            default:
                return COAP_405_METHOD_NOT_ALLOWED;
            }
        }
    }
}
开发者ID:domedambrosio,项目名称:wakaama,代码行数:54,代码来源:object_server.c


示例15: lwm2m_observe

int ICACHE_FLASH_ATTR
lwm2m_observe(lwm2m_context_t * contextP,
                  uint16_t clientID,
                  lwm2m_uri_t * uriP,
                  lwm2m_result_callback_t callback,
                  void * userData)
{
    lwm2m_client_t * clientP;
    lwm2m_transaction_t * transactionP;
    lwm2m_observation_t * observationP;
    uint8_t token[4];

    if (!LWM2M_URI_IS_SET_INSTANCE(uriP) && LWM2M_URI_IS_SET_RESOURCE(uriP)) return COAP_400_BAD_REQUEST;

    clientP = (lwm2m_client_t *)lwm2m_list_find((lwm2m_list_t *)contextP->clientList, clientID);
    if (clientP == NULL) return COAP_404_NOT_FOUND;

    observationP = (lwm2m_observation_t *)lwm2m_malloc(sizeof(lwm2m_observation_t));
    if (observationP == NULL) return COAP_500_INTERNAL_SERVER_ERROR;
    c_memset(observationP, 0, sizeof(lwm2m_observation_t));

    observationP->id = lwm2m_list_newId((lwm2m_list_t *)clientP->observationList);
    c_memcpy(&observationP->uri, uriP, sizeof(lwm2m_uri_t));
    observationP->clientP = clientP;
    observationP->status = STATE_REG_PENDING;
    observationP->callback = callback;
    observationP->userData = userData;

    token[0] = clientP->internalID >> 8;
    token[1] = clientP->internalID & 0xFF;
    token[2] = observationP->id >> 8;
    token[3] = observationP->id & 0xFF;

    transactionP = transaction_new(COAP_TYPE_CON, COAP_GET, clientP->altPath, uriP, contextP->nextMID++, 4, token, ENDPOINT_CLIENT, (void *)clientP);
    if (transactionP == NULL)
    {
        lwm2m_free(observationP);
        return COAP_500_INTERNAL_SERVER_ERROR;
    }

    observationP->clientP->observationList = (lwm2m_observation_t *)LWM2M_LIST_ADD(observationP->clientP->observationList, observationP);

    coap_set_header_observe(transactionP->message, 0);
    coap_set_header_token(transactionP->message, token, sizeof(token));

    transactionP->callback = prv_obsRequestCallback;
    transactionP->userData = (void *)observationP;

    contextP->transactionList = (lwm2m_transaction_t *)LWM2M_LIST_ADD(contextP->transactionList, transactionP);

    return transaction_send(contextP, transactionP);
}
开发者ID:jollen,项目名称:node-wot,代码行数:52,代码来源:observe.c


示例16: prv_create

static uint8_t prv_create(lwm2m_uri_t * uriP,
                          char * buffer,
                          int length,
                          lwm2m_object_t * objectP)
{
    prv_instance_t * targetP;
    lwm2m_tlv_type_t type;
    uint16_t newId;
    uint16_t resID;
    size_t dataIndex;
    size_t dataLen;
    int result;
    int64_t value;

    if (LWM2M_URI_IS_SET_INSTANCE(uriP))
    {
        targetP = (prv_instance_t *)lwm2m_list_find(objectP->instanceList, uriP->instanceId);
        if (targetP != NULL) return COAP_406_NOT_ACCEPTABLE;
        newId = uriP->instanceId;
    }
    else
    {
        // determine a new unique ID
        newId = lwm2m_list_newId(objectP->instanceList);
    }

    result = lwm2m_decodeTLV(buffer, length, &type, &resID, &dataIndex, &dataLen);
    if (result != length)
    {
        // decode failure or too much data for our single ressource object
        return COAP_400_BAD_REQUEST;
    }
    if (type != TLV_RESSOURCE || resID != 1)
    {
        return COAP_400_BAD_REQUEST;
    }
    result = lwm2m_opaqueToInt(buffer + dataIndex, dataLen, &value);
    if (result == 0 || value < 0 || value > 255)
        return COAP_400_BAD_REQUEST;

    targetP = (prv_instance_t *)malloc(sizeof(prv_instance_t));
    if (NULL == targetP) return COAP_500_INTERNAL_SERVER_ERROR;
    memset(targetP, 0, sizeof(prv_instance_t));
    targetP->shortID = newId;
    targetP->test = value;
    objectP->instanceList = LWM2M_LIST_ADD(objectP->instanceList, targetP);

    return COAP_201_CREATED;
}
开发者ID:fab13n,项目名称:liblwm2m,代码行数:49,代码来源:test_object.c


示例17: prv_print_uri

static void prv_print_uri(FILE * fd,
                          lwm2m_uri_t * uriP)
{
    fprintf(fd, "/");
    if (uriP != NULL)
    {
        fprintf(fd, "%hu", uriP->objectId);
        if (LWM2M_URI_IS_SET_INSTANCE(uriP))
        {
            fprintf(fd, "/%d", uriP->instanceId);
            if (LWM2M_URI_IS_SET_RESOURCE(uriP))
                fprintf(fd, "/%d", uriP->resourceId);
        }
    }
}
开发者ID:weatherxm,项目名称:wakaama,代码行数:15,代码来源:bootstrap_server.c


示例18: object_create

coap_status_t ICACHE_FLASH_ATTR
object_create(lwm2m_context_t * contextP,
                            lwm2m_uri_t * uriP,
                            lwm2m_media_type_t format,
                            uint8_t * buffer,
                            size_t length)
{
    lwm2m_object_t * targetP;
    lwm2m_data_t * dataP = NULL;
    int size = 0;
    uint8_t result;

    if (length == 0 || buffer == 0)
    {
        return BAD_REQUEST_4_00;
    }

    targetP = prv_find_object(contextP, uriP->objectId);
    if (NULL == targetP) return NOT_FOUND_4_04;
    if (NULL == targetP->createFunc) return METHOD_NOT_ALLOWED_4_05;

    if (LWM2M_URI_IS_SET_INSTANCE(uriP))
    {
        if (NULL != lwm2m_list_find(targetP->instanceList, uriP->instanceId))
        {
            // Instance already exists
            return COAP_406_NOT_ACCEPTABLE;
        }
    }
    else
    {
        uriP->instanceId = lwm2m_list_newId(targetP->instanceList);
        uriP->flag |= LWM2M_URI_FLAG_INSTANCE_ID;
    }

    size = lwm2m_data_parse(buffer, length, format, &dataP);
    if (size == 0) return COAP_500_INTERNAL_SERVER_ERROR;
#ifdef ICACHE_FLASH_ATTR
    if (contextP->bsState == BOOTSTRAP_PENDING)
    {
        dataP->flags |= LWM2M_TLV_FLAG_BOOTSTRAPPING;
    }
#endif
    result = targetP->createFunc(uriP->instanceId, size, dataP, targetP);
    lwm2m_data_free(size, dataP);

    return result;
}
开发者ID:jollen,项目名称:node-wot,代码行数:48,代码来源:objects.c


示例19: lwm2m_dm_delete

int lwm2m_dm_delete(lwm2m_context_t * contextP,
                    uint16_t clientID,
                    lwm2m_uri_t * uriP,
                    lwm2m_result_callback_t callback,
                    void * userData)
{
    if (!LWM2M_URI_IS_SET_INSTANCE(uriP)
     || LWM2M_URI_IS_SET_RESOURCE(uriP))
    {
        return COAP_400_BAD_REQUEST;
    }

    return prv_make_operation(contextP, clientID, uriP,
                              COAP_DELETE, NULL, 0,
                              callback, userData);
}
开发者ID:1248,项目名称:liblwm2m,代码行数:16,代码来源:management.c


示例20: handle_observe_request

coap_status_t handle_observe_request(lwm2m_context_t * contextP,
                                     lwm2m_uri_t * uriP,
                                     uint8_t * fromAddr,
                                     size_t fromAddrLen,
                                     coap_packet_t * message,
                                     coap_packet_t * response)
{
    lwm2m_observed_t * observedP;
    lwm2m_watcher_t * watcherP;
    lwm2m_server_t * serverP;

    LOG("handle_observe_request()\r\n");

    if (!LWM2M_URI_IS_SET_INSTANCE(uriP) && LWM2M_URI_IS_SET_RESOURCE(uriP)) return COAP_400_BAD_REQUEST;
    if (message->token_len == 0) return COAP_400_BAD_REQUEST;

    serverP = prv_findServer(contextP, fromAddr, fromAddrLen);
    if (serverP == NULL || serverP->status != STATE_REGISTERED) return COAP_401_UNAUTHORIZED;

    observedP = prv_findObserved(contextP, uriP);
    if (observedP == NULL)
    {
        observedP = (lwm2m_observed_t *)lwm2m_malloc(sizeof(lwm2m_observed_t));
        if (observedP == NULL) return COAP_500_INTERNAL_SERVER_ERROR;
        memset(observedP, 0, sizeof(lwm2m_observed_t));
        memcpy(&(observedP->uri), uriP, sizeof(lwm2m_uri_t));
        observedP->next = contextP->observedList;
        contextP->observedList = observedP;
    }

    watcherP = prv_findWatcher(observedP, serverP);
    if (watcherP == NULL)
    {
        watcherP = (lwm2m_watcher_t *)lwm2m_malloc(sizeof(lwm2m_watcher_t));
        if (watcherP == NULL) return COAP_500_INTERNAL_SERVER_ERROR;
        memset(watcherP, 0, sizeof(lwm2m_watcher_t));
        watcherP->server = serverP;
        watcherP->tokenLen = message->token_len;
        memcpy(watcherP->token, message->token, message->token_len);
        watcherP->next = observedP->watcherList;
        observedP->watcherList = watcherP;
    }

    coap_set_header_observe(response, watcherP->counter++);

    return COAP_205_CONTENT;
}
开发者ID:1248,项目名称:liblwm2m,代码行数:47,代码来源:observe.c



注:本文中的LWM2M_URI_IS_SET_INSTANCE函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ LWM2M_URI_IS_SET_RESOURCE函数代码示例发布时间:2022-05-30
下一篇:
C++ LWLockRelease函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap