Fix primitiveResource and serverBuilder to remove incompatibles for GCC4.6
authorcoderhyme <jhyo.kim@samsung.com>
Thu, 16 Jul 2015 06:25:41 +0000 (15:25 +0900)
committerUze Choi <uzchoi@samsung.com>
Thu, 16 Jul 2015 08:22:17 +0000 (08:22 +0000)
Change some codes using C++11 features which is not supported on GCC4.6.

Change-Id: I864321abdfaee960277ebfcab5fa09c33757453e
Signed-off-by: coderhyme <jhyo.kim@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/1688
Reviewed-by: Uze Choi <uzchoi@samsung.com>
Tested-by: Uze Choi <uzchoi@samsung.com>
23 files changed:
service/resource-manipulation/src/common/expiryTimer/SConscript
service/resource-manipulation/src/common/primitiveResource/include/PrimitiveException.h
service/resource-manipulation/src/common/primitiveResource/include/PrimitiveResource.h
service/resource-manipulation/src/common/primitiveResource/include/ResourceAttributes.h
service/resource-manipulation/src/common/primitiveResource/include/internal/AssertUtils.h
service/resource-manipulation/src/common/primitiveResource/include/internal/PrimitiveResourceImpl.h
service/resource-manipulation/src/common/primitiveResource/include/internal/ResourceAttributesConverter.h
service/resource-manipulation/src/common/primitiveResource/include/internal/ResourceAttributesUtils.h
service/resource-manipulation/src/common/primitiveResource/src/PresenceSubscriber.cpp
service/resource-manipulation/src/common/primitiveResource/src/PrimitiveResource.cpp
service/resource-manipulation/src/common/primitiveResource/src/ResourceAttributes.cpp
service/resource-manipulation/src/common/primitiveResource/src/ResponseStatement.cpp
service/resource-manipulation/src/common/primitiveResource/unittests/PresenceSubscriberTest.cpp
service/resource-manipulation/src/common/primitiveResource/unittests/PrimitiveResourceTest.cpp
service/resource-manipulation/src/common/primitiveResource/unittests/ResourceAttributesTest.cpp
service/resource-manipulation/src/serverBuilder/include/ResourceObject.h
service/resource-manipulation/src/serverBuilder/include/internal/RequestHandler.h
service/resource-manipulation/src/serverBuilder/src/PrimitiveResponse.cpp
service/resource-manipulation/src/serverBuilder/src/RequestHandler.cpp
service/resource-manipulation/src/serverBuilder/src/ResourceObject.cpp
service/resource-manipulation/src/serverBuilder/unittests/PrimitiveResponseTest.cpp
service/resource-manipulation/src/serverBuilder/unittests/RequestHandlerTest.cpp
service/resource-manipulation/src/serverBuilder/unittests/ResourceObjectTest.cpp

index 0fd1747..de1a13b 100644 (file)
@@ -46,7 +46,7 @@ timer_env.AppendUnique(CPPPATH = ['src'])
 timer_env.PrependUnique(LIBS = ['oc', 'octbstack', 'oc_logger', 'connectivity_abstraction', 'libcoap'])
 
 if target_os not in ['windows', 'winrt']:
-    timer_env.AppendUnique(CXXFLAGS = ['-O2', '-g', '-Wall', '-fmessage-length=0', '-std=c++11'])
+    timer_env.AppendUnique(CXXFLAGS = ['-O2', '-g', '-Wall', '-fmessage-length=0', '-std=c++0x'])
 
 if target_os == 'linux':
     timer_env.AppendUnique(LIBS = ['pthread'])
index c623eb1..967008d 100755 (executable)
@@ -37,7 +37,9 @@ namespace OIC
             explicit PrimitiveException(const std::string& what) : m_what{ what } {}
             explicit PrimitiveException(std::string&& what) : m_what{ std::move(what) } {}
 
-            const char* what() const noexcept override
+            virtual ~PrimitiveException() noexcept {}
+
+            virtual const char* what() const noexcept
             {
                 return m_what.c_str();
             }
