Change fn manager
authorJihoon Jung <jh8801.jung@samsung.com>
Wed, 13 Dec 2017 02:44:51 +0000 (11:44 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Mon, 2 Jul 2018 10:38:37 +0000 (19:38 +0900)
Signed-off-by: Jihoon Jung <jh8801.jung@samsung.com>
src/fn-manager/fn_iotivity.c
src/include/fn_enum.h
src/include/fn_iotivity.h

index 293cc0bc3bf59c2e5604c1734f0669414476f2ff..372465a4aae932149f7cb04053e4e47aa24cf5bd 100755 (executable)
@@ -8,3 +8,108 @@ int fn_iotivity_initialize()
        return FN_ERROR_NONE;
 }
 
+char * __get_type_from_resource_type(fn_resource_type_e resource_type)
+{
+       return NULL;
+}
+char * __get_uri_from_resource_type(fn_resource_type_e resource_type, int index)
+{
+       return NULL;
+}
+
+uint8_t __get_resource_properties_from_resource_type(fn_resource_type_e resource_type)
+{
+       return 0;
+}
+
+OCEntityHandlerResult OCEntityHandlerCb (OCEntityHandlerFlag flag,
+       OCEntityHandlerRequest *entityHandlerRequest, void* callbackParam)
+{
+       LOG_DEBUG("Inside entity handler - flags: 0x%x", flag);
+       OCEntityHandlerResult ehResult = OC_EH_ERROR;
+       OCEntityHandlerResponse response;
+       memset(&response, 0, sizeof(response));
+
+       // Validate pointer
+       if (!entityHandlerRequest) {
+               LOG_DEBUG("Invalid request pointer");
+               return OC_EH_ERROR;
+       }
+
+       OCRepPayload* payload = NULL;
+
+       if (flag & OC_REQUEST_FLAG) {
+               LOG_DEBUG("Flag includes OC_REQUEST_FLAG");
+               if (entityHandlerRequest) {
+                       if (OC_REST_GET == entityHandlerRequest->method) {
+                               LOG_DEBUG("Received OC_REST_GET from client");
+                               //ehResult = ProcessGetRequest (entityHandlerRequest, &payload);
+                       } else if (OC_REST_PUT == entityHandlerRequest->method) {
+                               LOG_DEBUG("Received OC_REST_PUT from client");
+                               //ehResult = ProcessPutRequest (entityHandlerRequest, &payload);
+                       } else if (OC_REST_POST == entityHandlerRequest->method) {
+                               LOG_DEBUG("Received OC_REST_POST from client");
+                               //ehResult = ProcessPostRequest (entityHandlerRequest, &response, &payload);
+                       } else {
+                               LOG_DEBUG("Received unsupported method %d from client %d", entityHandlerRequest->method);
+                               ehResult = OC_EH_ERROR;
+                       }
+
+                       if (ehResult == OC_EH_OK && ehResult != OC_EH_FORBIDDEN) {
+                               // Format the response.  Note this requires some info about the request
+                               response.requestHandle = entityHandlerRequest->requestHandle;
+                               response.resourceHandle = entityHandlerRequest->resource;
+                               response.ehResult = ehResult;
+                               response.payload = (OCPayload*)(payload);
+                               response.numSendVendorSpecificHeaderOptions = 0;
+                               memset(response.sendVendorSpecificHeaderOptions, 0,
+                                       sizeof(response.sendVendorSpecificHeaderOptions));
+                               memset(response.resourceUri, 0, sizeof(response.resourceUri));
+                               // Indicate that response is NOT in a persistent buffer
+                               response.persistentBufferFlag = 0;
+
+                               // Send the response
+                               if (OCDoResponse(&response) != OC_STACK_OK) {
+                                       LOG_DEBUG("Error sending response");
+                                       ehResult = OC_EH_ERROR;
+                               }
+                       }
+               }
+       }
+
+       OCPayloadDestroy(response.payload);
+       return ehResult;
+}
+
+int fn_iotivity_add_resource(fn_resource_type_e resource_type, int index)
+{
+       OCResourceHandle handle;
+       fn_context *fn_ctx = fn_context_get_context();
+       void *callbackParam = NULL;
+       //get resource list of resource type
+       //GList *list = fn_ctx->resource_list[resource_type];
+
+       //type generation and uri generation and resourceProperties generation
+       char *type = __get_type_from_resource_type(resource_type);
+       char *uri = __get_uri_from_resource_type(resource_type, index);
+       uint8_t resource_properties = __get_resource_properties_from_resource_type(resource_type);
+
+       //create callback parameter - insert resource type and index and...?
+       callbackParam = NULL;
+
+       OCStackResult result = OCCreateResource(&handle,
+                         type,
+                         OC_RSRVD_INTERFACE_DEFAULT,
+                         uri,
+                         OCEntityHandlerCb,
+                         callbackParam,
+                         resource_properties);
+
+       return 0;
+}
+
+int fn_iotivity_delete_resource(fn_resource_type_e resource_type, int index)
+{
+       //delete resource from resource list using resource_type and index
+}
+
index 14e4413827ac7411a2de7d016d2c064869570331..b4fa00bc05b477cc538881964cb02361dc75aefe 100755 (executable)
@@ -25,4 +25,9 @@ typedef enum {
        FN_ROLE_CLIENT
 } fn_role_e;
 
+/* resource type enum */
+typedef enum {
+       FN_RESOURCE_TYPE_GROUP,
+} fn_resource_type_e;
+
 #endif
index bcbfb81fa1846f07c64ae54f3dde7f88e72a382c..94daf6a973681b2c1c88b67aacae6212b910babd 100755 (executable)
@@ -8,5 +8,7 @@
 #include <fn_context.h>
 
 int fn_iotivity_initialize();
+int fn_iotivity_add_resource(fn_resource_type_e resource_type, int index);
+int fn_iotivity_delete_resource(fn_resource_type_e resource_type, int index);
 
 #endif