Add fn manager implementation
authorJihoon Jung <jh8801.jung@samsung.com>
Tue, 12 Dec 2017 11:45:35 +0000 (20:45 +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>
16 files changed:
src/fn-manager/fn-manager.c [deleted file]
src/fn-manager/fn_context.c [new file with mode: 0755]
src/fn-manager/fn_group.c [new file with mode: 0755]
src/fn-manager/fn_iotivity.c [new file with mode: 0755]
src/fn-manager/fn_log.c [new file with mode: 0755]
src/fn-manager/fn_manager.c [new file with mode: 0755]
src/fn-manager/fn_rx.c [new file with mode: 0755]
src/fn-manager/fn_tx.c [new file with mode: 0755]
src/include/fn_context.h [new file with mode: 0755]
src/include/fn_enum.h [new file with mode: 0755]
src/include/fn_group.h [new file with mode: 0755]
src/include/fn_iotivity.h [new file with mode: 0755]
src/include/fn_log.h [new file with mode: 0755]
src/include/fn_manager.h [new file with mode: 0755]
src/include/fn_rx.h [new file with mode: 0755]
src/include/fn_tx.h [new file with mode: 0755]

diff --git a/src/fn-manager/fn-manager.c b/src/fn-manager/fn-manager.c
deleted file mode 100644 (file)
index f2559f0..0000000
+++ /dev/null
@@ -1,529 +0,0 @@
-/******************************************************************
-*
-* Copyright 2015 Samsung Electronics All Rights Reserved.
-*
-*
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*      http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*
-******************************************************************/
-///////////////////////////////////////////////////////////////////////
-//NOTE :  This sample server is generated based on ocserverbasicops.cpp
-///////////////////////////////////////////////////////////////////////
-#include "iotivity_config.h"
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-#ifdef HAVE_PTHREAD_H
-#include <pthread.h>
-#endif
-#include <signal.h>
-#include "ocstack.h"
-#include "ocpayload.h"
-#include "pinoxmcommon.h"
-#include "srmutility.h"
-
-#include <tzplatform_config.h>
-
-#define MAX_FILE_PATH_LEN 1024
-
-#ifdef HAVE_WINDOWS_H
-#include <windows.h>
-/** @todo stop-gap for naming issue. Windows.h does not like us to use ERROR */
-#ifdef ERROR
-#undef ERROR
-#endif //ERROR
-#endif //HAVE_WINDOWS_H
-#include "platform_features.h"
-#include "logger.h"
-
-
-#define TAG "SAMPLE_JUSTWORKS"
-
-int gQuitFlag = 0;
-
-/* Structure to represent a LED resource */
-typedef struct LEDRESOURCE{
-    OCResourceHandle handle;
-    bool state;
-    int power;
-} LEDResource;
-
-static LEDResource LED;
-// This variable determines instance number of the LED resource.
-// Used by POST method to create a new instance of LED resource.
-static int gCurrLedInstance = 0;
-#define SAMPLE_MAX_NUM_POST_INSTANCE  2
-static LEDResource gLedInstance[SAMPLE_MAX_NUM_POST_INSTANCE];
-
-char *gResourceUri= (char *)"/a/led";
-
-//Secure Virtual Resource database for Iotivity Server
-//It contains Server's Identity and the PSK credentials
-//of other devices which the server trusts
-static char CRED_FILE[] = "oic_svr_db_server_justworks.dat";
-
-/* Function that creates a new LED resource by calling the
- * OCCreateResource() method.
- */
-int createLEDResource (char *uri, LEDResource *ledResource, bool resourceState, int resourcePower);
-
-/* This method converts the payload to JSON format */
-OCRepPayload* constructResponse (OCEntityHandlerRequest *ehRequest);
-
-/* Following methods process the PUT, GET, POST
- * requests
- */
-OCEntityHandlerResult ProcessGetRequest (OCEntityHandlerRequest *ehRequest,
-                                         OCRepPayload **payload);
-OCEntityHandlerResult ProcessPutRequest (OCEntityHandlerRequest *ehRequest,
-                                         OCRepPayload **payload);
-OCEntityHandlerResult ProcessPostRequest (OCEntityHandlerRequest *ehRequest,
-                                        OCEntityHandlerResponse *response,
-                                        OCRepPayload **payload);
-
-/* Entity Handler callback functions */
-OCEntityHandlerResult
-OCEntityHandlerCb (OCEntityHandlerFlag flag,
-        OCEntityHandlerRequest *entityHandlerRequest,
-        void* callbackParam);
-
-const char *getResult(OCStackResult result) {
-    switch (result) {
-    case OC_STACK_OK:
-        return "OC_STACK_OK";
-    case OC_STACK_RESOURCE_CREATED:
-        return "OC_STACK_RESOURCE_CREATED";
-    case OC_STACK_RESOURCE_DELETED:
-        return "OC_STACK_RESOURCE_DELETED";
-    case OC_STACK_INVALID_URI:
-        return "OC_STACK_INVALID_URI";
-    case OC_STACK_INVALID_QUERY:
-        return "OC_STACK_INVALID_QUERY";
-    case OC_STACK_INVALID_IP:
-        return "OC_STACK_INVALID_IP";
-    case OC_STACK_INVALID_PORT:
-        return "OC_STACK_INVALID_PORT";
-    case OC_STACK_INVALID_CALLBACK:
-        return "OC_STACK_INVALID_CALLBACK";
-    case OC_STACK_INVALID_METHOD:
-        return "OC_STACK_INVALID_METHOD";
-    case OC_STACK_NO_MEMORY:
-        return "OC_STACK_NO_MEMORY";
-    case OC_STACK_COMM_ERROR:
-        return "OC_STACK_COMM_ERROR";
-    case OC_STACK_INVALID_PARAM:
-        return "OC_STACK_INVALID_PARAM";
-    case OC_STACK_NOTIMPL:
-        return "OC_STACK_NOTIMPL";
-    case OC_STACK_NO_RESOURCE:
-        return "OC_STACK_NO_RESOURCE";
-    case OC_STACK_RESOURCE_ERROR:
-        return "OC_STACK_RESOURCE_ERROR";
-    case OC_STACK_SLOW_RESOURCE:
-        return "OC_STACK_SLOW_RESOURCE";
-    case OC_STACK_NO_OBSERVERS:
-        return "OC_STACK_NO_OBSERVERS";
-    #ifdef WITH_PRESENCE
-    case OC_STACK_PRESENCE_STOPPED:
-        return "OC_STACK_PRESENCE_STOPPED";
-    #endif
-    case OC_STACK_ERROR:
-        return "OC_STACK_ERROR";
-    default:
-        return "UNKNOWN";
-    }
-}
-
-OCRepPayload* getPayload(const char* uri, int64_t power, bool state)
-{
-    OCRepPayload* payload = OCRepPayloadCreate();
-    if(!payload)
-    {
-        OIC_LOG(ERROR, TAG, "Failed to allocate Payload");
-        return NULL;
-    }
-
-    OCRepPayloadSetUri(payload, uri);
-    OCRepPayloadSetPropBool(payload, "state", state);
-    OCRepPayloadSetPropInt(payload, "power", power);
-
-    return payload;
-}
-
-//This function takes the request as an input and returns the response
-OCRepPayload* constructResponse (OCEntityHandlerRequest *ehRequest)
-{
-    if(ehRequest->payload && ehRequest->payload->type != PAYLOAD_TYPE_REPRESENTATION)
-    {
-        OIC_LOG(ERROR, TAG, "Incoming payload not a representation");
-        return NULL;
-    }
-
-    OCRepPayload* input = (OCRepPayload*)(ehRequest->payload);
-
-    LEDResource *currLEDResource = &LED;
-
-    if (ehRequest->resource == gLedInstance[0].handle)
-    {
-        currLEDResource = &gLedInstance[0];
-        gResourceUri = (char *) "/a/led/0";
-    }
-    else if (ehRequest->resource == gLedInstance[1].handle)
-    {
-        currLEDResource = &gLedInstance[1];
-        gResourceUri = (char *) "/a/led/1";
-    }
-
-    if(OC_REST_PUT == ehRequest->method)
-    {
-        // Get pointer to query
-        int64_t pow;
-        if(OCRepPayloadGetPropInt(input, "power", &pow))
-        {
-            currLEDResource->power =pow;
-        }
-
-        bool state;
-        if(OCRepPayloadGetPropBool(input, "state", &state))
-        {
-            currLEDResource->state = state;
-        }
-    }
-
-    return getPayload(gResourceUri, currLEDResource->power, currLEDResource->state);
-}
-
-OCEntityHandlerResult ProcessGetRequest (OCEntityHandlerRequest *ehRequest,
-        OCRepPayload **payload)
-{
-    OCEntityHandlerResult ehResult;
-
-    OCRepPayload *getResp = constructResponse(ehRequest);
-
-    if(getResp)
-    {
-        *payload = getResp;
-        ehResult = OC_EH_OK;
-    }
-    else
-    {
-        ehResult = OC_EH_ERROR;
-    }
-
-    return ehResult;
-}
-
-OCEntityHandlerResult ProcessPutRequest (OCEntityHandlerRequest *ehRequest,
-        OCRepPayload **payload)
-{
-    OCEntityHandlerResult ehResult;
-
-    OCRepPayload *putResp = constructResponse(ehRequest);
-
-    if(putResp)
-    {
-        *payload = putResp;
-        ehResult = OC_EH_OK;
-    }
-    else
-    {
-        ehResult = OC_EH_ERROR;
-    }
-
-    return ehResult;
-}
-
-OCEntityHandlerResult ProcessPostRequest (OCEntityHandlerRequest *ehRequest,
-        OCEntityHandlerResponse *response, OCRepPayload **payload)
-{
-    OCRepPayload *respPLPost_led = NULL;
-    OCEntityHandlerResult ehResult = OC_EH_OK;
-
-    /*
-     * The entity handler determines how to process a POST request.
-     * Per the REST paradigm, POST can also be used to update representation of existing
-     * resource or create a new resource.
-     * In the sample below, if the POST is for /a/led then a new instance of the LED
-     * resource is created with default representation (if representation is included in
-     * POST payload it can be used as initial values) as long as the instance is
-     * lesser than max new instance count. Once max instance count is reached, POST on
-     * /a/led updated the representation of /a/led (just like PUT)
-     */
-
-    if (ehRequest->resource == LED.handle)
-    {
-        if (gCurrLedInstance < SAMPLE_MAX_NUM_POST_INSTANCE)
-        {
-            // Create new LED instance
-            char newLedUri[15] = "/a/led/";
-            int newLedUriLength = strlen(newLedUri);
-            snprintf (newLedUri + newLedUriLength, sizeof(newLedUri)-newLedUriLength, "%d", gCurrLedInstance);
-
-            respPLPost_led = OCRepPayloadCreate();
-            OCRepPayloadSetUri(respPLPost_led, gResourceUri);
-            OCRepPayloadSetPropString(respPLPost_led, "createduri", newLedUri);
-
-            if (0 == createLEDResource (newLedUri, &gLedInstance[gCurrLedInstance], false, 0))
-            {
-                OIC_LOG (INFO, TAG, "Created new LED instance");
-                gLedInstance[gCurrLedInstance].state = 0;
-                gLedInstance[gCurrLedInstance].power = 0;
-                gCurrLedInstance++;
-                strncpy ((char *)response->resourceUri, newLedUri, sizeof(response->resourceUri));
-                ehResult = OC_EH_RESOURCE_CREATED;
-            }
-        }
-        else
-        {
-            respPLPost_led = constructResponse(ehRequest);
-        }
-    }
-    else
-    {
-        for (int i = 0; i < SAMPLE_MAX_NUM_POST_INSTANCE; i++)
-        {
-            if (ehRequest->resource == gLedInstance[i].handle)
-            {
-                if (i == 0)
-                {
-                    respPLPost_led = constructResponse(ehRequest);
-                    break;
-                }
-                else if (i == 1)
-                {
-                    respPLPost_led = constructResponse(ehRequest);
-                }
-            }
-        }
-    }
-
-    if (respPLPost_led != NULL)
-    {
-        *payload = respPLPost_led;
-        ehResult = OC_EH_OK;
-    }
-    else
-    {
-        OIC_LOG_V (INFO, TAG, "Payload was NULL");
-        ehResult = OC_EH_ERROR;
-    }
-
-    return ehResult;
-}
-
-OCEntityHandlerResult
-OCEntityHandlerCb (OCEntityHandlerFlag flag,
-        OCEntityHandlerRequest *entityHandlerRequest,
-        void* callbackParam)
-{
-    OIC_LOG_V (INFO, TAG, "Inside entity handler - flags: 0x%x", flag);
-    (void)callbackParam;
-    OCEntityHandlerResult ehResult = OC_EH_ERROR;
-
-    OCEntityHandlerResponse response;
-    memset(&response, 0, sizeof(response));
-
-    // Validate pointer
-    if (!entityHandlerRequest)
-    {
-        OIC_LOG (ERROR, TAG, "Invalid request pointer");
-        return OC_EH_ERROR;
-    }
-
-    OCRepPayload* payload = NULL;
-
-    if (flag & OC_REQUEST_FLAG)
-    {
-        OIC_LOG (INFO, TAG, "Flag includes OC_REQUEST_FLAG");
-        if (entityHandlerRequest)
-        {
-            if (OC_REST_GET == entityHandlerRequest->method)
-            {
-                OIC_LOG (INFO, TAG, "Received OC_REST_GET from client");
-                ehResult = ProcessGetRequest (entityHandlerRequest, &payload);
-            }
-            else if (OC_REST_PUT == entityHandlerRequest->method)
-            {
-                OIC_LOG (INFO, TAG, "Received OC_REST_PUT from client");
-                ehResult = ProcessPutRequest (entityHandlerRequest, &payload);
-            }
-            else if (OC_REST_POST == entityHandlerRequest->method)
-            {
-                OIC_LOG (INFO, TAG, "Received OC_REST_POST from client");
-                ehResult = ProcessPostRequest (entityHandlerRequest, &response, &payload);
-            }
-            else
-            {
-                OIC_LOG_V (INFO, TAG, "Received unsupported method %d from client",
-                        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)
-                {
-                    OIC_LOG(ERROR, TAG, "Error sending response");
-                    ehResult = OC_EH_ERROR;
-                }
-            }
-        }
-    }
-
-    OCPayloadDestroy(response.payload);
-    return ehResult;
-}
-
-/* SIGINT handler: set gQuitFlag to 1 for graceful termination */
-void handleSigInt(int signum)
-{
-    if (signum == SIGINT)
-    {
-        gQuitFlag = 1;
-    }
-}
-
-FILE* server_fopen(const char *path, const char *mode)
-{
-       char data_dir[MAX_FILE_PATH_LEN] = {0,};
-
-       snprintf(data_dir, MAX_FILE_PATH_LEN, "%s/network/%s",
-                               tzplatform_getenv(TZ_SYS_GLOBALUSER_DATA), CRED_FILE);
-
-       (void)path;
-
-    return fopen(data_dir, mode);
-}
-
-static void OtmEventHandler(void *ctx, const char *addr, uint16_t port,
-        const char* ownerId, OCOtmEvent_t event)
-{
-    (void)ctx;
-    printf("--------------------------------------\n");
-    printf("Get OTM event.\n");
-    printf("Address : %s\n", addr);
-    printf("Port : %d\n", port);
-    printf("Owner ID : %s\n", ownerId);
-
-    switch (event)
-    {
-        case OIC_OTM_READY:
-            printf("State : OIC_OTM_READY\n");
-            break;
-        case OIC_OTM_STARTED:
-            printf("State : OIC_OTM_STARTED\n");
-            break;
-        case OIC_OTM_DONE:
-            printf("State : OIC_OTM_DONE\n");
-            break;
-        case OIC_OTM_ERROR:
-            printf("State : OIC_OTM_ERROR\n");
-            break;
-        default:
-            printf("State : Unknown state.\n");
-            break;
-    }
-    printf("--------------------------------------\n");
-}
-
-int main()
-{
-    struct timespec timeout;
-
-    OIC_LOG(DEBUG, TAG, "OCServer is starting...");
-
-    //This function should be invoked before invoke OCInit
-    OCSetOtmEventHandler(NULL, OtmEventHandler);
-
-    // Initialize Persistent Storage for SVR database
-    OCPersistentStorage ps = {server_fopen, fread, fwrite, fclose, unlink, NULL, NULL};
-
-    OCRegisterPersistentStorageHandler(&ps);
-
-    if (OCInit(NULL, 0, OC_SERVER) != OC_STACK_OK)
-    {
-        OIC_LOG(ERROR, TAG, "OCStack init error");
-        return 0;
-    }
-
-    /*
-     * Declare and create the example resource: LED
-     */
-    createLEDResource(gResourceUri, &LED, false, 0);
-
-    timeout.tv_sec  = 0;
-    timeout.tv_nsec = 100000000L;
-
-    // Break from loop with Ctrl-C
-    OIC_LOG(INFO, TAG, "Entering ocserver main loop...");
-    signal(SIGINT, handleSigInt);
-    while (!gQuitFlag)
-    {
-        if (OCProcess() != OC_STACK_OK)
-        {
-            OIC_LOG(ERROR, TAG, "OCStack process error");
-            return 0;
-        }
-        nanosleep(&timeout, NULL);
-    }
-
-    OIC_LOG(INFO, TAG, "Exiting ocserver main loop...");
-
-    if (OCStop() != OC_STACK_OK)
-    {
-        OIC_LOG(ERROR, TAG, "OCStack process error");
-    }
-
-    return 0;
-}
-
-int createLEDResource (char *uri, LEDResource *ledResource, bool resourceState, int resourcePower)
-{
-    if (!uri)
-    {
-        OIC_LOG(ERROR, TAG, "Resource URI cannot be NULL");
-        return -1;
-    }
-
-    ledResource->state = resourceState;
-    ledResource->power= resourcePower;
-    OCStackResult res = OCCreateResource(&(ledResource->handle),
-            "core.led",
-            OC_RSRVD_INTERFACE_DEFAULT,
-            uri,
-            OCEntityHandlerCb,
-            NULL,
-            OC_DISCOVERABLE|OC_OBSERVABLE | OC_SECURE);
-    OIC_LOG_V(INFO, TAG, "Created LED resource with result: %s", getResult(res));
-
-    return 0;
-}
-
-
diff --git a/src/fn-manager/fn_context.c b/src/fn-manager/fn_context.c
new file mode 100755 (executable)
index 0000000..6e482eb
--- /dev/null
@@ -0,0 +1,17 @@
+#include <fn_context.h>
+
+int fn_context_create_context()
+{
+       _fn_ctx = g_new0(fn_context, 1);
+       if (!_fn_ctx) {
+               LOG_DEBUG("create mtp_context is failed");
+       }
+
+       return FN_ERROR_NONE;
+}
+
+fn_context *fn_context_get_context()
+{
+       return _fn_ctx;
+}
+
diff --git a/src/fn-manager/fn_group.c b/src/fn-manager/fn_group.c
new file mode 100755 (executable)
index 0000000..f879f76
--- /dev/null
@@ -0,0 +1,2 @@
+#include <fn_group.h>
+
diff --git a/src/fn-manager/fn_iotivity.c b/src/fn-manager/fn_iotivity.c
new file mode 100755 (executable)
index 0000000..293cc0b
--- /dev/null
@@ -0,0 +1,10 @@
+#include <fn_iotivity.h>
+
+int fn_iotivity_initialize()
+{
+       OCStackResult result = OCInit(NULL, 0, OC_CLIENT_SERVER);
+       LOG_DEBUG("OCInit : %s", fn_get_iotivity_error_string(result));
+
+       return FN_ERROR_NONE;
+}
+
diff --git a/src/fn-manager/fn_log.c b/src/fn-manager/fn_log.c
new file mode 100755 (executable)
index 0000000..3436b8b
--- /dev/null
@@ -0,0 +1,76 @@
+#include <fn_log.h>
+
+const char *fn_get_iotivity_error_string(OCStackResult result) {
+       switch (result) {
+               case OC_STACK_OK:
+                       return "OC_STACK_OK";
+               case OC_STACK_RESOURCE_CREATED:
+                       return "OC_STACK_RESOURCE_CREATED";
+               case OC_STACK_RESOURCE_DELETED:
+                       return "OC_STACK_RESOURCE_DELETED";
+               case OC_STACK_INVALID_URI:
+                       return "OC_STACK_INVALID_URI";
+               case OC_STACK_INVALID_QUERY:
+                       return "OC_STACK_INVALID_QUERY";
+               case OC_STACK_INVALID_IP:
+                       return "OC_STACK_INVALID_IP";
+               case OC_STACK_INVALID_PORT:
+                       return "OC_STACK_INVALID_PORT";
+               case OC_STACK_INVALID_CALLBACK:
+                       return "OC_STACK_INVALID_CALLBACK";
+               case OC_STACK_INVALID_METHOD:
+                       return "OC_STACK_INVALID_METHOD";
+               case OC_STACK_NO_MEMORY:
+                       return "OC_STACK_NO_MEMORY";
+               case OC_STACK_COMM_ERROR:
+                       return "OC_STACK_COMM_ERROR";
+               case OC_STACK_INVALID_PARAM:
+                       return "OC_STACK_INVALID_PARAM";
+               case OC_STACK_NOTIMPL:
+                       return "OC_STACK_NOTIMPL";
+               case OC_STACK_NO_RESOURCE:
+                       return "OC_STACK_NO_RESOURCE";
+               case OC_STACK_RESOURCE_ERROR:
+                       return "OC_STACK_RESOURCE_ERROR";
+               case OC_STACK_SLOW_RESOURCE:
+                       return "OC_STACK_SLOW_RESOURCE";
+               case OC_STACK_NO_OBSERVERS:
+                       return "OC_STACK_NO_OBSERVERS";
+#ifdef WITH_PRESENCE
+               case OC_STACK_PRESENCE_STOPPED:
+                       return "OC_STACK_PRESENCE_STOPPED";
+#endif
+               case OC_STACK_ERROR:
+                       return "OC_STACK_ERROR";
+               default:
+                       return "UNKNOWN";
+       }
+}
+
+const char *fn_get_tizen_error_string(int result) {
+       switch (result) {
+               case FN_ERROR_NONE:
+                       return "FN_ERROR_NONE";
+               case FN_ERROR_IO_ERROR:
+                       return "FN_ERROR_IO_ERROR";
+               case FN_ERROR_INVALID_PARAMETER:
+                       return "FN_ERROR_INVALID_PARAMETER";
+               case FN_ERROR_OUT_OF_MEMORY:
+                       return "FN_ERROR_OUT_OF_MEMORY";
+               case FN_ERROR_PERMISSION_DENIED:
+                       return "FN_ERROR_PERMISSION_DENIED";
+               case FN_ERROR_NOT_SUPPORTED:
+                       return "FN_ERROR_NOT_SUPPORTED";
+               case FN_ERROR_COMM_ERROR:
+                       return "FN_ERROR_COMM_ERROR";
+               case FN_ERROR_RX:
+                       return "FN_ERROR_RX";
+               case FN_ERROR_TX:
+                       return "FN_ERROR_RX";
+               case FN_ERROR_PLUGIN_FAIL:
+                       return "FN_ERROR_PLUGIN_FAIL";
+               default:
+                       return "UNKNOWN";
+       }
+}
+
diff --git a/src/fn-manager/fn_manager.c b/src/fn-manager/fn_manager.c
new file mode 100755 (executable)
index 0000000..dae56e9
--- /dev/null
@@ -0,0 +1,46 @@
+#include <fn_manager.h>
+
+int main(int argc, char *argv[])
+{
+       LOG_DEBUG("FN Manager start");
+
+       //1. create & context
+       int ret = fn_context_create_context();
+       if (ret != FN_ERROR_NONE) {
+               LOG_DEBUG("FN context create failed exit");
+               goto EXIT;
+       }
+
+       fn_context *fn_ctx = fn_context_get_context();
+
+       //2. parsing pass arguements and determine this device is owner or client
+       if (argc > 1 && strcmp(argv[1],"1") == 0)
+               fn_ctx->role = FN_ROLE_OWNER;
+       else
+               fn_ctx->role = FN_ROLE_CLIENT;
+
+
+       //3. iotivity iniatlize
+       ret = fn_iotivity_initialize();
+       if (ret != FN_ERROR_NONE) {
+               goto EXIT;
+       }
+
+       //4. dbus interface initialize
+
+       //5. Make RX/TX interface
+
+
+       //6. group mgr initialize
+
+       // loop run
+       fn_ctx->main_loop = g_main_loop_new(NULL, FALSE);
+       g_main_loop_run(fn_ctx->main_loop);
+
+EXIT:
+       // deinitialize phase
+
+       LOG_DEBUG("FN Manager exit");
+
+       return 0;
+}
diff --git a/src/fn-manager/fn_rx.c b/src/fn-manager/fn_rx.c
new file mode 100755 (executable)
index 0000000..177706c
--- /dev/null
@@ -0,0 +1,2 @@
+#include <fn_rx.h>
+
diff --git a/src/fn-manager/fn_tx.c b/src/fn-manager/fn_tx.c
new file mode 100755 (executable)
index 0000000..de435de
--- /dev/null
@@ -0,0 +1,2 @@
+#include <fn_tx.h>
+
diff --git a/src/include/fn_context.h b/src/include/fn_context.h
new file mode 100755 (executable)
index 0000000..7fa3fc6
--- /dev/null
@@ -0,0 +1,23 @@
+#ifndef __FN_CONTEXT_H__
+#define __FN_CONTEXT_H__
+
+#include <glib.h>
+#include <fn_log.h>
+
+typedef struct _fn_context fn_context;
+
+struct _fn_context {
+       GMainLoop *main_loop;
+       fn_role_e role;
+
+       // TX / RX thread
+       // dbus interface
+       // group list
+};
+
+fn_context *_fn_ctx;
+
+int fn_context_create_context();
+fn_context *fn_context_get_context();
+
+#endif
diff --git a/src/include/fn_enum.h b/src/include/fn_enum.h
new file mode 100755 (executable)
index 0000000..14e4413
--- /dev/null
@@ -0,0 +1,28 @@
+#ifndef __FN_ENUM_H__
+#define __FN_ENUM_H__
+
+#include <tizen.h>
+
+#define TIZEN_ERROR_FN 0
+
+/* error enum */
+typedef enum {
+       FN_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
+       FN_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, /**< I/O error */
+       FN_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
+       FN_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */
+       FN_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */
+       FN_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, /**< Not supported */
+       FN_ERROR_COMM_ERROR = TIZEN_ERROR_FN | 0x01, /**< communication error */
+       FN_ERROR_RX = TIZEN_ERROR_FN | 0x02, /**< RX error */
+       FN_ERROR_TX = TIZEN_ERROR_FN | 0x03, /**< TX error */
+       FN_ERROR_PLUGIN_FAIL = TIZEN_ERROR_FN | 0x04, /**< Plugin failed */
+} fn_error_e;
+
+/* role enum */
+typedef enum {
+       FN_ROLE_OWNER,
+       FN_ROLE_CLIENT
+} fn_role_e;
+
+#endif
diff --git a/src/include/fn_group.h b/src/include/fn_group.h
new file mode 100755 (executable)
index 0000000..eb50739
--- /dev/null
@@ -0,0 +1,4 @@
+#ifndef __FN_GROUP_H__
+#define __FN_GROUP_H__
+
+#endif
diff --git a/src/include/fn_iotivity.h b/src/include/fn_iotivity.h
new file mode 100755 (executable)
index 0000000..bcbfb81
--- /dev/null
@@ -0,0 +1,12 @@
+#ifndef __FN_IOTIVITY_H__
+#define __FN_IOTIVITY_H__
+
+#include <iotivity_config.h>
+#include <ocstack.h>
+#include <ocpayload.h>
+#include <fn_log.h>
+#include <fn_context.h>
+
+int fn_iotivity_initialize();
+
+#endif
diff --git a/src/include/fn_log.h b/src/include/fn_log.h
new file mode 100755 (executable)
index 0000000..4fb27ee
--- /dev/null
@@ -0,0 +1,43 @@
+#ifndef __FN_LOG_H__
+#define __FN_LOG_H__
+
+#include <dlog.h>
+#include <fn_enum.h>
+#include <fn_iotivity.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define COLOR_RED               "\033[0;31m"
+#define COLOR_GREEN             "\033[0;32m"
+#define COLOR_BROWN             "\033[0;33m"
+#define COLOR_BLUE              "\033[0;34m"
+#define COLOR_PURPLE            "\033[0;35m"
+#define COLOR_CYAN              "\033[0;36m"
+#define COLOR_LIGHTBLUE         "\033[0;37m"
+#define COLOR_END               "\033[0;m"
+
+#define LOG_TAG "FN_MANAGER"
+
+#define LOG_DEBUG(fmt, ...) \
+       do { \
+               LOGD(COLOR_BROWN" " fmt COLOR_END, ##__VA_ARGS__); \
+       } while (0)
+#define LOG_ERR(fmt, ...) \
+       do { \
+               LOGE(COLOR_RED" " fmt COLOR_END, ##__VA_ARGS__); \
+       } while (0)
+#define LOG_BEGIN() \
+       do { \
+               LOGD(COLOR_BLUE"BEGIN >>>>"COLOR_END); \
+       } while (0)
+#define LOG_END() \
+       do { \
+               LOGD(COLOR_BLUE"END <<<<"COLOR_END); \
+       } while (0)
+
+const char *fn_get_iotivity_error_string(OCStackResult result);
+const char *fn_get_tizen_error_string(int result);
+
+#endif
diff --git a/src/include/fn_manager.h b/src/include/fn_manager.h
new file mode 100755 (executable)
index 0000000..1daca44
--- /dev/null
@@ -0,0 +1,9 @@
+#ifndef __FN_MANAGER_H__
+#define __FN_MANAGER_H__
+
+#include <fn_log.h>
+#include <fn_group.h>
+#include <fn_rx.h>
+#include <fn_tx.h>
+
+#endif
diff --git a/src/include/fn_rx.h b/src/include/fn_rx.h
new file mode 100755 (executable)
index 0000000..7a8b382
--- /dev/null
@@ -0,0 +1,5 @@
+#ifndef __FN_RX_H__
+#define __FN_RX_H__
+
+#endif
+
diff --git a/src/include/fn_tx.h b/src/include/fn_tx.h
new file mode 100755 (executable)
index 0000000..8b13789
--- /dev/null
@@ -0,0 +1 @@
+