From 88d9299c4d81440adb9a6d8079853d299ea36c3a Mon Sep 17 00:00:00 2001 From: "jyong2.kim" Date: Fri, 24 Jul 2015 16:37:28 +0900 Subject: [PATCH] Remove "define variables" on Notification Manager. change anonymous namespace variables from define variables. change macro to function in OIC::Service namespace. Change-Id: I9d1e2a8d23d92b190b3255d21434c84efe359c73 Signed-off-by: jyong2.kim Reviewed-on: https://gerrit.iotivity.org/gerrit/1875 Tested-by: jenkins-iotivity Reviewed-by: Uze Choi --- .../NotificationManager/src/HostingObject.cpp | 16 +++++++++++++-- .../NotificationManager/src/HostingObject.h | 2 ++ .../NotificationManager/src/ResourceHosting.cpp | 7 ++----- .../NotificationManager/src/hosting.cpp | 23 +++++++++------------- 4 files changed, 27 insertions(+), 21 deletions(-) diff --git a/service/notification-manager/NotificationManager/src/HostingObject.cpp b/service/notification-manager/NotificationManager/src/HostingObject.cpp index 22d4b5c..8dcf868 100644 --- a/service/notification-manager/NotificationManager/src/HostingObject.cpp +++ b/service/notification-manager/NotificationManager/src/HostingObject.cpp @@ -24,8 +24,20 @@ namespace OIC { namespace Service { -#define HOSTING_LOG_TAG PCF("Hosting") -#define OIC_HOSTING_LOG(level, tag, ...) OCLogv((level), (HOSTING_LOG_TAG), __VA_ARGS__) + +void OIC_HOSTING_LOG(LogLevel level, const char * format, ...) +{ + if (!format) + { + return; + } + char buffer[MAX_LOG_V_BUFFER_SIZE] = {}; + va_list args; + va_start(args, format); + vsnprintf(buffer, sizeof buffer - 1, format, args); + va_end(args); + OCLog(level, PCF("Hosting"), buffer); +} HostingObject::HostingObject() : remoteObject(nullptr), mirroredServer(nullptr), diff --git a/service/notification-manager/NotificationManager/src/HostingObject.h b/service/notification-manager/NotificationManager/src/HostingObject.h index a93a30a..514eb43 100644 --- a/service/notification-manager/NotificationManager/src/HostingObject.h +++ b/service/notification-manager/NotificationManager/src/HostingObject.h @@ -33,6 +33,8 @@ namespace OIC namespace Service { +void OIC_HOSTING_LOG(LogLevel level, const char * format, ...); + class HostingObject { private: diff --git a/service/notification-manager/NotificationManager/src/ResourceHosting.cpp b/service/notification-manager/NotificationManager/src/ResourceHosting.cpp index 46289b4..2e77d8b 100755 --- a/service/notification-manager/NotificationManager/src/ResourceHosting.cpp +++ b/service/notification-manager/NotificationManager/src/ResourceHosting.cpp @@ -28,13 +28,10 @@ namespace OIC namespace Service { -#define HOSTING_TAG "/hosting" -#define HOSTING_TAG_SIZE ((size_t)8) -#define HOSTING_LOG_TAG PCF("Hosting") -#define OIC_HOSTING_LOG(level, tag, ...) OCLogv((level), (HOSTING_LOG_TAG), __VA_ARGS__) - namespace { + std::string HOSTING_TAG = "/hosting"; + size_t HOSTING_TAG_SIZE = (size_t)HOSTING_TAG.size(); std::string MULTICAST_PRESENCE_ADDRESS = std::string("coap://") + OC_MULTICAST_PREFIX; std::string HOSTING_RESOURSE_TYPE = "Resource.Hosting"; } diff --git a/service/notification-manager/NotificationManager/src/hosting.cpp b/service/notification-manager/NotificationManager/src/hosting.cpp index 79ba751..d222795 100644 --- a/service/notification-manager/NotificationManager/src/hosting.cpp +++ b/service/notification-manager/NotificationManager/src/hosting.cpp @@ -29,27 +29,22 @@ #include "octypes.h" #include "logger.h" #include "ResourceHosting.h" - -namespace -{ - #define OC_TRANSPORT CT_ADAPTER_IP - #define HOSTING_TAG PCF("Hosting") - #define OIC_HOSTING_LOG(level, tag, ...) OCLogv((level), (HOSTING_TAG), __VA_ARGS__) - OIC::Service::ResourceHosting * rhInstance = OIC::Service::ResourceHosting::getInstance(); -} +#include "HostingObject.h" OCStackResult OICStartCoordinate() { + using namespace OIC::Service; OCStackResult retResult = OC_STACK_OK; try { - rhInstance->startHosting(); - }catch(OIC::Service::PlatformException &e) + ResourceHosting::getInstance()->startHosting(); + }catch(PlatformException &e) { - OIC_HOSTING_LOG(DEBUG, "[OICStartCoordinate] platformException, reason:%s", e.what()); + OIC_HOSTING_LOG(DEBUG, + "[OICStartCoordinate] platformException, reason:%s", e.what()); retResult = OC_STACK_ERROR; throw; - }catch(OIC::Service::InvalidParameterException &e) + }catch(InvalidParameterException &e) { OIC_HOSTING_LOG(DEBUG, "[OICStartCoordinate] InvalidParameterException, reason:%s", e.what()); @@ -57,7 +52,7 @@ OCStackResult OICStartCoordinate() throw; }catch(...) { - OIC_HOSTING_LOG(DEBUG, "[OICStartCoordinate] Unknown Exception", ""); + OIC_HOSTING_LOG(DEBUG, "[OICStartCoordinate] Unknown Exception"); retResult = OC_STACK_ERROR; } @@ -67,7 +62,7 @@ OCStackResult OICStartCoordinate() OCStackResult OICStopCoordinate() { OCStackResult retResult = OC_STACK_OK; - rhInstance->stopHosting(); + OIC::Service::ResourceHosting::getInstance()->stopHosting(); return retResult; } -- 2.7.4