Skip to content

Commit

Permalink
Modify Static Client API to separate Resource definition from setting…
Browse files Browse the repository at this point in the history
… a Resource Operation handler, or storage pointer.

    Add AwaStaticClient_DefineResource().
    Add AwaStaticClient_SetResourceOperationHandler().
    Add AwaStaticClient_SetResourceStorageWithPointer().
    Add AwaStaticClient_SetResourceStorageWithPointerArray().
    Deprecate AwaStaticClient_DefineResourceWithHandler().
    Deprecate AwaStaticClient_DefineResourceWithPointer().
    Deprecate AwaStaticClient_DefineResourceWithPointerArray().

Signed-off-by: David Antliff <[email protected]>
  • Loading branch information
David Antliff committed May 2, 2016
1 parent d1513c5 commit beb56e8
Show file tree
Hide file tree
Showing 10 changed files with 2,106 additions and 81 deletions.
102 changes: 97 additions & 5 deletions api/include/awa/static.h
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ void AwaStaticClient_Free(AwaStaticClient ** client);
* that will be called whenever a LWM2M operation on any instance of the
* defined object is performed.
*
* In order for an LWM2M server to perform operations on the defined object,
* @note In order for an LWM2M server to perform operations on the defined object,
* a matching object must be defined on the LWM2M server.
*
* @param[in] client A pointer to a valid Awa Static Client.
Expand All @@ -409,7 +409,7 @@ AwaError AwaStaticClient_DefineObjectWithHandler(AwaStaticClient * client, const
* @brief Define a new custom LWM2M object. By default, the LWM2M Client will handle instance operations such as delete and create.
* Use ::AwaStaticClient_SetObjectOperationHandler to override this default behaviour with a specified handler.
*
* In order for an LWM2M server to perform operations on the defined object,
* @note In order for an LWM2M server to perform operations on the defined object,
* a matching object must be defined on the LWM2M server.
*
* @param[in] client A pointer to a valid Awa Static Client.
Expand Down Expand Up @@ -438,10 +438,98 @@ AwaError AwaStaticClient_DefineObject(AwaStaticClient * client, const char * obj
AwaError AwaStaticClient_SetObjectOperationHandler(AwaStaticClient * client, AwaObjectID objectID, AwaStaticClientHandler handler);

/**
* @brief Define a new resource of an existing object. By default, the LWM2M Client will handle resource operations.
* Use ::AwaStaticClient_SetResourceOperationHandler, ::AwaStaticClient_SetResourceStorageWithPointer or ::AwaStaticClient_SetResourceStorageWithPointerArray
* to configure whether operations are handled by the user, or directed to operate on static memory.
*
* @note In order for an LWM2M server to perform operations on the defined resource,
* a matching object with resources must be defined on the LWM2M server.
*
* @param[in] client A pointer to a valid Awa Static Client.
* @param[in] resourceName A human-friendly name for the new resource.
* @param[in] objectID An ID that uniquely identifies the object which will contain the new resource.
* @param[in] resourceID An ID that uniquely identifies the new resource within the object.
* @param[in] resourceType The type of the new resource.
* @param[in] minimumInstances The minimum number of instances of this resource that must exist at any time. Must be less than or equal to @e maximumInstances.
* @param[in] maximumInstances The maximum number of instances of this resource that must exist at any time. Must be greater than zero.
* @param[in] operations The allowed LWM2M operations on the new resource.
*
* @return AwaError_Success on success.
* @return AwaError_DefinitionInvalid if @e resourceName is invalid, or @e objectID or @e resourceID is out of range, or
* @e minimumInstances or @e maximumInstances are invalid.
* @return AwaError_StaticClientInvalid if @e client is NULL.
*/
AwaError AwaStaticClient_DefineResource(AwaStaticClient * client, const char * resourceName,
AwaObjectID objectID, AwaResourceID resourceID, AwaResourceType resourceType,
uint16_t minimumInstances, uint16_t maximumInstances, AwaResourceOperations operations);

/**
* @brief Set a user-specified callback handler that will be called whenever a LWM2M operation on the resource is performed.
*
* @note This function overrides the effect of ::AwaStaticClient_SetResourceStorageWithPointer and ::AwaStaticClient_SetResourceStorageWithPointerArray.
*
* @param[in] client A pointer to a valid Awa Static Client.
* @param[in] objectID An ID that uniquely identifies the object which will contain the new resource.
* @param[in] resourceID An ID that uniquely identifies the new resource within the object.
* @param[in] handler A user-specified callback handler.
* @return AwaError_Success on success.
* @return AwaError_DefinitionInvalid if @e objectID or @e resourceID is invalid or out of range.
* @return AwaError_StaticClientInvalid if @e client is NULL.
*
*/
AwaError AwaStaticClient_SetResourceOperationHandler(AwaStaticClient * client, AwaObjectID objectID, AwaResourceID resourceID, AwaStaticClientHandler handler);

/**
* @brief Set a resource's storage with a pointer to the resource's data,
* leaving handling of the resource to the LWM2M Client. The resource's value
* within any of its instances may be directly modified at any time, however
* ::AwaStaticClient_ResourceChanged should be called to allow notifications to be sent to
* any observing LWM2M servers.
* @note This function overrides the effect of ::AwaStaticClient_SetResourceOperationHandler and ::AwaStaticClient_SetResourceStorageWithPointerArray.
*
* @param[in] client A pointer to a valid Awa Static Client.
* @param[in] objectID An ID that uniquely identifies the object which will contain the new resource.
* @param[in] resourceID An ID that uniquely identifies the new resource within the object.
* @param[in] dataPointer A pointer to the resource's data.
* @param[in] dataElementSize The size in bytes of the resource's data. Must be greater than or equal to 1.
* @param[in] dataStepSize The step size in bytes between the resource's data per object instance.
* @return AwaError_Success on success.
* @return AwaError_DefinitionInvalid if @e objectID or @e resourceID is invalid is out of range, or
* @e dataPointers is NULL, or @e dataElementSize is less than 1.
* @return AwaError_StaticClientInvalid if the client is NULL.
*/
AwaError AwaStaticClient_SetResourceStorageWithPointer(AwaStaticClient * client, AwaObjectID objectID, AwaResourceID resourceID, void * dataPointer, size_t dataElementSize, size_t dataStepSize);

/**
* @brief Set a resource's storage with an array of pointers to non-contiguous data,
* where each piece of data stores the resource for a single instance of its object.
* Handling of the resource is left to the LWM2M Client. The resource's value
* within any of its instances may be directly modified at any time, however
* ::AwaStaticClient_ResourceChanged should be called to allow notifications to be sent to any observing
* LWM2M servers.
*
* @note This function overrides the effect of ::AwaStaticClient_SetResourceOperationHandler and ::AwaStaticClient_SetResourceStorageWithPointer.
*
* @param[in] client A pointer to a valid Awa Static Client.
* @param[in] objectID An ID that uniquely identifies the object which will contain the new resource.
* @param[in] resourceID An ID that uniquely identifies the new resource within the object.
* @param[in] dataPointers An array of pointers, each containing the location of the resource's data for a single object instance.
* @param[in] dataElementSize The size in bytes of the resource's data. Must be greater than or equal to 1.
* @return AwaError_Success on success.
* @return AwaError_DefinitionInvalid if @e objectID or @e resourceID is invalid or out of range, or
* @e dataPointers is NULL, or @e dataElementSize is less than 1.
* @return AwaError_StaticClientInvalid if the client is NULL.
*/
AwaError AwaStaticClient_SetResourceStorageWithPointerArray(AwaStaticClient * client, AwaObjectID objectID, AwaResourceID resourceID, void * dataPointers[], size_t dataElementSize);

/**
* @deprecated Use ::AwaStaticClient_DefineResource followed by ::AwaStaticClient_SetResourceOperationHandler instead.
*
* @brief Define a new resource of an existing object with a user-specified callback handler
* that will be called whenever a LWM2M operation on the resource is performed.
*
* In order for an LWM2M server to perform operations on the defined resource,
* @note In order for an LWM2M server to perform operations on the defined resource,
* a matching object with resources must be defined on the LWM2M server.
*
* @param[in] client A pointer to a valid Awa Static Client.
Expand All @@ -465,13 +553,15 @@ AwaError AwaStaticClient_DefineResourceWithHandler(AwaStaticClient * client, con
AwaStaticClientHandler handler);

/**
* @deprecated Use ::AwaStaticClient_DefineResource followed by ::AwaStaticClient_SetResourceStorageWithPointer instead.
*
* @brief Define a new resource of an existing object with a pointer to the resource's data,
* leaving handling of the resource to the LWM2M Client. The resource's value
* within any of its instances may be directly modified at any time, however
* ::AwaStaticClient_ResourceChanged should be called to allow notifications to be sent to
* any observing LWM2M servers.
*
* In order for an LWM2M server to perform operations on the defined
* @note In order for an LWM2M server to perform operations on the defined
* resource, a matching object with resources must be defined on the LWM2M server.
*
* @param[in] client A pointer to a valid Awa Static Client.
Expand All @@ -496,14 +586,16 @@ AwaError AwaStaticClient_DefineResourceWithPointer(AwaStaticClient * client, con
void * dataPointer, size_t dataElementSize, size_t dataStepSize);

/**
* @deprecated Use ::AwaStaticClient_DefineResource followed by ::AwaStaticClient_SetResourceStorageWithPointerArray instead.
*
* @brief Define a new resource of an existing object with an array of pointers to non-contiguous data,
* where each piece of data stores the resource for a single instance of its object.
* Handling of the resource is left to the LWM2M Client. The resource's value
* within any of its instances may be directly modified at any time, however
* ::AwaStaticClient_ResourceChanged should be called to allow notifications to be sent to any observing
* LWM2M servers.
*
* In order for an LWM2M server to perform operations on the defined resource,
* @note In order for an LWM2M server to perform operations on the defined resource,
* a matching object with resources must be defined on the LWM2M server.
*
* @param[in] client A pointer to a valid Awa Static Client.
Expand Down
3 changes: 3 additions & 0 deletions api/tests-static/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ set (test_static_api_runner_SOURCES
support/static_api_support.cc
test_static_api.cc
test_static_api_with_pointer.cc
test_static_api_with_pointer_deprecated.cc
test_static_api_handlers.cc
test_static_api_handlers_deprecated.cc
test_static_api_get_resource_instance_pointer.cc
test_static_api_get_resource_instance_pointer_deprecated.cc
)

set (test_static_api_runner_INCLUDE_DIRS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const AwaResourceID TEST_RESOURCE_OPAQUEARRAY = 5;
const AwaResourceID TEST_RESOURCE_TIMEARRAY = 6;
const AwaResourceID TEST_RESOURCE_OBJECTLINKARRAY = 7;

}
} // namespace TestStaticClientGetResourceInstancePointerDetail

struct TestGetResourceInstancePointerData
{
Expand Down Expand Up @@ -118,7 +118,8 @@ class TestStaticClientGetResourceInstancePointer : public TestStaticClientWithSe
StaticClientAllocedValue_ = malloc(data.ValueSize);
EXPECT_TRUE(StaticClientAllocedValue_ != NULL);
memset(StaticClientAllocedValue_, 0, data.ValueSize);
EXPECT_EQ(AwaError_Success, AwaStaticClient_DefineResourceWithPointer(client_, "Test Resource", data.ObjectID, data.ResourceID, data.Type, 1, 1, AwaResourceOperations_ReadWrite, StaticClientAllocedValue_, data.ValueSize, 0));
EXPECT_EQ(AwaError_Success, AwaStaticClient_DefineResource(client_, "Test Resource", data.ObjectID, data.ResourceID, data.Type, 1, 1, AwaResourceOperations_ReadWrite));
EXPECT_EQ(AwaError_Success, AwaStaticClient_SetResourceStorageWithPointer(client_, data.ObjectID, data.ResourceID, StaticClientAllocedValue_, data.ValueSize, 0));
}
break;
}
Expand Down
Loading

0 comments on commit beb56e8

Please sign in to comment.