Update a logic to handle response code and connectivity type in constructResourceObject
authorJihun Ha <jihun.ha@samsung.com>
Thu, 18 Aug 2016 05:33:48 +0000 (14:33 +0900)
committerUze Choi <uzchoi@samsung.com>
Thu, 18 Aug 2016 12:59:23 +0000 (12:59 +0000)
OC_STACK_RESOURCE_CHANGED is also dealt as a success response code.
And (CT_ADAPTER_IP | CT_IP_USE_V4) or  (CT_ADAPTER_IP | CT_IP_USE_V6)
should be used in constructResourceObject function.
And the access mode of files has been changed to 644

Change-Id: Iadbffd045f6baab87aa42dc88f5221abc9940b20
Signed-off-by: Jihun Ha <jihun.ha@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/10333
Reviewed-by: Uze Choi <uzchoi@samsung.com>
Tested-by: Uze Choi <uzchoi@samsung.com>
service/scene-manager/src/RemoteSceneCollection.cpp
service/scene-manager/src/Scene.cpp [changed mode: 0755->0644]
service/scene-manager/src/SceneAction.cpp [changed mode: 0755->0644]
service/scene-manager/src/SceneCollection.cpp [changed mode: 0755->0644]
service/scene-manager/src/SceneCollectionResource.cpp [changed mode: 0755->0644]
service/scene-manager/src/SceneCollectionResourceRequestor.cpp
service/scene-manager/src/SceneCommons.h [changed mode: 0644->0755]
service/scene-manager/src/SceneList.cpp [changed mode: 0755->0644]
service/scene-manager/src/SceneListResourceRequestor.cpp
service/scene-manager/src/SceneMemberResourceRequestor.cpp
service/scene-manager/src/SceneUtils.cpp [changed mode: 0644->0755]

old mode 100755 (executable)
new mode 100644 (file)
old mode 100755 (executable)
new mode 100644 (file)
old mode 100755 (executable)
new mode 100644 (file)
old mode 100755 (executable)
new mode 100644 (file)
index 6467ec9..7409e79
@@ -345,9 +345,9 @@ namespace OIC
             auto requestKey = attributes.at(SCENE_KEY_LAST_SCENE).get<std::string>();
 
             RCSRequest req(request.getResourceObject().lock(), request.getOCRequest());