index 9dde868..69aed42 100755 (executable)
@@ -33,8 +33,8 @@ namespace OIC
     namespace Service
     {
 
-        using HeaderOption = OC::HeaderOption::OCHeaderOption;
-        using HeaderOptions = std::vector<HeaderOption>;
+        typedef OC::HeaderOption::OCHeaderOption HeaderOption;
+        typedef std::vector<HeaderOption> HeaderOptions;
 
         class ResourceAttributes;
         class ResponseStatement;
@@ -42,21 +42,21 @@ namespace OIC
         class PrimitiveResource
         {
         public:
-            using Ptr = std::shared_ptr<PrimitiveResource>;
+            typedef std::shared_ptr<PrimitiveResource> Ptr;
 
-            using GetCallback = std::function<
-                    void(const HeaderOptions&, const ResponseStatement&, int)>;
+            typedef std::function<void(const HeaderOptions&, const ResponseStatement&, int)>
+                    GetCallback;
 
-            using SetCallback = std::function<
-                    void(const HeaderOptions&, const ResponseStatement&, int)>;
+            typedef std::function<void(const HeaderOptions&, const ResponseStatement&, int)>
+                    SetCallback;
 
-            using ObserveCallback = std::function<
-                    void(const HeaderOptions&, const ResponseStatement&, int, int)>;
+            typedef std::function<void(const HeaderOptions&, const ResponseStatement&, int, int)>
+                    ObserveCallback;
 
         public:
             static PrimitiveResource::Ptr create(const std::shared_ptr<OC::OCResource>&);
 
-            virtual ~PrimitiveResource() = default;
+            virtual ~PrimitiveResource() { };
 
             virtual void requestGet(GetCallback) = 0;
             virtual void requestSet(const ResourceAttributes&, SetCallback) = 0;
@@ -81,7 +81,7 @@ namespace OIC
             PrimitiveResource& operator=(PrimitiveResource&&) = delete;
         };
 
-        using DiscoverCallback = std::function<void(std::shared_ptr<PrimitiveResource>)>;
+        typedef std::function<void(std::shared_ptr<PrimitiveResource>)> DiscoverCallback;
 
         void discoverResource(const std::string& host, const std::string& resourceURI,
                 OCConnectivityType, DiscoverCallback);
index f7afd77..9151cab 100755 (executable)
@@ -62,25 +62,22 @@ namespace OIC
         private:
             template< typename T > struct IsSupportedTypeHelper;
 
-            using ValueVariant = boost::variant<
+            typedef boost::variant<
                 std::nullptr_t,
                 int,
                 double,
                 bool,
                 std::string,
                 ResourceAttributes
-            >;
+            > ValueVariant;
 
-            template< typename T >
-            using mpl_begin = typename boost::mpl::begin<T>::type;
-
-            template< typename T, typename V = void >
-            using enable_if_supported = typename std::enable_if<
-                    IsSupportedTypeHelper< T >::type::value, V >::type;
-
-            template< typename T, typename V = void >
-            using enable_if_unsupported = typename std::enable_if<
-                    !IsSupportedTypeHelper< T >::type::value, V >::type;
+            template< typename T, typename V = void,
+                    typename = typename std::enable_if<
+                        IsSupportedTypeHelper< T >::type::value, V >::type >
+            struct enable_if_supported
+            {
+                typedef V type;
+            };
 
             template< typename VISITOR >
             class KeyValueVisitorHelper: public boost::static_visitor< >
@@ -105,7 +102,8 @@ namespace OIC
 
         public:
             template< typename T >
-            using is_supported_type = typename IsSupportedTypeHelper< T >::type;
+            struct is_supported_type: public std::conditional<
+                IsSupportedTypeHelper< T >::type::value, std::true_type, std::false_type>::type { };
 
             enum class TypeId
             {
@@ -155,7 +153,7 @@ namespace OIC
                 Value(const Value&);
                 Value(Value&&);
 
-                template< typename T, typename = enable_if_supported< T > >
+                template< typename T, typename = typename enable_if_supported< T >::type >
                 Value(T&& value) :
                         m_data{ new ValueVariant{ std::forward< T >(value) } }
                 {
@@ -166,7 +164,7 @@ namespace OIC
                 Value& operator=(const Value&);
                 Value& operator=(Value&&);
 
-                template< typename T, typename = enable_if_supported< T > >
+                template< typename T, typename = typename enable_if_supported< T >::type >
                 Value& operator=(T&& rhs)
                 {
                     *m_data = std::forward< T >(rhs);
@@ -203,7 +201,7 @@ namespace OIC
                 bool operator==(const char*) const;
 
             private:
-                template< typename T, typename = enable_if_supported< T > >
+                template< typename T, typename = typename enable_if_supported< T >::type >
                 typename std::add_lvalue_reference< T >::type checkedGet() const
                 {
                     try
@@ -293,16 +291,16 @@ namespace OIC
         template< typename T >
         struct ResourceAttributes::IsSupportedTypeHelper
         {
-            using type = boost::mpl::contains<ValueVariant::types, typename std::decay< T >::type>;
+            typedef boost::mpl::contains<ValueVariant::types, typename std::decay< T >::type> type;
         };
 
         template <typename T>
         struct ResourceAttributes::IndexOfType
         {
-            using iter = typename boost::mpl::find< ValueVariant::types, T >::type;
+            typedef typename boost::mpl::find< ValueVariant::types, T >::type iter;
+            typedef typename boost::mpl::begin< ValueVariant::types >::type mpl_begin;
 
-            static constexpr int value = boost::mpl::distance< mpl_begin< ValueVariant::types >,
-                    iter >::value;
+            static constexpr int value = boost::mpl::distance< mpl_begin, iter >::value;
         };
 
         bool operator==(const ResourceAttributes::Type&, const ResourceAttributes::Type&);
@@ -386,7 +384,7 @@ namespace OIC
                 ResourceAttributes::KeyValuePair >
         {
         private:
-            using base_iterator = std::unordered_map< std::string, Value >::iterator;
+            typedef std::unordered_map< std::string, Value >::iterator base_iterator;
 
         public:
             iterator();
@@ -417,7 +415,7 @@ namespace OIC
                 const ResourceAttributes::KeyValuePair >
         {
         private:
-            using base_iterator = std::unordered_map< std::string, Value >::const_iterator;
+            typedef std::unordered_map< std::string, Value >::const_iterator base_iterator;
 
         public:
             const_iterator();
index f1df6bd..9e28199 100644 (file)
@@ -41,7 +41,7 @@ namespace OIC
             template <typename FUNC, typename ...PARAMS>
             struct ResultType
             {
-                using type = decltype(std::declval<FUNC>()(std::declval<PARAMS>()...));
+                typedef decltype(std::declval<FUNC>()(std::declval<PARAMS>()...)) type;
             };
 
             template< typename A, typename B, typename ENABLER = void >
@@ -51,14 +51,14 @@ namespace OIC
             struct EnableIfTypeIs< A, OCStackResult,
                     typename std::enable_if< std::is_same< A, OCStackResult >::value >::type >
             {
-                using type = void;
+                typedef void type;
             };
 
             template< typename A >
             struct EnableIfTypeIs< A, NotOCStackResult,
                     typename std::enable_if< !std::is_same< A, OCStackResult >::value >::type >
             {
-                using type = A;
+                typedef A type;
             };
 
 
@@ -66,14 +66,14 @@ namespace OIC
                     std::is_class<T>::value && std::is_pointer<T>::value>::type >
             struct EnableIfClassPointer
             {
-                using type = void;
+                typedef void type;
             };
 
-            template< typename T, typename = typename std::enable_if<std::is_class<T>::value > >
-             struct EnableIfClass
-             {
-                 using type = void;
-             };
+            template< typename T, typename = typename std::enable_if< std::is_class< T >::value > >
+            struct EnableIfClass
+            {
+                typedef void type;
+            };
         }
 
         inline void expectOCStackResult(OCStackResult actual,
index b840639..9ff5f23 100644 (file)
@@ -36,7 +36,7 @@ namespace OIC
         class PrimitiveResourceImpl: public PrimitiveResource
         {
         private:
-            using BaseResourcePtr = std::shared_ptr< BaseResource >;
+            typedef std::shared_ptr< BaseResource > BaseResourcePtr;
 
         private:
             static ResponseStatement createResponseStatement(
@@ -52,11 +52,11 @@ namespace OIC
             {
             }
 
-            void requestGet(GetCallback callback) override
+            void requestGet(GetCallback callback)
             {
                 using namespace std::placeholders;
 
-                using GetFunc = OCStackResult(BaseResource::*)(
+                typedef OCStackResult(BaseResource::*GetFunc)(
                         const OC::QueryParamsMap&, OC::GetCallback);
 
                 invokeOC(m_baseResource, static_cast< GetFunc >(&BaseResource::get),
@@ -64,11 +64,11 @@ namespace OIC
                                 std::bind(createResponseStatement, _2), _3));
             }
 
-            void requestSet(const ResourceAttributes& attrs, SetCallback callback) override
+            void requestSet(const ResourceAttributes& attrs, SetCallback callback)
             {
                 using namespace std::placeholders;
 
-                using PutFunc = OCStackResult(BaseResource::*)(
+                typedef OCStackResult(BaseResource::*PutFunc)(
                         const OC::OCRepresentation&,
                         const OC::QueryParamsMap&, OC::PutCallback);
 
@@ -78,11 +78,11 @@ namespace OIC
                                 std::bind(createResponseStatement, _2), _3));
             }
 
-            void requestObserve(ObserveCallback callback) override
+            void requestObserve(ObserveCallback callback)
             {
                 using namespace std::placeholders;
 
-                using ObserveFunc = OCStackResult (BaseResource::*)(OC::ObserveType,
+                typedef OCStackResult (BaseResource::*ObserveFunc)(OC::ObserveType,
                         const OC::QueryParamsMap&, OC::ObserveCallback);
 
                 invokeOC(m_baseResource, static_cast< ObserveFunc >(&BaseResource::observe),
@@ -90,40 +90,40 @@ namespace OIC
                         bind(std::move(callback), _1, bind(createResponseStatement, _2), _3, _4));
             }
 
-            void cancelObserve() override
+            void cancelObserve()
             {
-                using CancelObserveFunc = OCStackResult (BaseResource::*)();
+                typedef OCStackResult (BaseResource::*CancelObserveFunc)();
 
                 invokeOC(m_baseResource,
                         static_cast< CancelObserveFunc >(&BaseResource::cancelObserve));
             }
 
-            std::string getSid() const override
+            std::string getSid() const
             {
                 return invokeOC(m_baseResource, &BaseResource::sid);
             }
 
-            std::string getUri() const override
+            std::string getUri() const
             {
                 return invokeOC(m_baseResource, &BaseResource::uri);
             }
 
-            std::string getHost() const override
+            std::string getHost() const
             {
                 return invokeOC(m_baseResource, &BaseResource::host);
             }
 
-            std::vector< std::string > getTypes() const override
+            std::vector< std::string > getTypes() const
             {
                 return invokeOC(m_baseResource, &BaseResource::getResourceTypes);
             }
 
-            std::vector< std::string > getInterfaces() const override
+            std::vector< std::string > getInterfaces() const
             {
                 return invokeOC(m_baseResource, &BaseResource::getResourceInterfaces);
             }
 
-            bool isObservable() const override
+            bool isObservable() const
             {
                 return invokeOC(m_baseResource, &BaseResource::isObservable);
             }
index b17fc49..4610730 100644 (file)
@@ -35,14 +35,6 @@ namespace OIC
         private:
             ResourceAttributesConverter() = delete;
 
-            template< typename T >
-            using SupportedType = typename std::enable_if<
-                    ResourceAttributes::is_supported_type< T >::type::value, T >::type;
-
-            template< typename T >
-            using UnsupportedType = typename std::enable_if<
-                    !ResourceAttributes::is_supported_type< T >::type::value, T >::type;
-
             class ResourceAttributesBuilder
             {
             public:
@@ -85,19 +77,15 @@ namespace OIC
 
             private:
                 template< typename T >
-                void putValue(const std::string key, T&& value)
-                {
-                    putValue< T >(key, std::forward< T >(value));
-                }
-
-                template< typename T >
-                void putValue(const std::string key, SupportedType< T > && value)
+                typename std::enable_if<ResourceAttributes::is_supported_type< T >::value >::type
+                putValue(const std::string& key, T && value)
                 {
                     m_target[key] = std::forward< T >(value);
                 }
 
                 template< typename T >
-                void putValue(const std::string key, UnsupportedType< T > && value)
+                typename std::enable_if<!ResourceAttributes::is_supported_type< T >::value >::type
+                putValue(const std::string& key, T && value)
                 {
                 }
 
@@ -136,7 +124,8 @@ namespace OIC
             };
 
         public:
-            static ResourceAttributes fromOCRepresentation(const OC::OCRepresentation& ocRepresentation)
+            static ResourceAttributes fromOCRepresentation(
+                    const OC::OCRepresentation& ocRepresentation)
             {
                 ResourceAttributesBuilder builder;
 
@@ -148,7 +137,8 @@ namespace OIC
                 return builder.extract();
             }
 
-            static OC::OCRepresentation toOCRepresentation(const ResourceAttributes& resourceAttributes)
+            static OC::OCRepresentation toOCRepresentation(
+                    const ResourceAttributes& resourceAttributes)
             {
                 OCRepresentationBuilder builder;
 
index 50f3b2d..defbe96 100644 (file)
@@ -28,8 +28,8 @@ namespace OIC
 {
     namespace Service
     {
-        using AttrKeyValuePair = std::pair< std::string, ResourceAttributes::Value >;
-        using AttrKeyValuePairs = std::vector< AttrKeyValuePair >;
+        typedef std::pair< std::string, ResourceAttributes::Value > AttrKeyValuePair;
+        typedef std::vector< AttrKeyValuePair > AttrKeyValuePairs;
 
         bool acceptableAttributes(const ResourceAttributes& dest, const ResourceAttributes& attr);
 
index a3284e7..ad8b241 100644 (file)
@@ -32,7 +32,7 @@ namespace OIC
         void subscribePresence(OCDoHandle& handle, const std::string& host,
                 OCConnectivityType connectivityType, SubscribeCallback presenceHandler)
         {
-            using SubscribePresence = OCStackResult (*)(OC::OCPlatform::OCPresenceHandle&,
+            typedef OCStackResult (*SubscribePresence)(OC::OCPlatform::OCPresenceHandle&,
                     const std::string&, OCConnectivityType, SubscribeCallback);
 
             invokeOCFunc(static_cast<SubscribePresence>(OC::OCPlatform::subscribePresence),
@@ -43,7 +43,7 @@ namespace OIC
                 const std::string& resourceType, OCConnectivityType connectivityType,
                 SubscribeCallback presenceHandler)
         {
-            using SubscribePresence = OCStackResult (*)(OC::OCPlatform::OCPresenceHandle&,
+            typedef OCStackResult (*SubscribePresence)(OC::OCPlatform::OCPresenceHandle&,
                     const std::string&, const std::string&, OCConnectivityType, SubscribeCallback);
 
             invokeOCFunc(static_cast<SubscribePresence>(OC::OCPlatform::subscribePresence),
index b558fc9..5a58c06 100755 (executable)
@@ -40,7 +40,7 @@ namespace OIC
         void discoverResource(const std::string& host, const std::string& resourceURI,
                 OCConnectivityType connectivityType, DiscoverCallback callback)
         {
-            using FindResource = OCStackResult (*)(const std::string&, const std::string&,
+            typedef OCStackResult (*FindResource)(const std::string&, const std::string&,
                     OCConnectivityType, OC::FindCallback);
 
             invokeOCFunc(static_cast<FindResource>(OC::OCPlatform::findResource),
index 4290eea..6572d15 100755 (executable)
@@ -349,7 +349,8 @@ namespace OIC
 
 
         ResourceAttributes::iterator::iterator() :
-                iterator{ base_iterator{} }
+                m_cur{ base_iterator{ } },
+                m_keyValuePair{ this }
         {
         }
 
@@ -394,7 +395,7 @@ namespace OIC
 
 
         ResourceAttributes::const_iterator::const_iterator() :
-                const_iterator{ base_iterator{} }
+                m_cur{ base_iterator{} }, m_keyValuePair{ this }
         {
         }
 
@@ -547,7 +548,6 @@ namespace OIC
 
             static_assert(ResourceAttributes::is_supported_type< ResourceAttributes >::value,
                     "ResourceAttributes doesn't have ResourceAttributes recursively.");
-
             if (dest.getType().getId() == ResourceAttributes::TypeId::ATTRIBUTES
                     && !acceptableAttributes(dest.get< ResourceAttributes >(),
                             value.get< ResourceAttributes >()))
index 41299af..70e403c 100644 (file)
@@ -43,7 +43,7 @@ namespace OIC
         }
 
         ResponseStatement::ResponseStatement(ResourceAttributes&& attrs) :
-                ResponseStatement{ std::move(attrs), "", { }, { } }
+                m_attrs{ std::move(attrs) }
         {
         }
 
index dd204ce..3329459 100644 (file)
@@ -85,7 +85,7 @@ public:
     MockRepository mocks;
 
 protected:
-    void SetUp() override {
+    void SetUp() {
         mocks.OnCallFuncOverload(
                 static_cast< subscribePresenceSig1 >(OC::OCPlatform::subscribePresence)).Do(
 
index d3dd65b..e178475 100644 (file)
@@ -35,7 +35,7 @@ const std::string KEY{ "key" };
 class FakeOCResource
 {
 public:
-    virtual ~FakeOCResource() = default;
+    virtual ~FakeOCResource() {};
 
     virtual OCStackResult get(const OC::QueryParamsMap&, OC::GetCallback) = 0;
 
@@ -64,15 +64,12 @@ public:
     FakeOCResource* fakeResource;
 
 protected:
-    void SetUp() override {
+    void SetUp() {
         fakeResource = mocks.Mock< FakeOCResource >();
 
         resource.reset(new PrimitiveResourceImpl< FakeOCResource >{
             std::shared_ptr< FakeOCResource >(fakeResource, [](FakeOCResource*) {}) });
     }
-
-    void TearDown() override {
-    }
 };
 
 TEST_F(PrimitiveResourceTest, RequestGetInvokesOCResourceGet)
index 6cdd531..e6a4345 100755 (executable)
 
 #include <string>
 #include <mutex>
-#include <atomic>
 #include <thread>
 
+#include <boost/atomic.hpp>
+
 #include <ResourceAttributes.h>
 #include <PrimitiveResponse.h>
 #include <PrimitiveRequest.h>
@@ -63,8 +64,8 @@ namespace OIC
                 ACCEPTANCE
             };
 
-            using Ptr = std::shared_ptr< ResourceObject >;
-            using ConstPtr = std::shared_ptr< const ResourceObject >;
+            typedef std::shared_ptr< ResourceObject > Ptr;
+            typedef std::shared_ptr< const ResourceObject > ConstPtr;
 
             class Builder
             {
@@ -95,12 +96,12 @@ namespace OIC
 
             class LockGuard;
 
-            using GetRequestHandler = std::function< PrimitiveGetResponse(const PrimitiveRequest&,
-                    ResourceAttributes&) >;
-            using SetRequestHandler = std::function< PrimitiveSetResponse(const PrimitiveRequest&,
-                    ResourceAttributes&) >;
-            using AttributeUpdatedHandler = std::function< void(const ResourceAttributes::Value&,
-                    const ResourceAttributes::Value&) >;
+            typedef std::function< PrimitiveGetResponse(const PrimitiveRequest&,
+                        ResourceAttributes&) > GetRequestHandler;
+            typedef std::function< PrimitiveSetResponse(const PrimitiveRequest&,
+                        ResourceAttributes&) > SetRequestHandler;
+            typedef std::function< void(const ResourceAttributes::Value&,
+                    const ResourceAttributes::Value&) > AttributeUpdatedHandler;
 
         public:
             ResourceObject(ResourceObject&&) = delete;
@@ -181,7 +182,7 @@ namespace OIC
             std::unordered_map< std::string, AttributeUpdatedHandler >
                     m_keyAttributesUpdatedHandlers;
 
-            mutable std::atomic< std::thread::id > m_lockOwner;
+            mutable boost::atomic< std::thread::id > m_lockOwner;
             mutable std::mutex m_mutex;
 
             std::mutex m_mutexKeyAttributeUpdate;
@@ -204,6 +205,9 @@ namespace OIC
             LockGuard& operator=(LockGuard&&) = delete;
 
         private:
+            void init();
+
+        private:
             const ResourceObject& m_resourceObject;
 
             AutoNotifyPolicy m_autoNotifyPolicy;
index d27723a..8bca0db 100644 (file)
@@ -39,11 +39,11 @@ namespace OIC
         class RequestHandler
         {
         private:
-            using BuildResponseHolder = std::function< std::shared_ptr< OC::OCResourceResponse >(
-                    ResourceObject&) >;
+            typedef std::function< std::shared_ptr< OC::OCResourceResponse >(ResourceObject&) >
+                        BuildResponseHolder;
 
         public:
-            using Ptr = std::shared_ptr< RequestHandler >;
+            typedef std::shared_ptr< RequestHandler > Pre;
 
             static constexpr int DEFAULT_ERROR_CODE = 200;
             static constexpr OCEntityHandlerResult DEFAULT_RESULT = OC_EH_OK;
@@ -64,7 +64,7 @@ namespace OIC
                     int errorCode = DEFAULT_ERROR_CODE);
 
 
-            virtual ~RequestHandler() = default;
+            virtual ~RequestHandler() { };
 
             std::shared_ptr< OC::OCResourceResponse > buildResponse(ResourceObject&);
 
@@ -75,7 +75,7 @@ namespace OIC
         class SetRequestHandler: public RequestHandler
         {
         public:
-            using Ptr = std::shared_ptr< SetRequestHandler >;
+            typedef std::shared_ptr< SetRequestHandler > Ptr;
 
             SetRequestHandler(const SetRequestHandler&) = delete;
             SetRequestHandler(SetRequestHandler&&) = default;
index 94eb85f..d608c72 100644 (file)
@@ -133,7 +133,8 @@ namespace OIC
         }
 
         PrimitiveSetResponse::PrimitiveSetResponse(std::shared_ptr< SetRequestHandler >&& handler) :
-                PrimitiveSetResponse{ std::move(handler), AcceptanceMethod::DEFAULT }
+                m_acceptanceMethod { AcceptanceMethod::DEFAULT },
+                m_handler{ std::move(handler) }
         {
         }
 
index e2bc59a..e6b38ad 100755 (executable)
@@ -28,7 +28,7 @@ namespace
 {
     using namespace OIC::Service;
 
-    using OCRepresentationGetter = std::function< OC::OCRepresentation(ResourceObject&) >;
+    typedef std::function< OC::OCRepresentation(ResourceObject&) > OCRepresentationGetter;
 
     OC::OCRepresentation getOCRepresentationFromResource(ResourceObject& resource)
     {
@@ -115,7 +115,8 @@ namespace OIC
         constexpr OCEntityHandlerResult RequestHandler::DEFAULT_RESULT;
 
         RequestHandler::RequestHandler() :
-            RequestHandler { DEFAULT_RESULT, DEFAULT_ERROR_CODE }
+                m_holder{ std::bind(doBuildResponse, std::placeholders::_1, DEFAULT_RESULT,
+                        DEFAULT_ERROR_CODE, getOCRepresentationFromResource) }
         {
         }
 
index 5a3a4c0..60ad8c3 100755 (executable)
@@ -35,8 +35,7 @@ namespace
 {
     using namespace OIC::Service;
 
-    constexpr const char LOG_TAG[]{ "PrimitiveServerResource" };
-
+    constexpr char LOG_TAG[]{ "PrimitiveServerResource" };
 
     inline bool hasProperty(uint8_t base, uint8_t target)
     {
@@ -174,7 +173,7 @@ namespace OIC
 
             try
             {
-                using RegisterResource = OCStackResult (*)(OCResourceHandle&, std::string&,
+                typedef OCStackResult (*RegisterResource)(OCResourceHandle&, std::string&,
                         const std::string&, const std::string&, OC::EntityHandler, uint8_t);
 
                 invokeOCFunc(static_cast<RegisterResource>(OC::OCPlatform::registerResource),
@@ -330,7 +329,7 @@ namespace OIC
 
         void ResourceObject::notify() const
         {
-            using NotifyAllObservers = OCStackResult (*)(OCResourceHandle);
+            typedef OCStackResult (*NotifyAllObservers)(OCResourceHandle);
 
             invokeOCFuncWithResultExpect(
                     { OC_STACK_OK, OC_STACK_NO_OBSERVERS },
@@ -499,20 +498,29 @@ namespace OIC
         }
 
         ResourceObject::LockGuard::LockGuard(const ResourceObject::Ptr ptr) :
-                LockGuard{ *ptr , ptr->getAutoNotifyPolicy() }
+                m_resourceObject(*ptr),
+                m_autoNotifyPolicy{ ptr->getAutoNotifyPolicy() },
+                m_isOwningLock{ false }
         {
+            init();
         }
 
         ResourceObject::LockGuard::LockGuard(
                 const ResourceObject& serverResource) :
-                LockGuard{ serverResource, serverResource.getAutoNotifyPolicy() }
+                m_resourceObject(serverResource),
+                m_autoNotifyPolicy{ serverResource.getAutoNotifyPolicy() },
+                m_isOwningLock{ false }
         {
+            init();
         }
 
         ResourceObject::LockGuard::LockGuard(
                 const ResourceObject::Ptr ptr, AutoNotifyPolicy autoNotifyPolicy) :
-                LockGuard{ *ptr, autoNotifyPolicy}
+                m_resourceObject(*ptr),
+                m_autoNotifyPolicy { autoNotifyPolicy },
+                m_isOwningLock{ false }
         {
+            init();
         }
 
         ResourceObject::LockGuard::LockGuard(
@@ -521,14 +529,7 @@ namespace OIC
                         m_autoNotifyPolicy { autoNotifyPolicy },
                         m_isOwningLock{ false }
         {
-            if (resourceObject.m_lockOwner != std::this_thread::get_id())
-            {
-                m_resourceObject.m_mutex.lock();
-                m_resourceObject.m_lockOwner = std::this_thread::get_id();
-                m_isOwningLock = true;
-            }
-            m_autoNotifyFunc = ::createAutoNotifyInvoker(&ResourceObject::autoNotify,
-                    m_resourceObject, m_resourceObject.m_resourceAttributes, m_autoNotifyPolicy);
+            init();
         }
 
         ResourceObject::LockGuard::~LockGuard()
@@ -542,6 +543,18 @@ namespace OIC
             }
         }
 
+        void ResourceObject::LockGuard::init()
+        {
+            if (m_resourceObject.m_lockOwner != std::this_thread::get_id())
+            {
+                m_resourceObject.m_mutex.lock();
+                m_resourceObject.m_lockOwner = std::this_thread::get_id();
+                m_isOwningLock = true;
+            }
+            m_autoNotifyFunc = ::createAutoNotifyInvoker(&ResourceObject::autoNotify,
+                    m_resourceObject, m_resourceObject.m_resourceAttributes, m_autoNotifyPolicy);
+        }
+
         ResourceObject::WeakGuard::WeakGuard(
                 const ResourceObject& resourceObject) :
                 m_isOwningLock{ false },
index 7a6e433..d51e349 100644 (file)
@@ -72,7 +72,7 @@ public:
     }
 
 protected:
-    void SetUp() override
+    void SetUp()
     {
         mocks.OnCallFuncOverload(static_cast< registerResourceSig >(OCPlatform::registerResource))
                 .Return(OC_STACK_OK);
index 66c214e..1055dbf 100644 (file)
@@ -35,7 +35,7 @@ constexpr int ORIGIN_VALUE{ 100 };
 
 constexpr int NEW_VALUE{ 1 };
 
-using RegisterResource = OCStackResult (*)(OCResourceHandle&, std::string&,
+typedef OCStackResult (*RegisterResource)(OCResourceHandle&, std::string&,
         const std::string&, const std::string&, OC::EntityHandler, uint8_t);
 
 class RequestHandlerTest: public Test
@@ -46,7 +46,7 @@ public:
     MockRepository mocks;
 
 protected:
-    void SetUp() override
+    void SetUp()
     {
         mocks.OnCallFuncOverload(static_cast<RegisterResource>(OC::OCPlatform::registerResource))
                 .Return(OC_STACK_OK);
@@ -103,7 +103,7 @@ public:
     ResourceAttributes requestAttrs;
 
 protected:
-    void SetUp() override
+    void SetUp()
     {
         RequestHandlerTest::SetUp();
 
index daf4441..add5323 100755 (executable)
@@ -33,14 +33,10 @@ using namespace testing;
 using namespace OIC::Service;
 using namespace OC;
 
-using registerResource = OCStackResult (*)(OCResourceHandle&,
-                       string&,
-                       const string&,
-                       const string&,
-                       EntityHandler,
-                       uint8_t );
+typedef OCStackResult (*registerResource)(OCResourceHandle&, string&, const string&, const string&,
+                           EntityHandler, uint8_t );
 
-using NotifyAllObservers = OCStackResult (*)(OCResourceHandle);
+typedef OCStackResult (*NotifyAllObservers)(OCResourceHandle);
 
 constexpr char RESOURCE_URI[]{ "a/test" };
 constexpr char RESOURCE_TYPE[]{ "resourceType" };
@@ -58,7 +54,7 @@ public:
     MockRepository mocks;
 
 protected:
-    void SetUp() override
+    void SetUp()
     {
         mocks.OnCallFuncOverload(static_cast< registerResource >(OCPlatform::registerResource))
                 .Return(OC_STACK_OK);
@@ -102,7 +98,7 @@ public:
     ResourceObject::Ptr server;
 
 protected:
-    void SetUp() override
+    void SetUp()
     {
         initMocks();
 
@@ -154,7 +150,7 @@ TEST_F(ResourceObjectTest, SettingAttributesWithinGuardDoesntCauseDeadLock)
 class AutoNotifyTest: public ResourceObjectTest
 {
 protected:
-    void initMocks() override
+    void initMocks()
     {
         mocks.OnCallFuncOverload(static_cast< NotifyAllObservers >(
                 OCPlatform::notifyAllObservers)).Return(OC_STACK_OK);
@@ -290,7 +286,8 @@ public:
             reinterpret_cast<OCResourceHandle>(0x4321);
 
 public:
-    OCResourceRequest::Ptr createRequest(OCMethod method = OC_REST_GET, OCRepresentation ocRep = {})
+    OCResourceRequest::Ptr createRequest(OCMethod method = OC_REST_GET, OCRepresentation ocRep =
+            OCRepresentation{})
     {
         auto request = make_shared<OCResourceRequest>();
 
@@ -318,7 +315,7 @@ protected:
         return OC_STACK_OK;
     }
 
-    void initMocks() override
+    void initMocks()
     {
         mocks.OnCallFuncOverload(
             static_cast<registerResource>(OCPlatform::registerResource)).Do(
@@ -409,7 +406,7 @@ TEST_F(ResourceObjectHandlingRequestTest, SendSetResponseWithCustomAttrsAndResul
 class SetRequestHandlerPolicyTest: public ResourceObjectHandlingRequestTest
 {
 public:
-    using SendResponse = OCStackResult (*)(std::shared_ptr<OCResourceResponse>);
+    typedef OCStackResult (*SendResponse)(std::shared_ptr<OCResourceResponse>);
 
 public:
     OCRepresentation createOCRepresentation()
@@ -426,7 +423,7 @@ public:
         return ocRep;
     }
 
-    void initMocks() override
+    void initMocks()
     {
         ResourceObjectHandlingRequestTest::initMocks();
         mocks.OnCallFunc(OCPlatform::sendResponse).Return(OC_STACK_OK);