To Enable property value for MQ Publisher/Subscriber
authorjihwan.seo <jihwan.seo@samsung.com>
Mon, 4 Jul 2016 07:06:37 +0000 (16:06 +0900)
committerAshok Babu Channa <ashok.channa@samsung.com>
Wed, 20 Jul 2016 10:26:52 +0000 (10:26 +0000)
client will be awared whether Resource can be supported
as MQ Publisher/Subscriber by Build Option 'WITH_MQ'

Change-Id: Id9d4db5c1d048d3fc9895ded6f0bfbf7bfbd45a8
Signed-off-by: jihwan.seo <jihwan.seo@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/9123
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Jaehong Jo <jaehong.jo@samsung.com>
Reviewed-by: Jee Hyeok Kim <jihyeok13.kim@samsung.com>
Reviewed-by: Ashok Babu Channa <ashok.channa@samsung.com>
build_common/SConscript
resource/csdk/SConscript
resource/csdk/connectivity/SConscript
resource/csdk/stack/include/octypes.h
resource/csdk/stack/src/ocpayload.c
resource/csdk/stack/src/ocstack.c
resource/include/OCResource.h
resource/include/OCSerialization.h
resource/src/OCPlatform_impl.cpp
resource/src/OCResource.cpp

index 1c570e0..3fab911 100644 (file)
@@ -86,6 +86,7 @@ help_vars.Add(EnumVariable('TARGET_OS', 'Target platform', host, host_target_map
 
 help_vars.Add(BoolVariable('WITH_RA', 'Build with Remote Access module', False))
 help_vars.Add(BoolVariable('WITH_TCP', 'Build with TCP adapter', False))
+help_vars.Add(ListVariable('WITH_MQ', 'Build with MQ publisher/broker', 'OFF', ['OFF', 'SUB', 'PUB', 'BROKER']))
 help_vars.Add(EnumVariable('WITH_RD', 'Build including Resource Directory', '0', allowed_values=('0', '1')))
 help_vars.Add(BoolVariable('WITH_CLOUD', 'Build including Cloud client sample', False))
 
index 559eb95..9b31045 100644 (file)
@@ -32,6 +32,7 @@ target_os = env.get('TARGET_OS')
 with_ra = env.get('WITH_RA')
 with_ra_ibb = env.get('WITH_RA_IBB')
 with_tcp = env.get('WITH_TCP')
+with_mq = env.get('WITH_MQ')
 # As in the source code, it includes arduino Time library (C++)
 # It requires compile the .c with g++
 if target_os == 'arduino':
@@ -58,6 +59,13 @@ liboctbstack_env.PrependUnique(CPPPATH = [
                'security/provisioning/include',
                ])
 
+if 'SUB' in with_mq:
+       liboctbstack_env.AppendUnique(CPPDEFINES = ['MQ_SUBSCRIBER', 'WITH_MQ'])
+if 'PUB' in with_mq:
+       liboctbstack_env.AppendUnique(CPPDEFINES = ['MQ_PUBLISHER', 'WITH_MQ'])
+if 'BROKER' in with_mq:
+       liboctbstack_env.AppendUnique(CPPDEFINES = ['MQ_BROKER', 'WITH_MQ'])
+
 if target_os not in ['arduino', 'windows']:
        liboctbstack_env.AppendUnique(CPPDEFINES  = ['WITH_POSIX'])
        liboctbstack_env.AppendUnique(CFLAGS = ['-std=c99'])
index 34b6ac1..42927bf 100644 (file)
@@ -9,10 +9,12 @@ transport = env.get('TARGET_TRANSPORT')
 build_sample = env.get('BUILD_SAMPLE')
 with_ra = env.get('WITH_RA')
 with_tcp = env.get('WITH_TCP')
+with_mq = env.get('WITH_MQ')
 
 print "Given Transport is %s" % transport
 print "Given OS is %s" % target_os
 print "BUILD_SAMPLE is %s" % build_sample
+print "MQ flag is %s" % with_mq
 
 targets_disallow_multitransport = ['arduino']
 
@@ -83,4 +85,16 @@ else:
        else:
                env.AppendUnique(CPPDEFINES = ['NO_NFC_ADAPTER'])
 
+if 'SUB' in with_mq:
+       env.AppendUnique(CPPDEFINES = ['MQ_SUBSCRIBER', 'WITH_MQ'])
+       print "MQ SUB support"
+
+if 'PUB' in with_mq:
+       env.AppendUnique(CPPDEFINES = ['MQ_PUBLISHER', 'WITH_MQ'])
+       print "MQ PUB support"
+
+if 'BROKER' in with_mq:
+       env.AppendUnique(CPPDEFINES = ['MQ_BROKER', 'WITH_MQ'])
+       print "MQ Broker support"
+
 env.SConscript('./src/SConscript')
index 7ea3819..4d45976 100644 (file)
@@ -683,7 +683,17 @@ typedef enum
     /** When this bit is set, the resource is allowed to be discovered only
      *  if discovery request contains an explicit querystring.
      *  Ex: GET /oic/res?rt=oic.sec.acl */
-    OC_EXPLICIT_DISCOVERABLE   = (1 << 5)
+    OC_EXPLICIT_DISCOVERABLE   = (1 << 5),
+
+#ifdef WITH_MQ
+    /** When this bit is set, the resource is allowed to be published */
+    OC_MQ_PUBLISHER     = (1 << 6),
+#endif
+
+#ifdef MQ_BROKER
+    /** When this bit is set, the resource is allowed to be notified as MQ broker.*/
+    OC_MQ_BROKER        = (1 << 7),
+#endif
 } OCResourceProperty;
 
 /**
index 362224b..da1b517 100644 (file)
@@ -1584,7 +1584,11 @@ static OCResourcePayload* OCCopyResource(const OCResource* res, uint16_t secureP
         }
     }
 
-    pl->bitmap = res->resourceProperties & (OC_OBSERVABLE | OC_DISCOVERABLE);
+    pl->bitmap = res->resourceProperties & (OC_OBSERVABLE | OC_DISCOVERABLE
+#ifdef MQ_PUBLISHER
+                                            | OC_MQ_PUBLISHER
+#endif
+                                            );
     pl->secure = (res->resourceProperties & OC_SECURE) != 0;
     pl->port = securePort;
 #ifdef TCP_ADAPTER
index bcd6f44..40bfa0b 100644 (file)
@@ -3227,10 +3227,20 @@ OCStackResult OCCreateResource(OCResourceHandle *handle,
         resourceInterfaceName = OC_RSRVD_INTERFACE_DEFAULT;
     }
 
+#ifdef MQ_PUBLISHER
+    resourceProperties = resourceProperties | OC_MQ_PUBLISHER;
+#endif
     // Make sure resourceProperties bitmask has allowed properties specified
     if (resourceProperties
             > (OC_ACTIVE | OC_DISCOVERABLE | OC_OBSERVABLE | OC_SLOW | OC_SECURE |
-               OC_EXPLICIT_DISCOVERABLE))
+               OC_EXPLICIT_DISCOVERABLE
+#ifdef MQ_PUBLISHER
+               | OC_MQ_PUBLISHER
+#endif
+#ifdef MQ_BROKER
+               | OC_MQ_BROKER
+#endif
+               ))
     {
         OIC_LOG(ERROR, TAG, "Invalid property");
         return OC_STACK_INVALID_PARAM;
index bc0bcdb..536c50a 100644 (file)
@@ -118,7 +118,7 @@ namespace OC
             m_resourceId(std::move(o.m_resourceId)),
             m_devAddr(std::move(o.m_devAddr)),
             m_useHostString(o.m_useHostString),
-            m_isObservable(o.m_isObservable),
+            m_property(o.m_property),
             m_isCollection(o.m_isCollection),
             m_resourceTypes(std::move(o.m_resourceTypes)),
             m_interfaces(std::move(o.m_interfaces)),
@@ -503,6 +503,15 @@ namespace OC
         */
         bool isObservable() const;
 
+#ifdef WITH_MQ
+        /**
+        * Function to provide ability to check if this resource is publisher or not
+        * @return bool true indicates resource is publisher; false indicates resource is
+        *         not publisher.
+        */
+        bool isPublish() const;
+#endif
+
         /**
         * Function to get the list of resource types
         * @return vector of resource types
@@ -555,8 +564,8 @@ namespace OC
         OCResourceIdentifier m_resourceId;
         OCDevAddr m_devAddr;
         bool m_useHostString;
-        bool m_isObservable;
         bool m_isCollection;
+        uint8_t m_property;
         std::vector<std::string> m_resourceTypes;
         std::vector<std::string> m_interfaces;
         std::vector<std::string> m_children;
@@ -566,14 +575,14 @@ namespace OC
     private:
         OCResource(std::weak_ptr<IClientWrapper> clientWrapper,
                     const OCDevAddr& devAddr, const std::string& uri,
-                    const std::string& serverId, bool observable,
+                    const std::string& serverId, uint8_t property,
                     const std::vector<std::string>& resourceTypes,
                     const std::vector<std::string>& interfaces);
 
         OCResource(std::weak_ptr<IClientWrapper> clientWrapper,
                     const std::string& host, const std::string& uri,
                     const std::string& serverId,
-                    OCConnectivityType connectivityType, bool observable,
+                    OCConnectivityType connectivityType, uint8_t property,
                     const std::vector<std::string>& resourceTypes,
                     const std::vector<std::string>& interfaces);
     };
index f037213..24cc059 100644 (file)
@@ -68,7 +68,7 @@ namespace OC
                                         new OC::OCResource(m_clientWrapper, rdPubAddr,
                                             std::string(res->uri),
                                             std::string(payload->sid),
-                                            (res->bitmap & OC_OBSERVABLE) == OC_OBSERVABLE,
+                                            res->bitmap,
                                             StringLLToVector(res->types),
                                             StringLLToVector(res->interfaces)
                                             )));
@@ -79,7 +79,7 @@ namespace OC
                                     new OC::OCResource(m_clientWrapper, m_devAddr,
                                         std::string(res->uri),
                                         std::string(payload->sid),
-                                        (res->bitmap & OC_OBSERVABLE) == OC_OBSERVABLE,
+                                        res->bitmap,
                                         StringLLToVector(res->types),
                                         StringLLToVector(res->interfaces)
                                         )));
@@ -94,7 +94,7 @@ namespace OC
                                             new OC::OCResource(m_clientWrapper, tcpDevAddr,
                                                 std::string(res->uri),
                                                 std::string(payload->sid),
-                                                (res->bitmap & OC_OBSERVABLE) == OC_OBSERVABLE,
+                                                res->bitmap,
                                                 StringLLToVector(res->types),
                                                 StringLLToVector(res->interfaces)
                                                 )));
index 03fa1d9..3862862 100644 (file)
@@ -156,10 +156,15 @@ namespace OC
             return std::shared_ptr<OCResource>();
         }
 
+        uint8_t resourceProperty = 0;
+        if (isObservable)
+        {
+            resourceProperty = (resourceProperty | OC_OBSERVABLE);
+        }
         return std::shared_ptr<OCResource>(new OCResource(m_client,
                                             host,
                                             uri, "", connectivityType,
-                                            isObservable,
+                                            resourceProperty,
                                             resourceTypes,
                                             interfaces));
     }
index c0601eb..43fdeab 100644 (file)
@@ -47,12 +47,12 @@ using OC::checked_guard;
 
 OCResource::OCResource(std::weak_ptr<IClientWrapper> clientWrapper,
                         const OCDevAddr& devAddr, const std::string& uri,
-                        const std::string& serverId, bool observable,
+                        const std::string& serverId, uint8_t property,
                         const std::vector<std::string>& resourceTypes,
                         const std::vector<std::string>& interfaces)
  :  m_clientWrapper(clientWrapper), m_uri(uri),
     m_resourceId(serverId, m_uri), m_devAddr(devAddr),
-    m_isObservable(observable), m_isCollection(false),
+    m_property(property), m_isCollection(false),
     m_resourceTypes(resourceTypes), m_interfaces(interfaces),
     m_observeHandle(nullptr)
 {
@@ -72,12 +72,12 @@ OCResource::OCResource(std::weak_ptr<IClientWrapper> clientWrapper,
 OCResource::OCResource(std::weak_ptr<IClientWrapper> clientWrapper,
                         const std::string& host, const std::string& uri,
                         const std::string& serverId,
-                        OCConnectivityType connectivityType, bool observable,
+                        OCConnectivityType connectivityType, uint8_t property,
                         const std::vector<std::string>& resourceTypes,
                         const std::vector<std::string>& interfaces)
  :  m_clientWrapper(clientWrapper), m_uri(uri),
     m_resourceId(serverId, m_uri),
-    m_isObservable(observable), m_isCollection(false),
+    m_property(property), m_isCollection(false),
     m_resourceTypes(resourceTypes), m_interfaces(interfaces),
     m_observeHandle(nullptr)
 {
@@ -550,9 +550,16 @@ OCConnectivityType OCResource::connectivityType() const
 
 bool OCResource::isObservable() const
 {
-    return m_isObservable;
+    return (m_property & OC_OBSERVABLE) == OC_OBSERVABLE;
 }
 
+#ifdef WITH_MQ
+bool OCResource::isPublish() const
+{
+    return (m_property & OC_MQ_PUBLISHER) == OC_MQ_PUBLISHER;
+}
+#endif
+
 std::vector<std::string> OCResource::getResourceTypes() const
 {
     return m_resourceTypes;