Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Execute may return a value in the response #5

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ lwm2m_uri_t * lwm2m_decode_uri(multi_option_t *uriPath);
coap_status_t object_read(lwm2m_context_t * contextP, lwm2m_uri_t * uriP, char ** bufferP, int * lengthP);
coap_status_t object_write(lwm2m_context_t * contextP, lwm2m_uri_t * uriP, char * buffer, int length);
coap_status_t object_create(lwm2m_context_t * contextP, lwm2m_uri_t * uriP, char * buffer, int length);
coap_status_t object_execute(lwm2m_context_t * contextP, lwm2m_uri_t * uriP, char * buffer, int length);
coap_status_t object_execute(lwm2m_context_t * contextP, lwm2m_uri_t * uriP, char * rbuffer, int rlength,char ** wbuffer, int *wlength);
coap_status_t object_delete(lwm2m_context_t * contextP, lwm2m_uri_t * uriP);
bool object_isInstanceNew(lwm2m_context_t * contextP, uint16_t objectId, uint16_t instanceId);
int prv_getRegisterPayload(lwm2m_context_t * contextP, char * buffer, size_t length);
Expand Down
2 changes: 1 addition & 1 deletion core/liblwm2m.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ typedef struct _lwm2m_object_t lwm2m_object_t;

typedef uint8_t (*lwm2m_read_callback_t) (uint16_t instanceId, int * numDataP, lwm2m_tlv_t ** dataArrayP, lwm2m_object_t * objectP);
typedef uint8_t (*lwm2m_write_callback_t) (uint16_t instanceId, int numData, lwm2m_tlv_t * dataArray, lwm2m_object_t * objectP);
typedef uint8_t (*lwm2m_execute_callback_t) (uint16_t instanceId, uint16_t resourceId, char * buffer, int length, lwm2m_object_t * objectP);
typedef uint8_t (*lwm2m_execute_callback_t) (uint16_t instanceId, uint16_t resourceId, char * rbuffer, int rlength,char ** wbuffer, int *wlength, lwm2m_object_t * objectP);
typedef uint8_t (*lwm2m_create_callback_t) (uint16_t instanceId, int numData, lwm2m_tlv_t * dataArray, lwm2m_object_t * objectP);
typedef uint8_t (*lwm2m_delete_callback_t) (uint16_t instanceId, lwm2m_object_t * objectP);
typedef void (*lwm2m_close_callback_t) (lwm2m_object_t * objectP);
Expand Down
7 changes: 6 additions & 1 deletion core/management.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,12 @@ coap_status_t handle_dm_request(lwm2m_context_t * contextP,
}
else
{
result = object_execute(contextP, uriP, message->payload, message->payload_len);
char * buffer = NULL;
int length = 0;
result = object_execute(contextP, uriP, message->payload, message->payload_len, &buffer, &length);

coap_set_payload(response, buffer, length);

}
}
break;
Expand Down
10 changes: 6 additions & 4 deletions core/objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,16 +250,18 @@ coap_status_t object_write(lwm2m_context_t * contextP,

coap_status_t object_execute(lwm2m_context_t * contextP,
lwm2m_uri_t * uriP,
char * buffer,
int length)
char * rBuffer,
int rLength,
char ** wBuffer,
int * wLength)
{
switch (uriP->objectId)
{
case LWM2M_SECURITY_OBJECT_ID:
return NOT_FOUND_4_04;

case LWM2M_SERVER_OBJECT_ID:
return object_server_execute(contextP, uriP, buffer, length);
return object_server_execute(contextP, uriP, rBuffer, rLength);

default:
{
Expand All @@ -269,7 +271,7 @@ coap_status_t object_execute(lwm2m_context_t * contextP,
if (NULL == targetP) return NOT_FOUND_4_04;
if (NULL == targetP->executeFunc) return METHOD_NOT_ALLOWED_4_05;

return targetP->executeFunc(uriP->instanceId, uriP->resourceId, buffer, length, targetP);
return targetP->executeFunc(uriP->instanceId, uriP->resourceId, rBuffer, rLength, wBuffer, wLength, targetP);
}
}
}
Expand Down
8 changes: 5 additions & 3 deletions tests/client/object_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,10 @@ static uint8_t prv_device_write(uint16_t instanceId,

static uint8_t prv_device_execute(uint16_t instanceId,
uint16_t resourceId,
char * buffer,
int length,
char * rBuffer,
int rLength,
char ** wBuffer,
int *wLength,
lwm2m_object_t * objectP)
{
// this is a single instance object
Expand All @@ -424,7 +426,7 @@ static uint8_t prv_device_execute(uint16_t instanceId,
return COAP_404_NOT_FOUND;
}

if (length != 0) return COAP_400_BAD_REQUEST;
if (rLength != 0) return COAP_400_BAD_REQUEST;

switch (resourceId)
{
Expand Down
8 changes: 5 additions & 3 deletions tests/client/object_firmware.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,10 @@ static uint8_t prv_firmware_write(uint16_t instanceId,

static uint8_t prv_firmware_execute(uint16_t instanceId,
uint16_t resourceId,
char * buffer,
int length,
char * rBuffer,
int rLength,
char ** wBuffer,
int *wLength,
lwm2m_object_t * objectP)
{
firmware_data_t * data = (firmware_data_t*)(objectP->userData);
Expand All @@ -201,7 +203,7 @@ static uint8_t prv_firmware_execute(uint16_t instanceId,
return COAP_404_NOT_FOUND;
}

if (length != 0) return COAP_400_BAD_REQUEST;
if (rLength != 0) return COAP_400_BAD_REQUEST;

// for execute callback, resId is always set.
switch (resourceId)
Expand Down
10 changes: 6 additions & 4 deletions tests/client/test_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,10 @@ static uint8_t prv_create(uint16_t instanceId,

static uint8_t prv_exec(uint16_t instanceId,
uint16_t resourceId,
char * buffer,
int length,
char * rBuffer,
int rLength,
char ** wBuffer,
int *wLength,
lwm2m_object_t * objectP)
{

Expand All @@ -239,8 +241,8 @@ static uint8_t prv_exec(uint16_t instanceId,
fprintf(stdout, "\r\n-----------------\r\n"
"Execute on %hu/%d/%d\r\n"
" Parameter (%d bytes):\r\n",
objectP->objID, instanceId, resourceId, length);
prv_output_buffer(buffer, length);
objectP->objID, instanceId, resourceId, rLength);
prv_output_buffer(rBuffer, rLength);
fprintf(stdout, "-----------------\r\n\r\n");
return COAP_204_CHANGED;
default:
Expand Down