From 6ad11133a66eadead1877ce1758e93482b28081c Mon Sep 17 00:00:00 2001 From: coderhyme Date: Thu, 16 Jul 2015 15:25:41 +0900 Subject: [PATCH] Fix primitiveResource and serverBuilder to remove incompatibles for GCC4.6 Change some codes using C++11 features which is not supported on GCC4.6. Change-Id: I864321abdfaee960277ebfcab5fa09c33757453e Signed-off-by: coderhyme Reviewed-on: https://gerrit.iotivity.org/gerrit/1688 Reviewed-by: Uze Choi Tested-by: Uze Choi --- .../src/common/expiryTimer/SConscript | 2 +- .../primitiveResource/include/PrimitiveException.h | 4 +- .../primitiveResource/include/PrimitiveResource.h | 22 +++++------ .../primitiveResource/include/ResourceAttributes.h | 42 ++++++++++----------- .../include/internal/AssertUtils.h | 18 ++++----- .../include/internal/PrimitiveResourceImpl.h | 30 +++++++-------- .../include/internal/ResourceAttributesConverter.h | 26 ++++--------- .../include/internal/ResourceAttributesUtils.h | 4 +- .../primitiveResource/src/PresenceSubscriber.cpp | 4 +- .../primitiveResource/src/PrimitiveResource.cpp | 2 +- .../primitiveResource/src/ResourceAttributes.cpp | 6 +-- .../primitiveResource/src/ResponseStatement.cpp | 2 +- .../unittests/PresenceSubscriberTest.cpp | 2 +- .../unittests/PrimitiveResourceTest.cpp | 7 +--- .../unittests/ResourceAttributesTest.cpp | 2 +- .../src/serverBuilder/include/ResourceObject.h | 24 +++++++----- .../include/internal/RequestHandler.h | 10 ++--- .../src/serverBuilder/src/PrimitiveResponse.cpp | 3 +- .../src/serverBuilder/src/RequestHandler.cpp | 5 ++- .../src/serverBuilder/src/ResourceObject.cpp | 43 ++++++++++++++-------- .../unittests/PrimitiveResponseTest.cpp | 2 +- .../serverBuilder/unittests/RequestHandlerTest.cpp | 6 +-- .../serverBuilder/unittests/ResourceObjectTest.cpp | 25 ++++++------- 23 files changed, 147 insertions(+), 144 deletions(-) diff --git a/service/resource-manipulation/src/common/expiryTimer/SConscript b/service/resource-manipulation/src/common/expiryTimer/SConscript index 0fd1747..de1a13b 100644 --- a/service/resource-manipulation/src/common/expiryTimer/SConscript +++ b/service/resource-manipulation/src/common/expiryTimer/SConscript @@ -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']) diff --git a/service/resource-manipulation/src/common/primitiveResource/include/PrimitiveException.h b/service/resource-manipulation/src/common/primitiveResource/include/PrimitiveException.h index c623eb1..967008d 100755 --- a/service/resource-manipulation/src/common/primitiveResource/include/PrimitiveException.h +++ b/service/resource-manipulation/src/common/primitiveResource/include/PrimitiveException.h @@ -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(); } diff --git a/service/resource-manipulation/src/common/primitiveResource/include/PrimitiveResource.h b/service/resource-manipulation/src/common/primitiveResource/include/PrimitiveResource.h index 9dde868..69aed42 100755 --- a/service/resource-manipulation/src/common/primitiveResource/include/PrimitiveResource.h +++ b/service/resource-manipulation/src/common/primitiveResource/include/PrimitiveResource.h @@ -33,8 +33,8 @@ namespace OIC namespace Service { - using HeaderOption = OC::HeaderOption::OCHeaderOption; - using HeaderOptions = std::vector; + typedef OC::HeaderOption::OCHeaderOption HeaderOption; + typedef std::vector HeaderOptions; class ResourceAttributes; class ResponseStatement; @@ -42,21 +42,21 @@ namespace OIC class PrimitiveResource { public: - using Ptr = std::shared_ptr; + typedef std::shared_ptr Ptr; - using GetCallback = std::function< - void(const HeaderOptions&, const ResponseStatement&, int)>; + typedef std::function + GetCallback; - using SetCallback = std::function< - void(const HeaderOptions&, const ResponseStatement&, int)>; + typedef std::function + SetCallback; - using ObserveCallback = std::function< - void(const HeaderOptions&, const ResponseStatement&, int, int)>; + typedef std::function + ObserveCallback; public: static PrimitiveResource::Ptr create(const std::shared_ptr&); - 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)>; + typedef std::function)> DiscoverCallback; void discoverResource(const std::string& host, const std::string& resourceURI, OCConnectivityType, DiscoverCallback); diff --git a/service/resource-manipulation/src/common/primitiveResource/include/ResourceAttributes.h b/service/resource-manipulation/src/common/primitiveResource/include/ResourceAttributes.h index f7afd77..9151cab 100755 --- a/service/resource-manipulation/src/common/primitiveResource/include/ResourceAttributes.h +++ b/service/resource-manipulation/src/common/primitiveResource/include/ResourceAttributes.h @@ -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::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::type>; + typedef boost::mpl::contains::type> type; }; template 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(); diff --git a/service/resource-manipulation/src/common/primitiveResource/include/internal/AssertUtils.h b/service/resource-manipulation/src/common/primitiveResource/include/internal/AssertUtils.h index f1df6bd..9e28199 100644 --- a/service/resource-manipulation/src/common/primitiveResource/include/internal/AssertUtils.h +++ b/service/resource-manipulation/src/common/primitiveResource/include/internal/AssertUtils.h @@ -41,7 +41,7 @@ namespace OIC template struct ResultType { - using type = decltype(std::declval()(std::declval()...)); + typedef decltype(std::declval()(std::declval()...)) 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::value && std::is_pointer::value>::type > struct EnableIfClassPointer { - using type = void; + typedef void type; }; - template< typename T, typename = typename std::enable_if::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, diff --git a/service/resource-manipulation/src/common/primitiveResource/include/internal/PrimitiveResourceImpl.h b/service/resource-manipulation/src/common/primitiveResource/include/internal/PrimitiveResourceImpl.h index b840639..9ff5f23 100644 --- a/service/resource-manipulation/src/common/primitiveResource/include/internal/PrimitiveResourceImpl.h +++ b/service/resource-manipulation/src/common/primitiveResource/include/internal/PrimitiveResourceImpl.h @@ -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); } diff --git a/service/resource-manipulation/src/common/primitiveResource/include/internal/ResourceAttributesConverter.h b/service/resource-manipulation/src/common/primitiveResource/include/internal/ResourceAttributesConverter.h index b17fc49..4610730 100644 --- a/service/resource-manipulation/src/common/primitiveResource/include/internal/ResourceAttributesConverter.h +++ b/service/resource-manipulation/src/common/primitiveResource/include/internal/ResourceAttributesConverter.h @@ -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::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::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; diff --git a/service/resource-manipulation/src/common/primitiveResource/include/internal/ResourceAttributesUtils.h b/service/resource-manipulation/src/common/primitiveResource/include/internal/ResourceAttributesUtils.h index 50f3b2d..defbe96 100644 --- a/service/resource-manipulation/src/common/primitiveResource/include/internal/ResourceAttributesUtils.h +++ b/service/resource-manipulation/src/common/primitiveResource/include/internal/ResourceAttributesUtils.h @@ -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); diff --git a/service/resource-manipulation/src/common/primitiveResource/src/PresenceSubscriber.cpp b/service/resource-manipulation/src/common/primitiveResource/src/PresenceSubscriber.cpp index a3284e7..ad8b241 100644 --- a/service/resource-manipulation/src/common/primitiveResource/src/PresenceSubscriber.cpp +++ b/service/resource-manipulation/src/common/primitiveResource/src/PresenceSubscriber.cpp @@ -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(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(OC::OCPlatform::subscribePresence), diff --git a/service/resource-manipulation/src/common/primitiveResource/src/PrimitiveResource.cpp b/service/resource-manipulation/src/common/primitiveResource/src/PrimitiveResource.cpp index b558fc9..5a58c06 100755 --- a/service/resource-manipulation/src/common/primitiveResource/src/PrimitiveResource.cpp +++ b/service/resource-manipulation/src/common/primitiveResource/src/PrimitiveResource.cpp @@ -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(OC::OCPlatform::findResource), diff --git a/service/resource-manipulation/src/common/primitiveResource/src/ResourceAttributes.cpp b/service/resource-manipulation/src/common/primitiveResource/src/ResourceAttributes.cpp index 4290eea..6572d15 100755 --- a/service/resource-manipulation/src/common/primitiveResource/src/ResourceAttributes.cpp +++ b/service/resource-manipulation/src/common/primitiveResource/src/ResourceAttributes.cpp @@ -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 >())) diff --git a/service/resource-manipulation/src/common/primitiveResource/src/ResponseStatement.cpp b/service/resource-manipulation/src/common/primitiveResource/src/ResponseStatement.cpp index 41299af..70e403c 100644 --- a/service/resource-manipulation/src/common/primitiveResource/src/ResponseStatement.cpp +++ b/service/resource-manipulation/src/common/primitiveResource/src/ResponseStatement.cpp @@ -43,7 +43,7 @@ namespace OIC } ResponseStatement::ResponseStatement(ResourceAttributes&& attrs) : - ResponseStatement{ std::move(attrs), "", { }, { } } + m_attrs{ std::move(attrs) } { } diff --git a/service/resource-manipulation/src/common/primitiveResource/unittests/PresenceSubscriberTest.cpp b/service/resource-manipulation/src/common/primitiveResource/unittests/PresenceSubscriberTest.cpp index dd204ce..3329459 100644 --- a/service/resource-manipulation/src/common/primitiveResource/unittests/PresenceSubscriberTest.cpp +++ b/service/resource-manipulation/src/common/primitiveResource/unittests/PresenceSubscriberTest.cpp @@ -85,7 +85,7 @@ public: MockRepository mocks; protected: - void SetUp() override { + void SetUp() { mocks.OnCallFuncOverload( static_cast< subscribePresenceSig1 >(OC::OCPlatform::subscribePresence)).Do( diff --git a/service/resource-manipulation/src/common/primitiveResource/unittests/PrimitiveResourceTest.cpp b/service/resource-manipulation/src/common/primitiveResource/unittests/PrimitiveResourceTest.cpp index d3dd65b..e178475 100644 --- a/service/resource-manipulation/src/common/primitiveResource/unittests/PrimitiveResourceTest.cpp +++ b/service/resource-manipulation/src/common/primitiveResource/unittests/PrimitiveResourceTest.cpp @@ -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) diff --git a/service/resource-manipulation/src/common/primitiveResource/unittests/ResourceAttributesTest.cpp b/service/resource-manipulation/src/common/primitiveResource/unittests/ResourceAttributesTest.cpp index b8f593c..fd81835 100644 --- a/service/resource-manipulation/src/common/primitiveResource/unittests/ResourceAttributesTest.cpp +++ b/service/resource-manipulation/src/common/primitiveResource/unittests/ResourceAttributesTest.cpp @@ -366,7 +366,7 @@ public: ResourceAttributes resourceAttributes; protected: - void SetUp() override + void SetUp() { resourceAttributes[KEY] = 1; } diff --git a/service/resource-manipulation/src/serverBuilder/include/ResourceObject.h b/service/resource-manipulation/src/serverBuilder/include/ResourceObject.h index 6cdd531..e6a4345 100755 --- a/service/resource-manipulation/src/serverBuilder/include/ResourceObject.h +++ b/service/resource-manipulation/src/serverBuilder/include/ResourceObject.h @@ -23,9 +23,10 @@ #include #include -#include #include +#include + #include #include #include @@ -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; diff --git a/service/resource-manipulation/src/serverBuilder/include/internal/RequestHandler.h b/service/resource-manipulation/src/serverBuilder/include/internal/RequestHandler.h index d27723a..8bca0db 100644 --- a/service/resource-manipulation/src/serverBuilder/include/internal/RequestHandler.h +++ b/service/resource-manipulation/src/serverBuilder/include/internal/RequestHandler.h @@ -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; diff --git a/service/resource-manipulation/src/serverBuilder/src/PrimitiveResponse.cpp b/service/resource-manipulation/src/serverBuilder/src/PrimitiveResponse.cpp index 94eb85f..d608c72 100644 --- a/service/resource-manipulation/src/serverBuilder/src/PrimitiveResponse.cpp +++ b/service/resource-manipulation/src/serverBuilder/src/PrimitiveResponse.cpp @@ -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) } { } diff --git a/service/resource-manipulation/src/serverBuilder/src/RequestHandler.cpp b/service/resource-manipulation/src/serverBuilder/src/RequestHandler.cpp index e2bc59a..e6b38ad 100755 --- a/service/resource-manipulation/src/serverBuilder/src/RequestHandler.cpp +++ b/service/resource-manipulation/src/serverBuilder/src/RequestHandler.cpp @@ -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) } { } diff --git a/service/resource-manipulation/src/serverBuilder/src/ResourceObject.cpp b/service/resource-manipulation/src/serverBuilder/src/ResourceObject.cpp index 5a3a4c0..60ad8c3 100755 --- a/service/resource-manipulation/src/serverBuilder/src/ResourceObject.cpp +++ b/service/resource-manipulation/src/serverBuilder/src/ResourceObject.cpp @@ -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(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 }, diff --git a/service/resource-manipulation/src/serverBuilder/unittests/PrimitiveResponseTest.cpp b/service/resource-manipulation/src/serverBuilder/unittests/PrimitiveResponseTest.cpp index 7a6e433..d51e349 100644 --- a/service/resource-manipulation/src/serverBuilder/unittests/PrimitiveResponseTest.cpp +++ b/service/resource-manipulation/src/serverBuilder/unittests/PrimitiveResponseTest.cpp @@ -72,7 +72,7 @@ public: } protected: - void SetUp() override + void SetUp() { mocks.OnCallFuncOverload(static_cast< registerResourceSig >(OCPlatform::registerResource)) .Return(OC_STACK_OK); diff --git a/service/resource-manipulation/src/serverBuilder/unittests/RequestHandlerTest.cpp b/service/resource-manipulation/src/serverBuilder/unittests/RequestHandlerTest.cpp index 66c214e..1055dbf 100644 --- a/service/resource-manipulation/src/serverBuilder/unittests/RequestHandlerTest.cpp +++ b/service/resource-manipulation/src/serverBuilder/unittests/RequestHandlerTest.cpp @@ -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(OC::OCPlatform::registerResource)) .Return(OC_STACK_OK); @@ -103,7 +103,7 @@ public: ResourceAttributes requestAttrs; protected: - void SetUp() override + void SetUp() { RequestHandlerTest::SetUp(); diff --git a/service/resource-manipulation/src/serverBuilder/unittests/ResourceObjectTest.cpp b/service/resource-manipulation/src/serverBuilder/unittests/ResourceObjectTest.cpp index daf4441..add5323 100755 --- a/service/resource-manipulation/src/serverBuilder/unittests/ResourceObjectTest.cpp +++ b/service/resource-manipulation/src/serverBuilder/unittests/ResourceObjectTest.cpp @@ -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(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(); @@ -318,7 +315,7 @@ protected: return OC_STACK_OK; } - void initMocks() override + void initMocks() { mocks.OnCallFuncOverload( static_cast(OCPlatform::registerResource)).Do( @@ -409,7 +406,7 @@ TEST_F(ResourceObjectHandlingRequestTest, SendSetResponseWithCustomAttrsAndResul class SetRequestHandlerPolicyTest: public ResourceObjectHandlingRequestTest { public: - using SendResponse = OCStackResult (*)(std::shared_ptr); + typedef OCStackResult (*SendResponse)(std::shared_ptr); 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); -- 2.7.4