Initial merge-commit of the OIC code. Should successfully do discovery for single...
[platform/upstream/iotivity.git] / OCLib / OCResource.cpp
1 //******************************************************************
2 //
3 // Copyright 2014 Intel Corporation All Rights Reserved.
4 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
5
6 #include "OCResource.h"
7 #include "OCReflect.h"
8
9 namespace OC {
10         OCResource::OCResource(std::string host, boost::property_tree::ptree& resourceNode) : m_isCollection(false)
11         {
12                 m_host = host;
13                 m_uri = resourceNode.get<std::string>("href","");
14                 m_isObservable = resourceNode.get<int>("obs",0)==1;
15                 
16                 boost::property_tree::ptree resourceTypes = resourceNode.get_child("rt", boost::property_tree::ptree());
17                 for(auto itr : resourceTypes)
18                 {
19                         m_resourceTypes.push_back(itr.second.data());
20                 }
21                 
22                 boost::property_tree::ptree interfaces = resourceNode.get_child("if", boost::property_tree::ptree());
23                 for(auto itr : interfaces)
24                 {
25                         if(itr.second.data() == "oc.mi.ll")
26                         {
27                                 m_isCollection = true;
28                         }
29                 
30                         m_interfaces.push_back(itr.second.data());
31                 }
32                 
33                 // TODO: If collection, load children, assuming this becomes a thing
34                 
35                 // TODO: Load attributes, assuming this becomes a 'thing'
36                 
37                 if (m_uri.empty() || resourceTypes.empty() || interfaces.empty())
38                 {
39                         throw ResourceInitException(m_uri.empty(), resourceTypes.empty(), interfaces.empty());
40                 }
41         }
42         
43         OCResource::~OCResource()
44         {
45         }
46 } // namespace OC