-  
+
             ptr->execute(std::string(requestKey),
-                    [req](int /*eCode*/) 
+                    [req](int /*eCode*/)
                     {
                         // TODO need to set error code.
                         // and need to set specific attr' but this attr not to be apply to RCSResourceObject.
index f36d3bc..ed06621 100644 (file)
@@ -39,7 +39,7 @@ namespace OIC
         {
             RCSResourceAttributes attributesToSet;
             std::vector< std::string > scenenames{ name };
-            
+
             attributesToSet[SCENE_KEY_SCENEVALUES] = scenenames;
 
             RCSRemoteResourceObject::RemoteAttributesSetCallback setRequestCB
@@ -144,7 +144,7 @@ namespace OIC
             m_sceneCollectionResource->get(params, cb);
         }
 
-        RCSRemoteResourceObject::Ptr 
+        RCSRemoteResourceObject::Ptr
             SceneCollectionResourceRequestor::getRemoteResourceObject() const
         {
             return m_sceneCollectionResource;
@@ -167,7 +167,7 @@ namespace OIC
                     std::make_shared< SceneMemberResourceRequestor >(pResource, id);
 
                 pMemRequestor->setRemoteResourceObject(target);
-                
+
                 {
                     std::lock_guard< std::mutex > memberlock(m_memberRequestorLock);
                     m_memberRequestors[target->getAddress() + target->getUri()] = pMemRequestor;
@@ -212,8 +212,7 @@ namespace OIC
         {
             // TODO error code
             int resultCode = SCENE_CLIENT_BADREQUEST;
-
-            if (eCode == OC_STACK_OK)
+            if (eCode == OC_STACK_OK || eCode == OC_STACK_RESOURCE_CHANGED)
             {
                 try
                 {
@@ -281,7 +280,7 @@ namespace OIC
             int result = SCENE_CLIENT_BADREQUEST;
             SceneMemberResourceRequestor::Ptr memRequestor = nullptr;
 
-            if (eCode == OC_STACK_OK)
+            if (eCode == OC_STACK_OK || eCode == OC_STACK_RESOURCE_CHANGED)
             {
                 try
                 {
@@ -325,7 +324,7 @@ namespace OIC
             const InternalSetNameCallback &internalCB)
         {
             int result = SCENE_CLIENT_BADREQUEST;
-            if (eCode == OC_STACK_OK)
+            if (eCode == OC_STACK_OK || eCode == OC_STACK_RESOURCE_CHANGED)
             {
                 if (rep.getAttributes().at(SCENE_KEY_NAME).get< std::string >() == name)
                 {
old mode 100644 (file)
new mode 100755 (executable)
old mode 100755 (executable)
new mode 100644 (file)
index 2776afa..963b50b 100644 (file)
@@ -103,7 +103,7 @@ namespace OIC
             int result = SCENE_CLIENT_BADREQUEST;
             std::string link, id;
 
-            if (eCode == OC_STACK_OK)
+            if (eCode == OC_STACK_OK || eCode == OC_STACK_RESOURCE_CHANGED)
             {
                 try
                 {
@@ -143,13 +143,13 @@ namespace OIC
             const InternalSetNameCallback &internalCB)
         {
             int result = SCENE_CLIENT_BADREQUEST;
-            if (eCode == OC_STACK_OK)
+
+            if (eCode == OC_STACK_OK || eCode == OC_STACK_RESOURCE_CHANGED)
             {
                 if (rep.getAttributes().at(SCENE_KEY_NAME).get< std::string >() == name)
                 {
                     result = SCENE_RESPONSE_SUCCESS;
                 }
-
             }
 
             internalCB(result);
index 3f43719..b4170a2 100644 (file)
@@ -104,7 +104,7 @@ namespace OIC
             // TODO error code
             int result = SCENE_CLIENT_BADREQUEST;
 
-            if (eCode == OC_STACK_OK)
+            if (eCode == OC_STACK_OK || eCode == OC_STACK_RESOURCE_CHANGED)
             {
                 try
                 {
old mode 100644 (file)
new mode 100755 (executable)
index 5ef7aeb..b99eaf8
@@ -74,34 +74,43 @@ namespace OIC
 
         std::string SceneUtils::getNetAddress()
         {
-            CAEndpoint_t ** netInfo = (CAEndpoint_t **)OICMalloc(sizeof(CAEndpoint_t*)*5);
-
-            if(netInfo == nullptr)
-            {
-                throw RCSException("memory allocation fail");
-            }
-
+            CAEndpoint_t * netInfo = nullptr;
             uint32_t size = 0;
-            CAGetNetworkInformation(netInfo, &size);
+            CAGetNetworkInformation(&netInfo, &size);
 
             if (size == 0)
             {
                 OICFree(netInfo);
                 throw RCSException("Disabled Network");
             }
+            std::string address_ipv4 = "", address_ipv6 = "";
 
             for (uint32_t i = 0; i < size; ++i)
             {
-                if (netInfo[i]->adapter == CATransportAdapter_t::CA_ADAPTER_IP)
+                if (netInfo[i].adapter == CATransportAdapter_t::CA_ADAPTER_IP)
                 {
-                    std::string retAddress
-                        = std::string(netInfo[i]->addr) + ":" + std::to_string(netInfo[i]->port);
-
-                    OICFree(netInfo);
-                    return retAddress;
+                    if(netInfo[i].flags == CATransportFlags_t::CA_IPV4)
+                    {
+                        address_ipv4 = std::string(netInfo[i].addr) + ":"
+                                            + std::to_string(netInfo[i].port);
+                    } else if(netInfo[i].flags == CATransportFlags_t::CA_IPV6)
+                    {
+                        address_ipv6 = "[" + std::string(netInfo[i].addr) + "]:"
+                                            + std::to_string(netInfo[i].port);
+                    }
                 }
             }
 
+            if(address_ipv4.length() > 0 && address_ipv6.length() == 0)
+            {
+                OICFree(netInfo);
+                return address_ipv4;
+            } else if(address_ipv6.length() > 0)
+            {
+                OICFree(netInfo);
+                return address_ipv6;
+            }
+
             OICFree(netInfo);
             throw RCSException("Not supported Network");
         }
@@ -115,9 +124,29 @@ namespace OIC
                 std::string hostaddress, uri;
                 SceneUtils::getHostUriString(address, &hostaddress, &uri);
 
-                OC::OCResource::Ptr pOCResource =
-                    OC::OCPlatform::constructResourceObject(
-                        hostaddress, uri, ct, false, vecRT, vecIF);
+                OC::OCResource::Ptr pOCResource = nullptr;
+
+                if(hostaddress.find("[") != std::string::npos &&
+                            hostaddress.find("]") != std::string::npos)
+                {
+                    pOCResource = OC::OCPlatform::constructResourceObject(
+                                     hostaddress,
+                                     uri,
+                                     (OCConnectivityType)(ct | CT_IP_USE_V6),
+                                     false,
+                                     vecRT,
+                                     vecIF);
+                }
+                else
+                {
+                    pOCResource = OC::OCPlatform::constructResourceObject(
+                                     hostaddress,
+                                     uri,
+                                     (OCConnectivityType)(ct | CT_IP_USE_V4),
+                                     false,
+                                     vecRT,
+                                     vecIF);
+                }
 
                 return RCSRemoteResourceObject::fromOCResource(pOCResource);
             }