Skip to content

Commit

Permalink
Swapped order of ObjectID (and ResourceID) with Name when defining ob…
Browse files Browse the repository at this point in the history
…jects and resources in the Static API. This is now consistent with the Gateway API, where Name follows the IDs.

Add CMakeLists.txt for examples/tutorials, to ensure they are built alongside the API.

Signed-off-by: David Antliff <[email protected]>
  • Loading branch information
David Antliff committed May 2, 2016
1 parent beb56e8 commit 40b5d4c
Show file tree
Hide file tree
Showing 12 changed files with 110 additions and 91 deletions.
22 changes: 2 additions & 20 deletions api/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,15 @@ set (Examples
server-execute-example
server-execute-arguments-example


# TODO: set-array example uses single values and not an array. Add an example for that too and
# rename this set-array to set-array-individual-instances-example

# TODO: get-response-iterator-example
# TODO: subscribe iterate through changeset example
)

#if (ENABLE_GCOV)
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0 --coverage")
# set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
#endif ()

foreach (example ${Examples})

# disable -Wall warnings for _cmdline.c files
set_source_files_properties(${example}_cmdline.c PROPERTIES COMPILE_FLAGS -Wno-all)

add_executable (${example} ${example}.c)
add_executable (${example} ${example}.c)
target_include_directories (${example} PRIVATE ${API_INCLUDE_DIR})
target_link_libraries (${example} Awa_static)
target_link_libraries (${example} libxml_static)
Expand All @@ -51,12 +41,4 @@ foreach (example ${Examples})
endif ()
endforeach (example ${Examples})

#TODO should we install the examples?
#install(TARGETS ${Examples}
# RUNTIME DESTINATION /bin
#)

#TODO
#if (ENABLE_TEST)
# add_subdirectory (tests/gtest)
#endif ()
add_subdirectory (tutorials)
21 changes: 21 additions & 0 deletions api/examples/tutorials/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
set (Tutorials
client-tutorial1
client-tutorial2
server-tutorial
static-client-tutorial1
static-client-tutorial2
static-client-tutorial3
)

foreach (tutorial ${Tutorials})

add_executable (${tutorial} ${tutorial}.c)
target_include_directories (${tutorial} PRIVATE ${API_INCLUDE_DIR})
target_link_libraries (${tutorial} Awa_static)
target_link_libraries (${tutorial} awa_static)
target_link_libraries (${tutorial} libxml_static)

if (ENABLE_GCOV)
target_link_libraries (${tutorial} gcov)
endif ()
endforeach (tutorial ${Tutorials})
10 changes: 5 additions & 5 deletions api/examples/tutorials/static-client-tutorial2.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ static HeaterObject heater[HEATER_INSTANCES];

static void DefineHeaterObject(AwaStaticClient * awaClient)
{
AwaStaticClient_DefineObject(awaClient, "Heater", 1000, 0, HEATER_INSTANCES);
AwaStaticClient_DefineResourceWithPointer(awaClient, "Manufacturer", 1000, 101, AwaResourceType_String, 0, 1, AwaResourceOperations_ReadOnly,
&heater[0].Manufacturer, sizeof(heater[0].Manufacturer), sizeof(heater[0]));
AwaStaticClient_DefineResourceWithPointer(awaClient, "Temperature", 1000, 104, AwaResourceType_Float, 0, 1, AwaResourceOperations_ReadOnly,
&heater[0].Temperature, sizeof(heater[0].Temperature), sizeof(heater[0]));
AwaStaticClient_DefineObject(awaClient, 1000, "Heater", 0, HEATER_INSTANCES);
AwaStaticClient_DefineResource(awaClient, 1000, 101, "Manufacturer", AwaResourceType_String, 0, 1, AwaResourceOperations_ReadOnly);
AwaStaticClient_SetResourceStorageWithPointer(awaClient, 1000, 101, &heater[0].Manufacturer, sizeof(heater[0].Manufacturer), sizeof(heater[0]));
AwaStaticClient_DefineResource(awaClient, 1000, 104, "Temperature", AwaResourceType_Float, 0, 1, AwaResourceOperations_ReadOnly);
AwaStaticClient_SetResourceStorageWithPointer(awaClient, 1000, 104, &heater[0].Temperature, sizeof(heater[0].Temperature), sizeof(heater[0]));
}

static void SetInitialValues(AwaStaticClient * awaClient)
Expand Down
14 changes: 9 additions & 5 deletions api/examples/tutorials/static-client-tutorial3.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ typedef struct

static HeaterObject heater[HEATER_INSTANCES];


