Import('env')
if env.get('RELEASE'):
- env.AppendUnique(CCFLAGS = ['-Os'])
- env.AppendUnique(CPPDEFINES = ['NDEBUG'])
+ env.AppendUnique(CCFLAGS = ['-Os'])
+ env.AppendUnique(CPPDEFINES = ['NDEBUG'])
else:
- env.AppendUnique(CCFLAGS = ['-g'])
+ env.AppendUnique(CCFLAGS = ['-g'])
if env.get('LOGGING'):
- env.AppendUnique(CPPDEFINES = ['-DTB_LOG'])
+ env.AppendUnique(CPPDEFINES = ['-DTB_LOG'])
lib_env = env.Clone()
SConscript(env.get('SRC_DIR') + '/service/third_party_libs.scons', 'lib_env')
rd_env.PrependUnique(LIBS = ['oc', 'octbstack', 'oc_logger', 'connectivity_abstraction', 'libcoap'])
if target_os not in ['windows', 'winrt']:
- rd_env.AppendUnique(CXXFLAGS = ['-O2', '-g', '-Wall', '-Wextra'])
+ rd_env.AppendUnique(CXXFLAGS = ['-O2', '-g', '-Wall', '-Wextra'])
if target_os == 'linux':
- rd_env.AppendUnique(LIBS = ['pthread'])
+ rd_env.AppendUnique(LIBS = ['pthread'])
if target_os == 'android':
- rd_env.AppendUnique(CXXFLAGS = ['-frtti', '-fexceptions'])
- rd_env.AppendUnique(LIBS = ['gnustl_static'])
+ rd_env.AppendUnique(CXXFLAGS = ['-frtti', '-fexceptions'])
+ rd_env.AppendUnique(LIBS = ['gnustl_static'])
- if not env.get('RELEASE'):
- rd_env.AppendUnique(LIBS = ['log'])
+ if not env.get('RELEASE'):
+ rd_env.AppendUnique(LIBS = ['log'])
######################################################################
# Source files and Targets
######################################################################
RD_SRC_DIR = 'src/'
rd_src = [
- RD_SRC_DIR + 'rd_server.c',
- RD_SRC_DIR + 'rd_payload.c',
- RD_SRC_DIR + 'rd_client.c',
- ]
+ RD_SRC_DIR + '/internal/rd_storage.c',
+ RD_SRC_DIR + 'rd_server.c',
+ RD_SRC_DIR + 'rd_payload.c',
+ RD_SRC_DIR + 'rd_client.c',
+ ]
if target_os in ['tizen'] :
rdsdk = rd_env.SharedLibrary('resource_directory', rd_src)
*/
void OCRDPayloadLog(LogLevel level, const char *tag, const OCRDPayload *payload);
+/**
+ * Logs the subset of the OCRDPayload, prints separately OCRDPublish.
+ *
+ * @param level Log level DEBUG or INFO or ERROR.
+ * @param tag File specific tag to use.
+ * @param payload Pointer to already allocated memory for OCRDPublish.
+ */
+void OCRDPublishPayloadLog(LogLevel level, const char *tag,
+ const OCRDPublishPayload *rdPublish);
+
#ifdef __cplusplus
}
#endif // __cplusplus
--- /dev/null
+//******************************************************************
+//
+// 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.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+#include "rd_storage.h"
+
+#include <pthread.h>
+
+#include "oic_malloc.h"
+#include "logger.h"
+
+#include "rd_payload.h"
+
+#define TAG PCF("RDStorage")
+
+pthread_mutex_t storageMutex = PTHREAD_MUTEX_INITIALIZER;
+// This variable holds the published resources on the RD.
+static OCRDStorePublishResources *g_rdStorage = NULL;
+
+static void printStoragedResources(OCRDStorePublishResources *payload)
+{
+ OC_LOG_V(DEBUG, TAG, "Print Storage Resources ... ");
+ for (OCRDStorePublishResources *temp = payload; temp; temp = temp->next)
+ {
+ if (temp->publishResource)
+ {
+ OCRDPublishPayloadLog(DEBUG, TAG, temp->publishResource);
+ }
+ }
+}
+
+OCStackResult OCRDStorePublishedResources(OCRDPublishPayload *payload)
+{
+ OCRDStorePublishResources *storeResource = OICCalloc(1, sizeof(OCRDStorePublishResources));
+ if (!storeResource)
+ {
+ OC_LOG_V(ERROR, TAG, "Failed allocating memory for OCRDStorePublishResources.");
+ return OC_STACK_NO_MEMORY;
+ }
+
+ OC_LOG_V(DEBUG, TAG, "Storing Resources ... ");
+
+ storeResource->publishResource = OCRDPublishPayloadCreate(payload->ttl, payload->links);
+ if (!storeResource->publishResource)
+ {
+ OC_LOG_V(ERROR, TAG, "Failed allocating memory for OCRDPublishResources.");
+ OICFree(storeResource);
+ return OC_STACK_NO_MEMORY;
+ }
+ storeResource->next = NULL;
+
+ pthread_mutex_lock(&storageMutex);
+ if (g_rdStorage)
+ {
+ OCRDStorePublishResources *temp = g_rdStorage;
+ while(temp->next)
+ {
+ temp = temp->next;
+ }
+ temp->next = storeResource;
+ }
+ else
+ {
+ g_rdStorage = storeResource;
+ }
+ pthread_mutex_unlock(&storageMutex);
+
+ printStoragedResources(g_rdStorage);
+ return OC_STACK_OK;
+}
--- /dev/null
+//******************************************************************
+//
+// 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.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+#ifndef _RESOURCE_DIRECTORY_SERVER_STORAGE_H_
+#define _RESOURCE_DIRECTORY_SERVER_STORAGE_H_
+
+#include "rd_types.h"
+
+/** Stucture holding Published Resources on the Resource Directory. */
+typedef struct OCRDStorePublishResources
+{
+ /** Publish resource. */
+ OCRDPublishPayload *publishResource;
+ /** Linked list pointing to next published resource. */
+ struct OCRDStorePublishResources *next;
+} OCRDStorePublishResources;
+
+/**
+ * Stores the publish resources.
+ *
+ * @param payload RDPublish payload sent from the remote device.
+ *
+ * @return ::OC_STACK_OK upon success, ::OC_STACK_ERROR in case of error.
+ */
+OCStackResult OCRDStorePublishedResources(OCRDPublishPayload *payload);
+
+#ifdef __cplusplus
+}
+#endif // __cplusplus
+
+#endif //_RESOURCE_DIRECTORY_SERVER_STORAGE_H_
links = links->next;
OICFree(tmp);
}
-
}
OCStackResult OCRDPayloadToCbor(const OCRDPayload *rdPayload, uint8_t **outPayload, size_t *size)
OC_LOG_V(DEBUG, TAG, "RD Payload bias factor: %d", rdPayload->rdDiscovery->sel);
}
}
+
cborEncoderResult = cbor_encoder_close_container(&rootArray, &map);
if (CborNoError != cborEncoderResult)
{
OCRDLinksPayload **linksPayload)
{
OCRDLinksPayload *payload = OICCalloc(1, sizeof(OCRDLinksPayload));
-
if (!payload)
{
goto no_memory;
OCRDLinksPayload *linksPayload)
{
OCRDPublishPayload *rdPublish = OICCalloc(1, sizeof(OCRDPublishPayload));
-
if (!rdPublish)
{
return NULL;
{
OC_LOG_V(level, tag, "RD Payload Discovery BIAS : %d", payload->rdDiscovery->sel);
}
+ OCRDPublishPayloadLog(level, tag, payload->rdPublish);
+}
- if (payload->rdPublish)
+void OCRDPublishPayloadLog(LogLevel level, const char *tag, const OCRDPublishPayload *rdPublish)
+{
+ if (rdPublish)
{
if (payload->rdPublish->deviceName.deviceName)
{
OC_LOG_V(level, tag, "RD Payload Publish ID : %s", payload->rdPublish->deviceId.id);
}
- OC_LOG_V(level, tag, "RD Payload Publish TTL : %d", payload->rdPublish->ttl);
+ OC_LOG_V(level, tag, "RD Payload Publish TTL : %d", rdPublish->ttl);
- if (payload->rdPublish->links)
+ if (rdPublish->links)
{
for (OCRDLinksPayload *temp = payload->rdPublish->links; temp; temp = temp->next)
{
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#include "rd_server.h"
+
#include "rd_types.h"
#include "rd_payload.h"
+#include "rd_storage.h"
#include "logger.h"
return OC_EH_ERROR;
}
- OCRDPayload *payload = (OCRDPayload*)ehRequest->payload;
+ OCRDPayload *payload = (OCRDPayload *)ehRequest->payload;
if (payload->payloadType == RD_PAYLOAD_TYPE_PUBLISH)
{
- // TODO STORE RESOURCE...
+ OCRDStorePublishedResources(payload->rdPublish);
}
OC_LOG_V(DEBUG, TAG, "Sending success response");
return ehResult;
}
+
/*
* This internal method is the entity handler for RD resources and
* will handle REST request (GET/PUT/POST/DEL) for them.
*/
-static OCEntityHandlerResult RDEntityHandler(OCEntityHandlerFlag flag,
+static OCEntityHandlerResult rdEntityHandler(OCEntityHandlerFlag flag,
OCEntityHandlerRequest *ehRequest, void *callbackParameter)
{
OCEntityHandlerResult ehRet = OC_EH_ERROR;
OC_RSRVD_RESOURCE_TYPE_RD,
OC_RSRVD_INTERFACE_DEFAULT,
OC_RSRVD_RD_URI,
- RDEntityHandler,
+ rdEntityHandler,
NULL,
(OC_ACTIVE | OC_DISCOVERABLE | OC_OBSERVABLE));