AwaResult handler(AwaStaticClient * client, AwaOperation operation, AwaObjectID objectID,
AwaObjectInstanceID objectInstanceID, AwaResourceID resourceID, AwaResourceInstanceID resourceInstanceID,
void ** dataPointer, uint16_t * dataSize, bool * changed)
AwaObjectInstanceID objectInstanceID, AwaResourceID resourceID, AwaResourceInstanceID resourceInstanceID,
void ** dataPointer, size_t * dataSize, bool * changed)
{
AwaResult result = AwaResult_InternalError;

Expand Down Expand Up @@ -129,9 +130,12 @@ AwaResult handler(AwaStaticClient * client, AwaOperation operation, AwaObjectID

static void DefineHeaterObject(AwaStaticClient * awaClient)
{
AwaStaticClient_DefineObjectWithHandler(awaClient, "Heater", 1000, 0, HEATER_INSTANCES, handler);
AwaStaticClient_DefineResourceWithHandler(awaClient, "Manufacturer", 1000, 101, AwaResourceType_String, 0, 1, AwaResourceOperations_ReadWrite, handler);
AwaStaticClient_DefineResourceWithHandler(awaClient, "Temperature", 1000, 104, AwaResourceType_Float, 0, 1, AwaResourceOperations_ReadWrite, handler);
AwaStaticClient_DefineObject(awaClient, 1000, "Heater", 0, HEATER_INSTANCES);
AwaStaticClient_SetObjectOperationHandler(awaClient, 1000, handler);
AwaStaticClient_DefineResource(awaClient, 1000, 101, "Manufacturer", AwaResourceType_String, 0, 1, AwaResourceOperations_ReadWrite);
AwaStaticClient_SetResourceOperationHandler(awaClient, 1000, 101, handler);
AwaStaticClient_DefineResource(awaClient, 1000, 104, "Temperature", AwaResourceType_Float, 0, 1, AwaResourceOperations_ReadWrite);
AwaStaticClient_SetResourceOperationHandler(awaClient, 1000, 104, handler);
}

static void CreateHeaterObject(AwaStaticClient * awaClient)
Expand Down
6 changes: 3 additions & 3 deletions api/include/awa/static.h
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ AwaError AwaStaticClient_DefineObjectWithHandler(AwaStaticClient * client, const
* @e minimumInstances or @e maximumInstances are invalid.
* @return AwaError_StaticClientInvalid if @e client is NULL.
*/
AwaError AwaStaticClient_DefineObject(AwaStaticClient * client, const char * objectName, AwaObjectID objectID,
AwaError AwaStaticClient_DefineObject(AwaStaticClient * client, AwaObjectID objectID, const char * objectName,
uint16_t minimumInstances, uint16_t maximumInstances);

/**
Expand Down Expand Up @@ -459,8 +459,8 @@ AwaError AwaStaticClient_SetObjectOperationHandler(AwaStaticClient * client, Awa
* @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,
AwaError AwaStaticClient_DefineResource(AwaStaticClient * client, AwaObjectID objectID, AwaResourceID resourceID,
const char * resourceName, AwaResourceType resourceType,
uint16_t minimumInstances, uint16_t maximumInstances, AwaResourceOperations operations);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@ class TestStaticClientGetResourceInstancePointer : public TestStaticClientWithSe
TestStaticClientWithServer::SetUp();
TestGetResourceInstancePointerData data = GetParam();

EXPECT_EQ(AwaError_Success,AwaStaticClient_DefineObject(client_, "TestObject", data.ObjectID, 0, 1));
EXPECT_EQ(AwaError_Success,AwaStaticClient_DefineObject(client_, data.ObjectID, "TestObject", 0, 1));

switch(data.Type)
{
case AwaResourceType_Opaque:
{
//EXPECT_EQ(AwaError_Success, AwaStaticClient_DefineResourceWithPointer(client_, "Test Resource", data.ObjectID, data.ResourceID, data.Type, 1, 1, AwaResourceOperations_ReadWrite, &opaque_, sizeof(opaque_), 0));
//EXPECT_EQ(AwaError_Success, AwaStaticClient_DefineResourceWithPointer(client_, data.ObjectID, data.ResourceID, "Test Resource", data.Type, 1, 1, AwaResourceOperations_ReadWrite, &opaque_, sizeof(opaque_), 0));
ASSERT_TRUE(false);
break;
}
Expand All @@ -118,7 +118,7 @@ class TestStaticClientGetResourceInstancePointer : public TestStaticClientWithSe
StaticClientAllocedValue_ = malloc(data.ValueSize);
EXPECT_TRUE(StaticClientAllocedValue_ != NULL);
memset(StaticClientAllocedValue_, 0, data.ValueSize);
EXPECT_EQ(AwaError_Success, AwaStaticClient_DefineResource(client_, "Test Resource", data.ObjectID, data.ResourceID, data.Type, 1, 1, AwaResourceOperations_ReadWrite));
EXPECT_EQ(AwaError_Success, AwaStaticClient_DefineResource(client_, data.ObjectID, data.ResourceID, "Test Resource", data.Type, 1, 1, AwaResourceOperations_ReadWrite));
EXPECT_EQ(AwaError_Success, AwaStaticClient_SetResourceStorageWithPointer(client_, data.ObjectID, data.ResourceID, StaticClientAllocedValue_, data.ValueSize, 0));
}
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
#include "awa/server.h"
#include "support/static_api_support.h"

// reverse the name and objectID to match updated API:
#define AwaStaticClient_DefineObject(A, B, C, D, E) AwaStaticClient_DefineObject(A, C, B, D, E)
#define AwaStaticClient_DefineResource(A, B, C, D, E, F, G, H) AwaStaticClient_DefineResource(A, C, D, B, E, F, G, H)

namespace Awa {

namespace TestStaticClientGetResourceInstancePointerDetailDeprecated
Expand Down
32 changes: 16 additions & 16 deletions api/tests-static/test_static_api_handlers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ TEST_F(TestStaticClientHandlerWithServer, AwaStaticClient_Create_and_Write_Opera

callback1 cbHandler(client_, 20);
EXPECT_EQ(AwaError_Success, AwaStaticClient_SetApplicationContext(client_, &cbHandler));
EXPECT_EQ(AwaError_Success, AwaStaticClient_DefineObject(client_, "TestObject", 9999, 0, 1));
EXPECT_EQ(AwaError_Success, AwaStaticClient_DefineObject(client_, 9999, "TestObject", 0, 1));
EXPECT_EQ(AwaError_Success, AwaStaticClient_SetObjectOperationHandler(client_, 9999, handler));
EXPECT_EQ(AwaError_Success, AwaStaticClient_DefineResource(client_, "TestResource", 9999, 1, AwaResourceType_Integer, 1, 1, AwaResourceOperations_ReadWrite));
EXPECT_EQ(AwaError_Success, AwaStaticClient_DefineResource(client_, 9999, 1, "TestResource", AwaResourceType_Integer, 1, 1, AwaResourceOperations_ReadWrite));
EXPECT_EQ(AwaError_Success, AwaStaticClient_SetResourceOperationHandler(client_, 9999, 1, handler));

AwaServerListClientsOperation * operation = AwaServerListClientsOperation_New(session_);
Expand Down Expand Up @@ -179,9 +179,9 @@ TEST_F(TestStaticClientHandlerWithServer, AwaStaticClient_Create_and_Read_Operat
callback1 cbHandler(client_, 20);

EXPECT_EQ(AwaError_Success, AwaStaticClient_SetApplicationContext(client_, &cbHandler));
EXPECT_EQ(AwaError_Success, AwaStaticClient_DefineObject(client_, "TestObject", 9999, 0, 1));
EXPECT_EQ(AwaError_Success, AwaStaticClient_DefineObject(client_, 9999, "TestObject", 0, 1));
EXPECT_EQ(AwaError_Success, AwaStaticClient_SetObjectOperationHandler(client_, 9999, handler));
EXPECT_EQ(AwaError_Success, AwaStaticClient_DefineResource(client_, "TestResource", 9999, 1, AwaResourceType_Integer, 1, 1, AwaResourceOperations_ReadWrite));
EXPECT_EQ(AwaError_Success, AwaStaticClient_DefineResource(client_, 9999, 1, "TestResource", AwaResourceType_Integer, 1, 1, AwaResourceOperations_ReadWrite));
EXPECT_EQ(AwaError_Success, AwaStaticClient_SetResourceOperationHandler(client_, 9999, 1, handler));

EXPECT_EQ(AwaError_Success, AwaStaticClient_CreateObjectInstance(client_, 9999, 0));
Expand Down Expand Up @@ -278,9 +278,9 @@ TEST_F(TestStaticClientHandlerWithServer, AwaStaticClient_Create_and_Delete_Oper
callback1 cbHandler(client_, 20);
EXPECT_EQ(AwaError_Success, AwaStaticClient_SetApplicationContext(client_, &cbHandler));

EXPECT_EQ(AwaError_Success, AwaStaticClient_DefineObject(client_, "TestObject", 9999, 0, 1));
EXPECT_EQ(AwaError_Success, AwaStaticClient_DefineObject(client_, 9999, "TestObject", 0, 1));
EXPECT_EQ(AwaError_Success, AwaStaticClient_SetObjectOperationHandler(client_, 9999, handler));
EXPECT_EQ(AwaError_Success, AwaStaticClient_DefineResource(client_, "TestResource", 9999, 1, AwaResourceType_Integer, 0, 1, AwaResourceOperations_ReadWrite));
EXPECT_EQ(AwaError_Success, AwaStaticClient_DefineResource(client_, 9999, 1, "TestResource", AwaResourceType_Integer, 0, 1, AwaResourceOperations_ReadWrite));
EXPECT_EQ(AwaError_Success, AwaStaticClient_SetResourceOperationHandler(client_, 9999, 1, handler));

EXPECT_EQ(AwaError_Success, AwaStaticClient_CreateObjectInstance(client_, 9999, 0));
Expand Down Expand Up @@ -373,9 +373,9 @@ TEST_F(TestStaticClientHandlerWithServer, AwaStaticClient_Create_and_Execute_Ope
callback1 cbHandler(client_, 20);
EXPECT_EQ(AwaError_Success, AwaStaticClient_SetApplicationContext(client_, &cbHandler));

EXPECT_EQ(AwaError_Success, AwaStaticClient_DefineObject(client_, "TestObject", 9999, 0, 1));
EXPECT_EQ(AwaError_Success, AwaStaticClient_DefineObject(client_, 9999, "TestObject", 0, 1));
EXPECT_EQ(AwaError_Success, AwaStaticClient_SetObjectOperationHandler(client_, 9999, handler));
EXPECT_EQ(AwaError_Success, AwaStaticClient_DefineResource(client_, "TestResource", 9999, 1, AwaResourceType_None, 1, 1, AwaResourceOperations_Execute));
EXPECT_EQ(AwaError_Success, AwaStaticClient_DefineResource(client_, 9999, 1, "TestResource", AwaResourceType_None, 1, 1, AwaResourceOperations_Execute));
EXPECT_EQ(AwaError_Success, AwaStaticClient_SetResourceOperationHandler(client_, 9999, 1, handler));

EXPECT_EQ(AwaError_Success, AwaStaticClient_CreateObjectInstance(client_, 9999, 0));
Expand Down Expand Up @@ -581,16 +581,16 @@ class TestStaticClienthandlerWriteReadValue : public TestStaticClientWithServer,

EXPECT_EQ(AwaError_Success, AwaStaticClient_SetApplicationContext(client_, cbHandler));

EXPECT_EQ(AwaError_Success, AwaStaticClient_DefineObject(client_, "Test Object Single", writeDetail::TEST_OBJECT_NON_ARRAY_TYPES, 0, 1));
EXPECT_EQ(AwaError_Success, AwaStaticClient_DefineObject(client_, writeDetail::TEST_OBJECT_NON_ARRAY_TYPES, "Test Object Single", 0, 1));
EXPECT_EQ(AwaError_Success, AwaStaticClient_SetObjectOperationHandler(client_, writeDetail::TEST_OBJECT_NON_ARRAY_TYPES, handler));

EXPECT_EQ(AwaError_Success, AwaStaticClient_DefineResource(client_, "Test String Resource", writeDetail::TEST_OBJECT_NON_ARRAY_TYPES, writeDetail::TEST_RESOURCE_STRING, AwaResourceType_String, 0, 1, AwaResourceOperations_ReadWrite));
EXPECT_EQ(AwaError_Success, AwaStaticClient_DefineResource(client_, "Test Integer Resource", writeDetail::TEST_OBJECT_NON_ARRAY_TYPES, writeDetail::TEST_RESOURCE_INTEGER, AwaResourceType_Integer, 0, 1, AwaResourceOperations_ReadWrite));
EXPECT_EQ(AwaError_Success, AwaStaticClient_DefineResource(client_, "Test Float Resource", writeDetail::TEST_OBJECT_NON_ARRAY_TYPES, writeDetail::TEST_RESOURCE_FLOAT, AwaResourceType_Float, 0, 1, AwaResourceOperations_ReadWrite));
EXPECT_EQ(AwaError_Success, AwaStaticClient_DefineResource(client_, "Test Boolean Resource", writeDetail::TEST_OBJECT_NON_ARRAY_TYPES, writeDetail::TEST_RESOURCE_BOOLEAN, AwaResourceType_Boolean, 0, 1, AwaResourceOperations_ReadWrite));
EXPECT_EQ(AwaError_Success, AwaStaticClient_DefineResource(client_, "Test Opaque Resource", writeDetail::TEST_OBJECT_NON_ARRAY_TYPES, writeDetail::TEST_RESOURCE_OPAQUE, AwaResourceType_Opaque, 0, 1, AwaResourceOperations_ReadWrite));
EXPECT_EQ(AwaError_Success, AwaStaticClient_DefineResource(client_, "Test Time Resource", writeDetail::TEST_OBJECT_NON_ARRAY_TYPES, writeDetail::TEST_RESOURCE_TIME, AwaResourceType_Time, 0, 1, AwaResourceOperations_ReadWrite));
EXPECT_EQ(AwaError_Success, AwaStaticClient_DefineResource(client_, "Test Object Link Resource", writeDetail::TEST_OBJECT_NON_ARRAY_TYPES, writeDetail::TEST_RESOURCE_OBJECTLINK, AwaResourceType_ObjectLink, 0, 1, AwaResourceOperations_ReadWrite));
EXPECT_EQ(AwaError_Success, AwaStaticClient_DefineResource(client_, writeDetail::TEST_OBJECT_NON_ARRAY_TYPES, writeDetail::TEST_RESOURCE_STRING, "Test String Resource", AwaResourceType_String, 0, 1, AwaResourceOperations_ReadWrite));
EXPECT_EQ(AwaError_Success, AwaStaticClient_DefineResource(client_, writeDetail::TEST_OBJECT_NON_ARRAY_TYPES, writeDetail::TEST_RESOURCE_INTEGER, "Test Integer Resource", AwaResourceType_Integer, 0, 1, AwaResourceOperations_ReadWrite));
EXPECT_EQ(AwaError_Success, AwaStaticClient_DefineResource(client_, writeDetail::TEST_OBJECT_NON_ARRAY_TYPES, writeDetail::TEST_RESOURCE_FLOAT, "Test Float Resource", AwaResourceType_Float, 0, 1, AwaResourceOperations_ReadWrite));
EXPECT_EQ(AwaError_Success, AwaStaticClient_DefineResource(client_, writeDetail::TEST_OBJECT_NON_ARRAY_TYPES, writeDetail::TEST_RESOURCE_BOOLEAN, "Test Boolean Resource", AwaResourceType_Boolean, 0, 1, AwaResourceOperations_ReadWrite));
EXPECT_EQ(AwaError_Success, AwaStaticClient_DefineResource(client_, writeDetail::TEST_OBJECT_NON_ARRAY_TYPES, writeDetail::TEST_RESOURCE_OPAQUE, "Test Opaque Resource", AwaResourceType_Opaque, 0, 1, AwaResourceOperations_ReadWrite));
EXPECT_EQ(AwaError_Success, AwaStaticClient_DefineResource(client_, writeDetail::TEST_OBJECT_NON_ARRAY_TYPES, writeDetail::TEST_RESOURCE_TIME, "Test Time Resource", AwaResourceType_Time, 0, 1, AwaResourceOperations_ReadWrite));
EXPECT_EQ(AwaError_Success, AwaStaticClient_DefineResource(client_, writeDetail::TEST_OBJECT_NON_ARRAY_TYPES, writeDetail::TEST_RESOURCE_OBJECTLINK, "Test Object Link Resource", AwaResourceType_ObjectLink, 0, 1, AwaResourceOperations_ReadWrite));

EXPECT_EQ(AwaError_Success, AwaStaticClient_SetResourceOperationHandler(client_, writeDetail::TEST_OBJECT_NON_ARRAY_TYPES, writeDetail::TEST_RESOURCE_STRING, handler));
EXPECT_EQ(AwaError_Success, AwaStaticClient_SetResourceOperationHandler(client_, writeDetail::TEST_OBJECT_NON_ARRAY_TYPES, writeDetail::TEST_RESOURCE_INTEGER, handler));
Expand Down
4 changes: 4 additions & 0 deletions api/tests-static/test_static_api_handlers_deprecated.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
#include "awa/server.h"
#include "support/static_api_support.h"

// reverse the name and objectID to match updated API:
#define AwaStaticClient_DefineObject(A, B, C, D, E) AwaStaticClient_DefineObject(A, C, B, D, E)
#define AwaStaticClient_DefineResource(A, B, C, D, E, F, G, H) AwaStaticClient_DefineResource(A, C, D, B, E, F, G, H)

namespace Awa {

class TestStaticClientHandlerWithServerDeprecated : public TestStaticClientWithServer {};
Expand Down
Loading

0 comments on commit 40b5d4c

Please sign in to comment.