OCPlatform Object Removal
authorErich Keane <erich.keane@intel.com>
Sat, 25 Oct 2014 00:15:13 +0000 (17:15 -0700)
committerErich Keane <erich.keane@intel.com>
Fri, 31 Oct 2014 18:02:00 +0000 (11:02 -0700)
Removed dependency on the OCPlatform object.  We turned it into an internal-singleton(renamed to OCPlatform_impl so that we can use OCPlatform for the namespace, making it more consistent with previous code) with the expectation that people are to use OC::OCPlatform::<functionname> to control the API.
Change-Id: I3f0e13a27021f7454da68add93aaf562506e08ec

37 files changed:
examples/fridgeclient.cpp
examples/fridgeserver.cpp
examples/garageclient.cpp
examples/garageserver.cpp
examples/ocicuc/client.cpp
examples/ocicuc/demo_client.hpp
examples/ocicuc/light_resource.cpp
examples/ocicuc/light_resource.hpp
examples/ocicuc/monoprocess.cpp
examples/ocicuc/server.cpp
examples/presenceclient.cpp
examples/presenceserver.cpp
examples/roomclient.cpp
examples/roomserver.cpp
examples/simpleclient.cpp
examples/simpleclientHQ.cpp
examples/simpleclientserver.cpp
examples/simpleserver.cpp
examples/simpleserverHQ.cpp
include/IClientWrapper.h
include/IServerWrapper.h
include/InProcClientWrapper.h
include/InProcServerWrapper.h
include/OCApi.h
include/OCPlatform.h
include/OCPlatformHandler.h [deleted file]
include/OCPlatform_impl.h [new file with mode: 0644]
include/OCResource.h
include/OutOfProcClientWrapper.h
include/OutOfProcServerWrapper.h
include/WrapperFactory.h
makefile
src/InProcClientWrapper.cpp
src/InProcServerWrapper.cpp
src/OCPlatform.cpp
src/OCPlatform_impl.cpp [new file with mode: 0644]
unittests/tests.cpp

index fe9315b..bb8d10f 100644 (file)
@@ -40,12 +40,12 @@ const uint16_t TOKEN = 3000;
 class ClientFridge
 {
     public:
-    ClientFridge(PlatformConfig &cfg) : m_platform(cfg)
+    ClientFridge()
     {
         std::cout << "Fridge Client has started " <<std::endl;
         FindCallback f (std::bind(&ClientFridge::foundDevice, this, PH::_1));
 
-        OCStackResult result = m_platform.findResource(
+        OCStackResult result = OCPlatform::findResource(
                 "", "coap://224.0.1.187/oc/core?rt=intel.fridge", f);
 
         if(OC_STACK_OK != result)
@@ -66,6 +66,7 @@ class ClientFridge
     private:
     void foundDevice(std::shared_ptr<OCResource> resource)
     {
+        using namespace OC::OCPlatform;
         if(resource && resource->uri() == "/device")
         {
             std::cout << "Discovered a device object"<<std::endl;
@@ -78,16 +79,16 @@ class ClientFridge
         // server, and query them.
         std::vector<std::string> lightTypes = {"intel.fridge.light"};
         std::vector<std::string> ifaces = {DEFAULT_INTERFACE};
-        OCResource::Ptr light = m_platform.constructResourceObject(resource->host(),
+        OCResource::Ptr light = constructResourceObject(resource->host(),
                                 "/light", false, lightTypes, ifaces);
 
         std::vector<std::string> doorTypes = {"intel.fridge.door"};
 
-        OCResource::Ptr leftdoor = m_platform.constructResourceObject(resource->host(),
+        OCResource::Ptr leftdoor = constructResourceObject(resource->host(),
                                 "/door/left", false, doorTypes, ifaces);
-        OCResource::Ptr rightdoor = m_platform.constructResourceObject(resource->host(),
+        OCResource::Ptr rightdoor = constructResourceObject(resource->host(),
                                 "/door/right", false, doorTypes, ifaces);
-        OCResource::Ptr randomdoor = m_platform.constructResourceObject(resource->host(),
+        OCResource::Ptr randomdoor = constructResourceObject(resource->host(),
                                 "/door/random", false, doorTypes, ifaces);
 
         // Set header options with API version and token
@@ -211,7 +212,6 @@ class ClientFridge
         }
     }
 
-    OCPlatform m_platform;
     std::mutex m_mutex;
     std::condition_variable m_cv;
 };
@@ -227,6 +227,7 @@ int main()
         QualityOfService::LowQos
     };
 
-    ClientFridge cf (cfg);
+    OCPlatform::Configure(cfg);
+    ClientFridge cf ();
     return 0;
 }
index 9052dd9..eb8ec6c 100644 (file)
@@ -57,9 +57,8 @@ class Resource
 class DeviceResource : public Resource
 {
     public:
-    OCPlatform& m_platform;
 
-    DeviceResource(OCPlatform& platform): m_platform(platform)
+    DeviceResource()
     {
         std::string resourceURI = "/device";
         std::string resourceTypeName = "intel.fridge";
@@ -70,10 +69,10 @@ class DeviceResource : public Resource
                                                                          PH::_1, PH::_2);
 
         std::cout << "Setting device default entity handler\n";
-        m_platform.setDefaultDeviceEntityHandler(defaultEH);
+        OCPlatform::setDefaultDeviceEntityHandler(defaultEH);
 
         uint8_t resourceProperty = OC_DISCOVERABLE;
-        OCStackResult result = m_platform.registerResource(m_resourceHandle,
+        OCStackResult result = OCPlatform::registerResource(m_resourceHandle,
             resourceURI,
             resourceTypeName,
             resourceInterface,
@@ -95,7 +94,7 @@ class DeviceResource : public Resource
 
     void deleteDeviceResource()
     {
-        OCStackResult result = m_platform.unregisterResource(m_resourceHandle);
+        OCStackResult result = OCPlatform::unregisterResource(m_resourceHandle);
         if(OC_STACK_OK != result)
         {
             throw std::runtime_error(
@@ -232,14 +231,14 @@ class DeviceResource : public Resource
 class LightResource : public Resource
 {
     public:
-    LightResource(OCPlatform& platform)
+    LightResource()
     {
         std::string resourceURI = "/light";
         std::string resourceTypeName = "intel.fridge.light";
         std::string resourceInterface = DEFAULT_INTERFACE;
         EntityHandler cb = std::bind(&LightResource::entityHandler, this,PH::_1, PH::_2);
         uint8_t resourceProperty = 0;
-        OCStackResult result = platform.registerResource(m_resourceHandle,
+        OCStackResult result = OCPlatform::registerResource(m_resourceHandle,
             resourceURI,
             resourceTypeName,
             resourceInterface,
@@ -315,7 +314,7 @@ class LightResource : public Resource
 class DoorResource : public Resource
 {
     public:
-    DoorResource(OCPlatform& platform, const std::string& side):m_side(side)
+    DoorResource(const std::string& side):m_side(side)
     {
 
         std::string resourceURI = "/door/"+ side;
@@ -324,7 +323,7 @@ class DoorResource : public Resource
         EntityHandler cb = std::bind(&DoorResource::entityHandler, this,PH::_1, PH::_2);
 
         uint8_t resourceProperty = 0;
-        OCStackResult result = platform.registerResource(m_resourceHandle,
+        OCStackResult result = OCPlatform::registerResource(m_resourceHandle,
             resourceURI,
             resourceTypeName,
             resourceInterface,
@@ -403,19 +402,18 @@ class DoorResource : public Resource
 
 };
 
-class Refridgerator
+class Refrigerator
 {
     public:
-    Refridgerator(PlatformConfig &cfg)
-        : m_platform(cfg),
-        m_light(m_platform),
-        m_device(m_platform),
-        m_leftdoor(m_platform, "left"),
-        m_rightdoor(m_platform, "right")
+    Refrigerator()
+        :
+        m_light(),
+        m_device(),
+        m_leftdoor("left"),
+        m_rightdoor("right")
     {
     }
     private:
-    OCPlatform m_platform;
     LightResource m_light;
     DeviceResource m_device;
     DoorResource m_leftdoor;
@@ -433,7 +431,8 @@ int main ()
         QualityOfService::LowQos
     };
 
-    Refridgerator rf(cfg);
+    OCPlatform::Configure(cfg);
+    Refrigerator rf();
 
     // we will keep the server alive for at most 30 minutes
     std::this_thread::sleep_for(std::chrono::minutes(30));
index a4f5a32..e1b4e5c 100644 (file)
@@ -23,7 +23,6 @@
 
 #include <string>
 #include <cstdlib>
-#include <pthread.h>
 #include "OCPlatform.h"
 #include "OCApi.h"
 
@@ -277,15 +276,12 @@ int main(int argc, char* argv[]) {
         OC::QualityOfService::LowQos
     };
 
-    // Create a OCPlatform instance.
-    // Note: Platform creation is synchronous call.
-
+    OCPlatform::Configure(cfg);
     try
     {
-        OCPlatform platform(cfg);
-        std::cout << "Created Platform..."<<std::endl;
         // Find all resources
-        platform.findResource("", "coap://224.0.1.187/oc/core?rt=core.garage", &foundResource);
+        OCPlatform::findResource("", "coap://224.0.1.187/oc/core?rt=core.garage",
+                    &foundResource);
         std::cout<< "Finding Resource... " <<std::endl;
         while(true)
         {
@@ -295,7 +291,7 @@ int main(int argc, char* argv[]) {
     }
     catch(OCException& e)
     {
-        //log(e.what());
+        std::cerr << "Exception in GarageClient: "<<e.what();
     }
 
     return 0;
index eae2b9c..e033504 100644 (file)
@@ -111,7 +111,7 @@ public:
     access to, you can accomplish this with a free function: */
 
     /// This function internally calls registerResource API.
-    void createResource(OC::OCPlatform& platform)
+    void createResource()
     {
         std::string resourceURI = m_garageUri; // URI of the resource
         std::string resourceTypeName = "core.garage"; // resource type name.
@@ -121,7 +121,7 @@ public:
         uint8_t resourceProperty = OC_DISCOVERABLE | OC_OBSERVABLE;
 
         // This will internally create and register the resource.
-        OCStackResult result = platform.registerResource(
+        OCStackResult result = OCPlatform::registerResource(
                                     m_resourceHandle, resourceURI, resourceTypeName,
                                     resourceInterface, &entityHandler, resourceProperty);
 
@@ -260,14 +260,11 @@ int main(int argc, char* argv[1])
         OC::QualityOfService::LowQos
     };
 
-    // Create a OCPlatform instance.
-    // Note: Platform creation is synchronous call.
+    OCPlatform::Configure(cfg);
     try
     {
-        OCPlatform platform(cfg);
-
         // Invoke createResource function of class light.
-        myGarage.createResource(platform);
+        myGarage.createResource();
 
         // Perform app tasks
         while(true)
@@ -280,6 +277,6 @@ int main(int argc, char* argv[1])
         //log(e.what());
     }
 
-    // No explicit call to stop the platform.
-    // When OCPlatform destructor is invoked, internally we do platform cleanup
+    // No explicit call to stop the OCPlatform
+    // When OCPlatform destructor is invoked, internally we do Platform cleanup
 }
index 3e509c0..d2edcfc 100644 (file)
@@ -64,7 +64,7 @@ int exec(const boost::program_options::variables_map& vm)
 {
  using namespace std;
 
- OC::OCPlatform platform({
+ OC::OCPlatform::Configure({
                           OC::ServiceType::InProc,              // in-process server
                           OC::ModeType::Client,                 // client mode
                           vm["host_ip"].as<string>(),           // host
@@ -107,7 +107,7 @@ int exec(const boost::program_options::variables_map& vm)
  for(const auto& resource_URI : resource_URIs)
   cout << resource_URI << '\n';
 
- Intel::OCDemo::client::resource_handler resources(platform, resource_URIs);
+ Intel::OCDemo::client::resource_handler resources(resource_URIs);
 
  // Register callbacks and wait for resources:
  resources.find_resources();
index d82b530..47830b0 100644 (file)
@@ -36,13 +36,12 @@ class resource_handle
 
 class resource_handler
 {
- OC::OCPlatform& platform;
 
  static std::vector<std::shared_ptr<resource_handle>> resources;    // URI -> Maybe resource
 
  public:
- resource_handler(OC::OCPlatform& platform_, const std::vector<std::string>& resource_URIs_);
- resource_handler(OC::OCPlatform& platform_);
+ resource_handler(const std::vector<std::string>& resource_URIs_);
+ resource_handler();
 
  public:
  bool has(const std::string& URI)
@@ -70,7 +69,7 @@ class resource_handler
 
                 call_timer.mark("find_resources");
 
-                platform.findResource("", resource->URI,
+                OC::OCPlatform::findResource("", resource->URI,
                                       std::bind(&resource_handle::onFoundResource, resource, std::placeholders::_1));
          }
  }
@@ -78,17 +77,12 @@ class resource_handler
 
 std::vector<std::shared_ptr<resource_handle>> resource_handler::resources;
 
-resource_handler::resource_handler(OC::OCPlatform& platform_, const std::vector<std::string>& resource_URIs)
- : platform(platform_)
+resource_handler::resource_handler(const std::vector<std::string>& resource_URIs)
 {
  for(const auto& URI : resource_URIs)
   add(URI);
 }
 
-resource_handler::resource_handler(OC::OCPlatform& platform_)
-  : platform(platform_)
-{}
-
 void resource_handle::onFoundResource(std::shared_ptr<OC::OCResource> in_resource)
 {
  using std::cout;
index 33af638..6b3dd42 100644 (file)
@@ -23,23 +23,23 @@ OCRepresentation LightResource::getRepresentation(void)
  return m_rep;
 }
 
-void LightResource::addType(const OC::OCPlatform& platform, const std::string& type) const
+void LightResource::addType(const std::string& type) const
 {
- OCStackResult result = platform.bindTypeToResource(m_resourceHandle, type);
+ OCStackResult result = OC::OCPlatform::bindTypeToResource(m_resourceHandle, type);
 
  if(OC_STACK_OK != result)
   cout << "Binding TypeName to Resource was unsuccessful, result was " << result << '\n';
 }
 
-void LightResource::addInterface(const OC::OCPlatform& platform, const std::string& interface) const
+void LightResource::addInterface(const std::string& interface) const
 {
- OCStackResult result = platform.bindInterfaceToResource(m_resourceHandle, interface);
+ OCStackResult result = OC::OCPlatform::bindInterfaceToResource(m_resourceHandle, interface);
 
  if(OC_STACK_OK != result)
   cout << "Binding TypeName to Resource was unsuccessful, result was " << result << '\n';
 }
 
-void LightResource::createResource(OC::OCPlatform& platform, const unsigned int resource_number)
+void LightResource::createResource(const unsigned int resource_number)
 {
  string resourceURI      { make_URI(resource_number) };
  string resourceTypeName { "core.light" };
@@ -47,7 +47,7 @@ void LightResource::createResource(OC::OCPlatform& platform, const unsigned int
  cout << "registering resource: " << resourceURI << '\n';
  cout << "registering type name \"" << resourceTypeName << "\".\n";
  // This will internally create and register the resource, binding the current instance's method as a callback:
- OCStackResult result = platform.registerResource(
+ OCStackResult result = OC::OCPlatform::registerResource(
                                             m_resourceHandle, resourceURI, resourceTypeName,
                                             DEFAULT_INTERFACE,
                                             std::bind(&LightResource::entityHandler, this, std::placeholders::_1, std::placeholders::_2),
@@ -69,7 +69,7 @@ void LightResource::observe_function()
 
     m_power += 10;
 
-    const auto result = m_platform.notifyAllObservers(getHandle());
+    const auto result = OC::OCPlatform::notifyAllObservers(getHandle());
 
     // Stop notifications when there are no more observers:
     if(OC_STACK_NO_OBSERVERS == result)
@@ -81,11 +81,11 @@ void LightResource::observe_function()
  cerr << "Observation thread is shutting down.\n";
 }
 
-void LightResource::unregisterResource(OC::OCPlatform& platform)
+void LightResource::unregisterResource()
 {
     std::cout << "Unregistering light resource"<<std::endl;
 
-    OCStackResult result = platform.unregisterResource(m_resourceHandle);
+    OCStackResult result = OC::OCPlatform::unregisterResource(m_resourceHandle);
 
     if(result == OC_STACK_OK)
     {
index fff6094..c569302 100644 (file)
@@ -25,7 +25,6 @@ using namespace std;
 class LightResource
 {
  public:
-    OCPlatform& m_platform;
     bool m_state;       // off or on?
     int m_power;        // power level
     OCRepresentation m_rep;
@@ -41,9 +40,8 @@ class LightResource
     OCResourceHandle m_resourceHandle;
 
     public:
-    LightResource(OCPlatform& platform)
-     : m_platform(platform),
-       m_state(false),
+    LightResource()
+     : m_state(false),
        m_power(0),
        m_observation(false)
     {}
@@ -66,15 +64,15 @@ class LightResource
 
     public:
     // This function internally calls registerResource API.
-    void createResource(OC::OCPlatform& platform, const unsigned int resource_number);
-    void unregisterResource(OC::OCPlatform& platform);
+    void createResource(const unsigned int resource_number);
+    void unregisterResource();
     OCResourceHandle getHandle() const { return m_resourceHandle; }
 
     void setRepresentation(const OCRepresentation& rep);
     OCRepresentation getRepresentation(void);
 
-    void addType(const OC::OCPlatform& platform, const std::string& type) const;
-    void addInterface(const OC::OCPlatform& platform, const std::string& interface) const;
+    void addType(const std::string& type) const;
+    void addInterface(const std::string& interface) const;
 
     private:
     OCEntityHandlerResult entityHandler(std::shared_ptr<OCResourceRequest> request,
index dc2175f..14566ea 100644 (file)
@@ -81,8 +81,6 @@ struct simple_join_guard
 struct client_t
 {
  const boost::program_options::variables_map        m_vm;
- std::shared_ptr<OC::OCPlatform>                    m_platform_ptr;
- OC::OCPlatform&                                    m_platform;     // reference to *m_platform_ptr
 
  atomic<bool>&                                      quit_flag;
 
@@ -90,11 +88,8 @@ struct client_t
 
  public:
  client_t(const boost::program_options::variables_map vm,
-          std::shared_ptr<OC::OCPlatform> platform_ptr,
           atomic<bool>& quit_flag_)
   : m_vm(vm),
-    m_platform_ptr(platform_ptr),
-    m_platform(*m_platform_ptr),
     quit_flag(quit_flag_)
  {}
 
@@ -117,7 +112,7 @@ struct client_t
     for(const auto& resource_URI : resource_URIs)
      cout << resource_URI << '\n';
 
-    Intel::OCDemo::client::resource_handler resources(m_platform, resource_URIs);
+    Intel::OCDemo::client::resource_handler resources(resource_URIs);
 
     // Register callbacks and wait for resources:
     resources.find_resources();
@@ -133,8 +128,6 @@ struct client_t
 struct server_t
 {
  const boost::program_options::variables_map        m_vm;
- std::shared_ptr<OC::OCPlatform>                    m_platform_ptr;
- OC::OCPlatform&                                    m_platform;
 
  atomic<bool>&                                      quit_flag;
 
@@ -146,11 +139,8 @@ struct server_t
 
  public:
  server_t(const boost::program_options::variables_map& vm,
-          std::shared_ptr<OC::OCPlatform> platform,
           atomic<bool>& quit_flag_)
   : m_vm(vm),
-    m_platform_ptr(platform),
-    m_platform(*m_platform_ptr),
     quit_flag(quit_flag_)
  {
     m_nresources = vm["nres"].as<unsigned long>();
@@ -176,11 +166,11 @@ void server_t::init()
   {
     cout << "Registering resource " << resource_number << ": " << std::flush;
 
-    auto lr = make_shared<Intel::OCDemo::LightResource>(m_platform);
+    auto lr = make_shared<Intel::OCDemo::LightResource>();
 
-    lr->createResource(m_platform, resource_number);
-    lr->addType(m_platform, "core.brightlight");
-    lr->addInterface(m_platform, "oc.mi.ll");
+    lr->createResource(resource_number);
+    lr->addType("core.brightlight");
+    lr->addInterface("oc.mi.ll");
 
     lights.push_back(lr);
 
@@ -194,20 +184,19 @@ int exec(const boost::program_options::variables_map& vm)
 
  std::cout << "Starting platform: " << std::flush;
 
auto platform = make_shared<OC::OCPlatform>(OC::PlatformConfig {
-                          OC::ServiceType::InProc,              // in-process server
OC::OCPlatform::Configure(OC::PlatformConfig {
+                          OC::ServiceType::InProc,
                           OC::ModeType::Both,                   // run in client/server mode
                           vm["host_ip"].as<string>(),           // host
                           vm["host_port"].as<uint16_t>(),       // port
                           OC::QualityOfService::LowQos
                         });
-
  std::cout << "Ok." << std::endl;
 
  std::atomic<bool> quit_flag;
 
- server_t server(vm, platform, quit_flag);
- client_t client(vm, platform, quit_flag);
+ server_t server(vm, quit_flag);
+ client_t client(vm, quit_flag);
 
 std::cout << "JFW: TODO: don't need to separate these any more\n";
  server.init();
index 990bc45..47b909c 100644 (file)
@@ -52,7 +52,7 @@ int exec(const boost::program_options::variables_map& vm)
 
  std::cout << "Starting platform: " << std::flush;
 
- OC::OCPlatform platform({
+ OC::OCPlatform::Configure({
                           OC::ServiceType::InProc,              // in-process server
                           OC::ModeType::Server,                 // run in server mode
                           vm["host_ip"].as<string>(),           // host
@@ -72,11 +72,11 @@ int exec(const boost::program_options::variables_map& vm)
   {
         cout << "Registering resource " << resource_number << ": " << std::flush;
 
-        auto lr = make_shared<Intel::OCDemo::LightResource>(platform);
+        auto lr = make_shared<Intel::OCDemo::LightResource>();
 
-        lr->createResource(platform, resource_number);
-        lr->addType(platform, std::string("core.brightlight"));
-        lr->addInterface(platform, std::string("oc.mi.ll"));
+        lr->createResource(resource_number);
+        lr->addType(std::string("core.brightlight"));
+        lr->addInterface(std::string("oc.mi.ll"));
 
         lights.push_back(lr);
 
@@ -89,7 +89,7 @@ int exec(const boost::program_options::variables_map& vm)
 
  for(auto light: lights)
  {
-    light->unregisterResource(platform);
+    light->unregisterResource();
  }
 
  return 1;
index f74d27f..8dfda11 100644 (file)
@@ -30,8 +30,6 @@ using namespace OC;
 
 std::shared_ptr<OCResource> curResource;
 
-OCPlatform* platformPtr;
-
 // Callback to presence
 void presenceHandler(OCStackResult result, const unsigned int nonce)
 {
@@ -94,7 +92,7 @@ void foundResource(std::shared_ptr<OCResource> resource)
             {
                 curResource = resource;
                 OCPlatform::OCPresenceHandle presenceHandle;
-                platformPtr->subscribePresence(presenceHandle, hostAddress, &presenceHandler);
+                OCPlatform::subscribePresence(presenceHandle, hostAddress, &presenceHandler);
             }
         }
         else
@@ -121,17 +119,13 @@ int main(int argc, char* argv[]) {
         OC::QualityOfService::LowQos
     };
 
-    // Create a OCPlatform instance.
-    // Note: Platform creation is synchronous call.
+    OCPlatform::Configure(cfg);
 
     try
     {
-        OCPlatform platform(cfg);
-        // PlatformPtr is used in another function
-        platformPtr = &platform;
         std::cout << "Created Platform..."<<std::endl;
         // Find all resources
-        platform.findResource("", "coap://224.0.1.187/oc/core", &foundResource);
+        OCPlatform::findResource("", "coap://224.0.1.187/oc/core", &foundResource);
         std::cout<< "Finding Resource... " <<std::endl;
         while(true)
         {
index f2319a0..305537b 100644 (file)
@@ -62,7 +62,7 @@ public:
     access to, you can accomplish this with a free function: */
 
     /// This function internally calls registerResource API.
-    void createResource(OC::OCPlatform& platform)
+    void createResource()
     {
         std::string resourceURI = m_lightUri; // URI of the resource
         std::string resourceTypeName = "core.light"; // resource type name.
@@ -72,7 +72,7 @@ public:
         uint8_t resourceProperty = OC_DISCOVERABLE | OC_OBSERVABLE;
 
         // This will internally create and register the resource.
-        OCStackResult result = platform.registerResource(
+        OCStackResult result = OCPlatform::registerResource(
                                     m_resourceHandle, resourceURI, resourceTypeName,
                                     resourceInterface, &entityHandler, resourceProperty);
 
@@ -83,7 +83,7 @@ public:
     }
 
     /// This function internally calls registerResource API.
-    void createResource2(OC::OCPlatform& platform)
+    void createResource2()
     {
         std::string resourceURI = m_lightUri2; // URI of the resource
         std::string resourceTypeName = "core.light"; // resource type name. In this case, it is light
@@ -93,7 +93,7 @@ public:
         uint8_t resourceProperty = OC_DISCOVERABLE | OC_OBSERVABLE;
 
         // This will internally create and register the resource.
-        OCStackResult result = platform.registerResource(
+        OCStackResult result = OCPlatform::registerResource(
                                     m_resourceHandle2, resourceURI, resourceTypeName,
                                     resourceInterface, &entityHandler, resourceProperty);
 
@@ -103,7 +103,7 @@ public:
         }
     }
 
-    void createResource3(OC::OCPlatform& platform)
+    void createResource3()
     {
         std::string resourceURI = m_lightUri3; // URI of the resource
         std::string resourceTypeName = "core.light";
@@ -113,7 +113,7 @@ public:
         uint8_t resourceProperty = OC_DISCOVERABLE | OC_OBSERVABLE;
 
         // This will internally create and register the resource.
-        OCStackResult result = platform.registerResource(
+        OCStackResult result = OCPlatform::registerResource(
                                     m_resourceHandle3, resourceURI, resourceTypeName,
                                     resourceInterface, &entityHandler, resourceProperty);
 
@@ -128,18 +128,18 @@ public:
         return m_resourceHandle;
     }
 
-    void addType(const OC::OCPlatform& platform, const std::string& type) const
+    void addType(const std::string& type) const
     {
-        OCStackResult result = platform.bindTypeToResource(m_resourceHandle, type);
+        OCStackResult result = OC::OCPlatform::bindTypeToResource(m_resourceHandle, type);
         if (OC_STACK_OK != result)
         {
             cout << "Binding TypeName to Resource was unsuccessful\n";
         }
     }
 
-    void addInterface(const OC::OCPlatform& platform, const std::string& interface) const
+    void addInterface(const std::string& interface) const
     {
-        OCStackResult result = platform.bindInterfaceToResource(m_resourceHandle, interface);
+        OCStackResult result = OC::OCPlatform::bindInterfaceToResource(m_resourceHandle, interface);
         if (OC_STACK_OK != result)
         {
             cout << "Binding TypeName to Resource was unsuccessful\n";
@@ -168,36 +168,34 @@ int main()
         OC::QualityOfService::LowQos
     };
 
-    // Create a OCPlatform instance.
-    // Note: Platform creation is synchronous call.
+    OCPlatform::Configure(cfg);
     try
     {
-        OCPlatform platform(cfg);
-
+        using namespace OC::OCPlatform;
         // Time to Live is 30 seconds
-        platform.startPresence(30);
+        startPresence(30);
 
         // Invoke createResource function of class light.
-        myLightResource.createResource(platform);
+        myLightResource.createResource();
 
         printf("\nEnter a key to create the second resource\n");
         getchar();
 
-        myLightResource.createResource2(platform);
+        myLightResource.createResource2();
 
         printf("\nEnter a key to stop the presence\n");
         getchar();
-        platform.stopPresence();
+        stopPresence();
 
         printf("\nEnter a key to restart the presence\n");
         getchar();
 
-        platform.startPresence(30);
+        startPresence(30);
 
         printf("\nEnter a key to create the third resource\n");
         getchar();
 
-        myLightResource.createResource3(platform);
+        myLightResource.createResource3();
 
         // Perform app tasks
         while(true)
index 4ea1cf2..60f0a4d 100644 (file)
@@ -225,15 +225,12 @@ int main(int argc, char* argv[]) {
         OC::QualityOfService::LowQos
     };
 
-    // Create a OCPlatform instance.
-    // Note: Platform creation is synchronous call.
+    OCPlatform::Configure(cfg);
 
     try
     {
-        OCPlatform platform(cfg);
-        std::cout << "Created Platform..."<<std::endl;
         // Find all resources
-        platform.findResource("", "coap://224.0.1.187/oc/core", &foundResource);
+        OCPlatform::findResource("", "coap://224.0.1.187/oc/core", &foundResource);
         std::cout<< "Finding Resource... " <<std::endl;
         while(true)
         {
index bae9eab..f9d3978 100644 (file)
@@ -108,10 +108,11 @@ public:
     }
 
     /// This function internally calls registerResource API.
-    void createResources(OC::OCPlatform& platform)
+    void createResources()
     {
+        using namespace OC::OCPlatform;
         // This will internally create and register the resource.
-        OCStackResult result = platform.registerResource(
+        OCStackResult result = registerResource(
                                     m_roomHandle, m_roomUri, m_roomTypes[0],
                                     m_roomInterfaces[0], entityHandlerRoom,
                                     OC_DISCOVERABLE | OC_OBSERVABLE
@@ -122,19 +123,19 @@ public:
             cout << "Resource creation (room) was unsuccessful\n";
         }
 
-        result = platform.bindInterfaceToResource(m_roomHandle, m_roomInterfaces[1]);
+        result = bindInterfaceToResource(m_roomHandle, m_roomInterfaces[1]);
         if (OC_STACK_OK != result)
         {
             cout << "Binding TypeName to Resource was unsuccessful\n";
         }
 
-        result = platform.bindInterfaceToResource(m_roomHandle, m_roomInterfaces[2]);
+        result = bindInterfaceToResource(m_roomHandle, m_roomInterfaces[2]);
         if (OC_STACK_OK != result)
         {
             cout << "Binding TypeName to Resource was unsuccessful\n";
         }
 
-        result = platform.registerResource(
+        result = registerResource(
                                     m_lightHandle, m_lightUri, m_lightTypes[0],
                                     m_lightInterfaces[0], entityHandlerLight,
                                     OC_DISCOVERABLE | OC_OBSERVABLE
@@ -145,7 +146,7 @@ public:
             cout << "Resource creation (light) was unsuccessful\n";
         }
 
-        result = platform.registerResource(
+        result = registerResource(
                                     m_fanHandle, m_fanUri, m_fanTypes[0],
                                     m_fanInterfaces[0], entityHandlerFan,
                                     OC_DISCOVERABLE | OC_OBSERVABLE
@@ -156,13 +157,13 @@ public:
             cout << "Resource creation (fan) was unsuccessful\n";
         }
 
-        result = platform.bindResource(m_roomHandle, m_lightHandle);
+        result = bindResource(m_roomHandle, m_lightHandle);
         if (OC_STACK_OK != result)
         {
             cout << "Binding fan resource to room was unsuccessful\n";
         }
 
-        result = platform.bindResource(m_roomHandle, m_fanHandle);
+        result = bindResource(m_roomHandle, m_fanHandle);
         if (OC_STACK_OK != result)
         {
             cout << "Binding light resource to room was unsuccessful\n";
@@ -501,13 +502,11 @@ int main()
         OC::QualityOfService::LowQos
     };
 
-    // Create a OCPlatform instance.
-    // Note: Platform creation is synchronous call.
+    OCPlatform::Configure(cfg);
     try
     {
-        OCPlatform platform(cfg);
 
-        myRoomResource.createResources(platform);
+        myRoomResource.createResources();
 
         // Perform app tasks
         while(true)
index 755fc65..400591a 100644 (file)
@@ -362,15 +362,11 @@ int main(int argc, char* argv[]) {
         OC::QualityOfService::LowQos
     };
 
-    // Create a OCPlatform instance.
-    // Note: Platform creation is synchronous call.
-
+    OCPlatform::Configure(cfg);
     try
     {
-        OCPlatform platform(cfg);
-        std::cout << "Created Platform..."<<std::endl;
         // Find all resources
-        platform.findResource("", "coap://224.0.1.187/oc/core?rt=core.light", &foundResource);
+        OCPlatform::findResource("", "coap://224.0.1.187/oc/core?rt=core.light", &foundResource);
         std::cout<< "Finding Resource... " <<std::endl;
         while(true)
         {
index 995b2a1..204de3e 100644 (file)
@@ -376,15 +376,12 @@ int main(int argc, char* argv[]) {
         OC::QualityOfService::LowQos
     };
 
-    // Create a OCPlatform instance.
-    // Note: Platform creation is synchronous call.
+    OCPlatform::Configure(cfg);
 
     try
     {
-        OCPlatform platform(cfg);
-        std::cout << "Created Platform..."<<std::endl;
         // Find all resources
-        platform.findResource("", "coap://224.0.1.187/oc/core?rt=core.light", &foundResource,
+        OCPlatform::findResource("", "coap://224.0.1.187/oc/core?rt=core.light", &foundResource,
                 OC::QualityOfService::LowQos);
         std::cout<< "Finding Resource... " <<std::endl;
         while(true)
index 4ceee38..444c4dc 100644 (file)
@@ -142,11 +142,13 @@ private:
     }
 
 public:
-    void start(OCPlatform& platform)
+    void start()
     {
         std::cout<<"Starting Client find:"<<std::endl;
         FindCallback f (std::bind(&ClientWorker::foundResource, this, std::placeholders::_1));
-        std::cout<<"result:" << platform.findResource("", "coap://224.0.1.187/oc/core?rt=core.foo", f)<< std::endl;
+        std::cout<<"result:" <<
+            OCPlatform::findResource("", "coap://224.0.1.187/oc/core?rt=core.foo", f)
+            << std::endl;
         std::cout<<"Finding Resource..."<<std::endl;
 
         {
@@ -175,7 +177,7 @@ struct FooResource
         m_rep.setValue("barCount", m_barCount);
     }
 
-    bool createResource(OCPlatform& platform)
+    bool createResource()
     {
         std::string resourceURI = "/q/foo";
         std::string resourceTypeName = "core.foo";
@@ -183,8 +185,10 @@ struct FooResource
 
         uint8_t resourceProperty = OC_DISCOVERABLE;
 
-        EntityHandler eh(std::bind(&FooResource::entityHandler, this, std::placeholders::_1, std::placeholders::_2));
-        OCStackResult result = platform.registerResource(m_resourceHandle, resourceURI, resourceTypeName,
+        EntityHandler eh(std::bind(&FooResource::entityHandler,
+                    this, std::placeholders::_1, std::placeholders::_2));
+        OCStackResult result = OCPlatform::registerResource(m_resourceHandle,
+                resourceURI, resourceTypeName,
                                     resourceInterface,
                                     eh, resourceProperty);
         if(OC_STACK_OK != result)
@@ -284,19 +288,19 @@ int main()
         OC::QualityOfService::LowQos
     };
 
+    OCPlatform::Configure(cfg);
     FooResource fooRes;
 
     try
     {
-        OCPlatform platform(cfg);
 
-        if(!fooRes.createResource(platform))
+        if(!fooRes.createResource())
         {
             return -1;
         }
 
         ClientWorker cw;
-        cw.start(platform);
+        cw.start();
     }
     catch(OCException& e)
     {
index 15f5a94..a8138f0 100644 (file)
@@ -52,7 +52,6 @@ class LightResource
 
 public:
     /// Access this property from a TB client
-    OCPlatform m_platform;
     std::string m_name;
     bool m_state;
     int m_power;
@@ -63,8 +62,8 @@ public:
 
 public:
     /// Constructor
-    LightResource(PlatformConfig& cfg): m_platform(cfg),
-            m_name("John's light"), m_state(false), m_power(0), m_lightUri("/a/light") {
+    LightResource()
+        :m_name("John's light"), m_state(false), m_power(0), m_lightUri("/a/light") {
         // Initialize representation
         m_lightRep.setUri(m_lightUri);
 
@@ -89,7 +88,7 @@ public:
         EntityHandler cb = std::bind(&LightResource::entityHandler, this,PH::_1, PH::_2);
 
         // This will internally create and register the resource.
-        OCStackResult result = m_platform.registerResource(
+        OCStackResult result = OCPlatform::registerResource(
                                     m_resourceHandle, resourceURI, resourceTypeName,
                                     resourceInterface, cb, resourceProperty);
 
@@ -113,7 +112,7 @@ public:
         OCResourceHandle resHandle;
 
         // This will internally create and register the resource.
-        OCStackResult result = m_platform.registerResource(
+        OCStackResult result = OCPlatform::registerResource(
                                     resHandle, resourceURI, resourceTypeName,
                                     resourceInterface, cb, resourceProperty);
 
@@ -202,7 +201,7 @@ public:
 
     void addType(const std::string& type) const
     {
-        OCStackResult result = m_platform.bindTypeToResource(m_resourceHandle, type);
+        OCStackResult result = OCPlatform::bindTypeToResource(m_resourceHandle, type);
         if (OC_STACK_OK != result)
         {
             cout << "Binding TypeName to Resource was unsuccessful\n";
@@ -211,7 +210,7 @@ public:
 
     void addInterface(const std::string& interface) const
     {
-        OCStackResult result = m_platform.bindInterfaceToResource(m_resourceHandle, interface);
+        OCStackResult result = OCPlatform::bindInterfaceToResource(m_resourceHandle, interface);
         if (OC_STACK_OK != result)
         {
             cout << "Binding TypeName to Resource was unsuccessful\n";
@@ -384,13 +383,13 @@ void * ChangeLightRepresentation (void *param)
                 resourceResponse->setErrorCode(200);
                 resourceResponse->setResourceRepresentation(lightPtr->get(), DEFAULT_INTERFACE);
 
-                result = lightPtr->m_platform.notifyListOfObservers(  lightPtr->getHandle(),
+                result = OCPlatform::notifyListOfObservers(  lightPtr->getHandle(),
                                                              lightPtr->m_interestedObservers,
                                                              resourceResponse);
             }
             else
             {
-                result = lightPtr->m_platform.notifyAllObservers(lightPtr->getHandle());
+                result = OCPlatform::notifyAllObservers(lightPtr->getHandle());
             }
 
             if(OC_STACK_NO_OBSERVERS == result)
@@ -443,10 +442,11 @@ int main(int argc, char* argv[1])
         OC::QualityOfService::LowQos
     };
 
+    OCPlatform::Configure(cfg);
     try
     {
         // Create the instance of the resource class (in this case instance of class 'LightResource').
-        LightResource myLight(cfg);
+        LightResource myLight;
 
         // Invoke createResource function of class light.
         myLight.createResource();
@@ -465,5 +465,5 @@ int main(int argc, char* argv[1])
     }
 
     // No explicit call to stop the platform.
-    // When OCPlatform destructor is invoked, internally we do platform cleanup
+    // When OCPlatform::destructor is invoked, internally we do platform cleanup
 }
index 0bcefd6..1b20294 100644 (file)
@@ -52,7 +52,6 @@ class LightResource
 
 public:
     /// Access this property from a TB client
-    OCPlatform m_platform;
     std::string m_name;
     bool m_state;
     int m_power;
@@ -63,8 +62,8 @@ public:
 
 public:
     /// Constructor
-    LightResource(PlatformConfig& cfg): m_platform(cfg),
-            m_name("John's light"), m_state(false), m_power(0), m_lightUri("/a/light") {
+    LightResource(PlatformConfig& cfg)
+        :m_name("John's light"), m_state(false), m_power(0), m_lightUri("/a/light") {
         // Initialize representation
         m_lightRep.setUri(m_lightUri);
 
@@ -89,7 +88,7 @@ public:
         EntityHandler cb = std::bind(&LightResource::entityHandler, this,PH::_1, PH::_2);
 
         // This will internally create and register the resource.
-        OCStackResult result = m_platform.registerResource(
+        OCStackResult result = OCPlatform::registerResource(
                                     m_resourceHandle, resourceURI, resourceTypeName,
                                     resourceInterface, cb, resourceProperty);
 
@@ -113,7 +112,7 @@ public:
         OCResourceHandle resHandle;
 
         // This will internally create and register the resource.
-        OCStackResult result = m_platform.registerResource(
+        OCStackResult result = OCPlatform::registerResource(
                                     resHandle, resourceURI, resourceTypeName,
                                     resourceInterface, cb, resourceProperty);
 
@@ -208,7 +207,7 @@ public:
 
     void addType(const std::string& type) const
     {
-        OCStackResult result = m_platform.bindTypeToResource(m_resourceHandle, type);
+        OCStackResult result = OCPlatform::bindTypeToResource(m_resourceHandle, type);
         if (OC_STACK_OK != result)
         {
             cout << "Binding TypeName to Resource was unsuccessful\n";
@@ -217,7 +216,7 @@ public:
 
     void addInterface(const std::string& interface) const
     {
-        OCStackResult result = m_platform.bindInterfaceToResource(m_resourceHandle, interface);
+        OCStackResult result = OCPlatform::bindInterfaceToResource(m_resourceHandle, interface);
         if (OC_STACK_OK != result)
         {
             cout << "Binding TypeName to Resource was unsuccessful\n";
@@ -379,13 +378,16 @@ void * ChangeLightRepresentation (void *param)
                 resourceResponse->setErrorCode(200);
                 resourceResponse->setResourceRepresentation(lightPtr->get(), DEFAULT_INTERFACE);
 
-                result = lightPtr->m_platform.notifyListOfObservers(  lightPtr->getHandle(),
-                                                             lightPtr->m_interestedObservers,
-                                                             resourceResponse, OC::QualityOfService::HighQos);
+                result = OCPlatform::notifyListOfObservers(
+                                                            lightPtr->getHandle(),
+                                                            lightPtr->m_interestedObservers,
+                                                            resourceResponse,
+                                                            OC::QualityOfService::HighQos);
             }
             else
             {
-                result = lightPtr->m_platform.notifyAllObservers(lightPtr->getHandle(), OC::QualityOfService::HighQos);
+                result = OCPlatform::notifyAllObservers(lightPtr->getHandle(),
+                                                            OC::QualityOfService::HighQos);
             }
 
             if(OC_STACK_NO_OBSERVERS == result)
@@ -438,6 +440,8 @@ int main(int argc, char* argv[1])
         OC::QualityOfService::LowQos
     };
 
+    OCPlatform::Configure(cfg);
+
     try
     {
         // Create the instance of the resource class (in this case instance of class 'LightResource').
index 8140ff9..e898a8d 100644 (file)
 
 namespace OC
 {
-    class OCPlatform;
+    class OCPlatform_impl;
 
     class IClientWrapper : public std::enable_shared_from_this<IClientWrapper>
     {
     protected:
-        OCPlatform& m_owner;
+        OCPlatform_impl& m_owner;
 
     public:
         typedef std::shared_ptr<IClientWrapper> Ptr;
 
-        IClientWrapper(OCPlatform& owner)
+        IClientWrapper(OCPlatform_impl& owner)
          : m_owner(owner)
         {}
 
index e0874fe..2371ce5 100644 (file)
@@ -34,12 +34,12 @@ namespace OC
     class IServerWrapper
     {
     protected:
-        OCPlatform& m_owner;
+        OCPlatform_impl& m_owner;
 
     public:
         typedef std::shared_ptr<IServerWrapper> Ptr;
 
-        IServerWrapper(OCPlatform& owner)
+        IServerWrapper(OCPlatform_impl& owner)
          : m_owner(owner)
         {}
 
index 49d80bf..b0af439 100644 (file)
@@ -40,7 +40,7 @@ namespace OC
     class InProcClientWrapper : public IClientWrapper
     {
     public:
-        InProcClientWrapper(OC::OCPlatform& owner, std::weak_ptr<std::recursive_mutex> csdkLock,
+        InProcClientWrapper(OC::OCPlatform_impl& owner, std::weak_ptr<std::recursive_mutex> csdkLock,
                             PlatformConfig cfg);
         virtual ~InProcClientWrapper();
 
@@ -94,7 +94,7 @@ namespace OC
         std::weak_ptr<std::recursive_mutex> m_csdkLock;
 
     private:
-        OC::OCPlatform& m_owner;
+        OC::OCPlatform_impl& m_owner;
         PlatformConfig  m_cfg;
     };
 }
index 23f1250..654f10b 100644 (file)
@@ -32,7 +32,7 @@ namespace OC
     class InProcServerWrapper : public IServerWrapper
     {
     public:
-        InProcServerWrapper(OC::OCPlatform& owner, std::weak_ptr<std::recursive_mutex> csdkLock,
+        InProcServerWrapper(OC::OCPlatform_impl& owner, std::weak_ptr<std::recursive_mutex> csdkLock,
             PlatformConfig cfg);
         virtual ~InProcServerWrapper();
 
index 2c7835d..fd988af 100644 (file)
@@ -40,7 +40,6 @@
 
 namespace OC
 {
-    class OCPlatform;
     class OCResource;
     class OCResourceRequest;
     class OCResourceResponse;
@@ -128,6 +127,13 @@ namespace OC
         QualityOfService           QoS;
 
         public:
+            PlatformConfig()
+                : serviceType(ServiceType::InProc),
+                mode(ModeType::Both),
+                ipAddress("0.0.0.0"),
+                port(0),
+                QoS(QualityOfService::NaQos)
+        {}
             PlatformConfig(const ServiceType serviceType_,
             const ModeType mode_,
             const std::string& ipAddress_,
index 93100ae..491f1ce 100644 (file)
 
 #ifndef __OCPLATFORM_H
 #define __OCPLATFORM_H
-
-#include <map>
-
-#include "OCApi.h"
-#include "OCResource.h"
-#include "OCPlatformHandler.h"
-#include "WrapperFactory.h"
-#include "OCResourceRequest.h"
-#include "OCResourceResponse.h"
-#include "OCRepresentation.h"
-
-#include "oc_logger.hpp"
-
+#include <OCApi.h>
+#include <OCPlatform_impl.h>
 namespace OC
 {
     /**
-    *   @brief  Both server and client must initialize the core platform by instantiating OCPlatform.
-    *           On successful initialization, an instance of the OCPlatform is returned.
-    *           APIs in OCPlatform provide mechanism to register a resource and host the resource
-    *           on the server, find resources on the network etc.
+    * @brief: This namespace contains the main entrance/functionality of the product.
+    * It may be used with OC::OCPlatform::functionName.  To set a custom configuration,
+    * the implementer must make a call to OCPlatform::Configure before the first usage
+    * of a function in this namespace.
     */
-    class OCPlatform
+    namespace OCPlatform
     {
-    public:
-        // typedef for handle to cancel presence info with
-        typedef OCDoHandle OCPresenceHandle;
-
         /**
-        * Constructor for OCPlatform. Constructs a new OCPlatform from a given PlatformConfig with
-        * appropriate fields
-        * @param config PlatformConfig struct which has details such as modeType (server/client/both),
-        *               in-proc/out-of-proc etc.
-        */
-        OCPlatform(const PlatformConfig& config);
+         * API for overwriting the default configuration of the OCPlatform object.
+         * Note: Any calls made to this AFTER the first call to OCPlatform::Instance
+         * will have no affect
+         */
+        void Configure(const PlatformConfig& config);
 
-        /**
-        * Virtual destructor
-        */
-        virtual ~OCPlatform(void);
+        // typedef for handle to cancel presence info with
+        typedef OCDoHandle OCPresenceHandle;
 
         /**
         * API for notifying base that resource's attributes have changed.
@@ -111,21 +93,25 @@ namespace OC
         *
         * @param host - Host IP Address of a service to direct resource discovery query. If null or
         *        empty, performs multicast resource discovery query
-        * @param resourceURI - name of the resource. If null or empty, performs search for all resource names
+        * @param resourceURI - name of the resource. If null or empty, performs search for all
+        *       resource names
         * @param handler - Handles callbacks, success states and failure states.
         *
         *        Four modes of discovery defined as follows:
-        *        (NULL/Empty, NULL/Empty) - Performs ALL service discovery AND ALL resource discovery.
-        *        (NULL/Empty, Not Empty) - Performs query for a filtered/scoped/particular resource(s)
-        *                                  from ALL services.
+        *        (NULL/Empty, NULL/Empty) - Performs ALL service discovery AND ALL resource
+        *           discovery.
+        *        (NULL/Empty, Not Empty) - Performs query for a filtered/scoped/particular
+        *                                   resource(s) from ALL services.
         *        (Not Empty, NULL/Empty) - Performs ALL resource discovery on a particular service.
-        *        (Not Empty, Not Empty) - Performs query for a filtered/scoped/particular resource(s)
+        *        (Not Empty, Not Empty) - Performs query for a filtered/scoped/particular
+        *                                   resource(s)
         *                                  from a particular service.
         * @param QualityOfService the quality of communication
         *
         * @return OCStackResult return value of this API. Returns OC_STACK_OK if success.
-        * NOTE: First parameter 'host' currently represents an IP address. This will change in future
-        * and will refer to endpoint interface so that we can refer to other transports such as BTH etc.
+        * NOTE: First parameter 'host' currently represents an IP address. This will change in
+        * future and will refer to endpoint interface so that we can refer to other transports such
+        * as BTH etc.
         * NOTE: OCStackResult is defined in ocstack.h.
         */
         OCStackResult findResource(const std::string& host, const std::string& resourceURI,
@@ -145,16 +131,19 @@ namespace OC
         * @param resourceProperty - indicates the property of the resource. Defined in ocstack.h.
         * setting resourceProperty as OC_DISCOVERABLE will allow Discovery of this resource
         * setting resourceProperty as OC_OBSERVABLE will allow observation
-        * settings resourceProperty as OC_DISCOVERABLE | OC_OBSERVABLE will allow both discovery and observation
+        * settings resourceProperty as OC_DISCOVERABLE | OC_OBSERVABLE will allow both discovery and
+        * observation
         *
         * @return OCStackResult return value of this API. Returns OC_STACK_OK if success.
         * NOTE: "a/light" is a relative URI.
         * Above relative URI will be prepended (by core) with a host IP + namespace "oc"
         * Therefore, fully qualified URI format would be //HostIP-Address/namespace/relativeURI"
-        * Example, a relative URI: 'a/light' will result in a fully qualified URI: //192.168.1.1/oc/a/light"
-        * First parameter can take a relative URI and core will take care of preparing the fully qualified URI
-        * OR
-        * first paramter can take fully qualified URI and core will take that as is for further operations
+        * Example, a relative URI: 'a/light' will result in a fully qualified URI:
+        *   //192.168.1.1/oc/a/light"
+        * First parameter can take a relative URI and core will take care of preparing the fully
+        * qualified URI OR
+        * first paramter can take fully qualified URI and core will take that as is for further
+        * operations
         * NOTE: OCStackResult is defined in ocstack.h.
         */
         OCStackResult registerResource(OCResourceHandle& resourceHandle,
@@ -181,12 +170,13 @@ namespace OC
         * This API unregisters a resource with the server
         * NOTE: This API applies to server side only.
         *
-        * @param resourceHandle - This is the resource handle which we which to unregister from the server
+        * @param resourceHandle - This is the resource handle which we which to unregister from the
+        * server
         *
         * @return OCStackResult return value of this API. Returns OC_STACK_OK if success.
         * NOTE: OCStackResult is defined in ocstack.h.
         */
-        OCStackResult unregisterResource(const OCResourceHandle& resourceHandle) const;
+        OCStackResult unregisterResource(const OCResourceHandle& resourceHandle);
 
         /**
         * Add a resource to a collection resource.
@@ -199,32 +189,43 @@ namespace OC
         * NOTE: bindResource must be used only after the both collection resource and
         * resource to add under a collections are created and respective handles obtained<br>
         * <b>Example:</b> <br>
-        * Step 1: registerResource(homeResourceHandle, "a/home", "home", Link_Interface, entityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
-        * Step 2: registerResource(kitchenResourceHandle, "a/kitchen", "kitchen", Link_Interface, entityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
+        * Step 1: registerResource(homeResourceHandle, "a/home", "home", Link_Interface,
+        *   entityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
+        * Step 2: registerResource(kitchenResourceHandle, "a/kitchen", "kitchen", Link_Interface,
+        *   entityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
         * Step 3: bindResource(homeResourceHandle, kitchenResourceHandle);<br>
         * At the end of Step 3, resource "a/home" will contain a reference to "a/kitchen".<br>
         */
-        OCStackResult bindResource(const OCResourceHandle collectionHandle, const OCResourceHandle resourceHandle);
+        OCStackResult bindResource(const OCResourceHandle collectionHandle,
+                const OCResourceHandle resourceHandle);
 
         /**
         * Add multiple resources to a collection resource.
         *
         * @param collectionHandle - handle to the collection resource
-        * @param addedResourceHandleList reference to list of resource handles to be added to the collection resource
+        * @param addedResourceHandleList reference to list of resource handles to be added to the
+        *   collection resource
         *
         * @return OCStackResult return value of this API. Returns OC_STACK_OK if success. <br>
         * NOTE: OCStackResult is defined in ocstack.h. <br>
         * NOTE: bindResources must be used only after the both collection resource and
-        * list of resources to add under a collection are created and respective handles obtained <br>
+        * list of resources to add under a collection are created and respective handles
+        * obtained <br>
         * <b> Example: </b> <br>
-        * Step 1: registerResource(homeResourceHandle, "a/home", "home", Link_Interface, homeEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
-        * Step 2: registerResource(kitchenResourceHandle, "a/kitchen", "kitchen", Link_Interface, kitchenEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
-        * Step 3: registerResource(roomResourceHandle, "a/room", "room", Link_Interface, roomEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
-        * Step 4: std::vector<OCResourceHandle> rList; rList.push_back(kitchenResourceHandle); rList.push_back(roomResourceHandle);<br>
+        * Step 1: registerResource(homeResourceHandle, "a/home", "home", Link_Interface,
+        *   homeEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
+        * Step 2: registerResource(kitchenResourceHandle, "a/kitchen", "kitchen", Link_Interface,
+        *   kitchenEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
+        * Step 3: registerResource(roomResourceHandle, "a/room", "room", Link_Interface,
+        *   roomEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
+        * Step 4: std::vector<OCResourceHandle> rList; rList.push_back(kitchenResourceHandle);
+        *   rList.push_back(roomResourceHandle);<br>
         * Step 5: bindResource(homeResourceHandle, rList);<br>
-        * At the end of Step 5, resource "a/home" will contain a references to "a/kitchen" and "a/room" <br>
+        * At the end of Step 5, resource "a/home" will contain a references to "a/kitchen" and
+        *   "a/room" <br>
         */
-        OCStackResult bindResources(const OCResourceHandle collectionHandle, const std::vector<OCResourceHandle>& addedResourceHandleList);
+        OCStackResult bindResources(const OCResourceHandle collectionHandle,
+                const std::vector<OCResourceHandle>& addedResourceHandleList);
 
         /**
         * Unbind a resource from a collection resource.
@@ -237,35 +238,46 @@ namespace OC
         * NOTE: unbindResource must be used only after the both collection resource and
         * resource to unbind from a collection are created and respective handles obtained<br>
         * <b> Example </b> <br>
-        * Step 1: registerResource(homeResourceHandle, "a/home", "home", Link_Interface, entityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
-        * Step 2: registerResource(kitchenResourceHandle, "a/kitchen", "kitchen", Link_Interface, entityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
+        * Step 1: registerResource(homeResourceHandle, "a/home", "home", Link_Interface,
+        *   entityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
+        * Step 2: registerResource(kitchenResourceHandle, "a/kitchen", "kitchen", Link_Interface,
+        *   entityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
         * Step 3: bindResource(homeResourceHandle, kitchenResourceHandle);<br>
         * Step 4: unbindResource(homeResourceHandle, kitchenResourceHandle);<br>
         * At the end of Step 4, resource "a/home" will no longer reference "a/kitchen". <br>
         */
-        OCStackResult unbindResource(const OCResourceHandle collectionHandle, const OCResourceHandle resourceHandle);
+        OCStackResult unbindResource(const OCResourceHandle collectionHandle,
+                    const OCResourceHandle resourceHandle);
 
         /**
         * Unbind resources from a collection resource.
         *
         * @param collectionHandle - handle to the collection resource
-        * @param resourceHandleList List of resource handles to be unbound from the collection resource
+        * @param resourceHandleList List of resource handles to be unbound from the collection
+        *   resource
         *
         * @return OCStackResult return value of this API. Returns OC_STACK_OK if success. <br>
         *
         * NOTE: OCStackResult is defined in ocstack.h.<br>
         * NOTE: unbindResources must be used only after the both collection resource and
-        * list of resources resource to unbind from a collection are created and respective handles obtained. <br>
+        * list of resources resource to unbind from a collection are created and respective handles
+        *   obtained. <br>
         * <b>Example</b> <br>
-        * Step 1: registerResource(homeResourceHandle, "a/home", "home", Link_Interface, homeEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
-        * Step 2: registerResource(kitchenResourceHandle, "a/kitchen", "kitchen", Link_Interface, kitchenEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
-        * Step 3: registerResource(roomResourceHandle, "a/room", "room", Link_Interface, roomEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
-        * Step 4: std::vector<OCResourceHandle> rList; rList.push_back(kitchenResourceHandle); rList.push_back(roomResourceHandle);<br>
+        * Step 1: registerResource(homeResourceHandle, "a/home", "home", Link_Interface,
+        *   homeEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
+        * Step 2: registerResource(kitchenResourceHandle, "a/kitchen", "kitchen", Link_Interface,
+        *   kitchenEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
+        * Step 3: registerResource(roomResourceHandle, "a/room", "room", Link_Interface,
+        *   roomEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
+        * Step 4: std::vector<OCResourceHandle> rList; rList.push_back(kitchenResourceHandle);
+        *   rList.push_back(roomResourceHandle);<br>
         * Step 5: bindResource(homeResourceHandle, rList);<br>
         * Step 6: unbindResources(homeResourceHandle, rList);<br>
-        * At the end of Step 6, resource "a/home" will no longer reference to "a/kitchen" and "a/room"<br>
+        * At the end of Step 6, resource "a/home" will no longer reference to "a/kitchen" and
+        *   "a/room"<br>
         */
-        OCStackResult unbindResources(const OCResourceHandle collectionHandle, const std::vector<OCResourceHandle>& resourceHandleList);
+        OCStackResult unbindResources(const OCResourceHandle collectionHandle,
+                        const std::vector<OCResourceHandle>& resourceHandleList);
 
         /**
         * Binds a type to a particular resource
@@ -275,7 +287,7 @@ namespace OC
         * @return OCStackResult - return value of the API. Returns OCSTACK_OK if success <br>
         */
         OCStackResult bindTypeToResource(const OCResourceHandle& resourceHandle,
-                        const std::string& resourceTypeName) const;
+                        const std::string& resourceTypeName);
 
         /**
         * Binds an interface to a particular resource
@@ -285,9 +297,9 @@ namespace OC
         * @return OCStackResult - return value of the API. Returns OCSTACK_OK if success <br>
         */
         OCStackResult bindInterfaceToResource(const OCResourceHandle& resourceHandle,
-                        const std::string& resourceInterfaceName) const;
+                        const std::string& resourceInterfaceName);
+
 
-        public:
         /**
         * Start Presence announcements.
         *
@@ -323,7 +335,8 @@ namespace OC
         *               request.  It can be used to unsubscribe from these events in the future.
         *               It will be set upon successful return of this method.
         * @param host - The IP address/addressable name of the server to subscribe to.
-        * @param presenceHandler - callback function that will receive notifications/subscription events
+        * @param presenceHandler - callback function that will receive notifications/subscription
+        *               events
         *
         * @return OCStackResult - return value of the API.  Returns OCSTACK_OK if success <br>
         */
@@ -335,8 +348,8 @@ namespace OC
         * you may for a short time still receive events from the server since it may take time
         * for the unsubscribe to take effect.
         *
-        * @param presenceHandle - the handle object provided by the subscribePresence call that identifies
-        *               this subscription.
+        * @param presenceHandle - the handle object provided by the subscribePresence call that
+        *               identifies this subscription.
         *
         * @return OCStackResult - return value of the API.  Returns OCSTACK_OK if success <br>
         */
@@ -370,30 +383,7 @@ namespace OC
         OCResource::Ptr constructResourceObject(const std::string& host, const std::string& uri,
                         bool isObservable, const std::vector<std::string>& resourceTypes,
                         const std::vector<std::string>& interfaces);
-
-    private:
-        PlatformConfig m_cfg;
-
-    private:
-        std::unique_ptr<WrapperFactory> m_WrapperInstance;
-        IServerWrapper::Ptr m_server;
-        IClientWrapper::Ptr m_client;
-        std::shared_ptr<std::recursive_mutex> m_csdkLock;
-
-    private:
-        /**
-        *  Private function to initalize the platfrom
-        */
-        void init(const PlatformConfig& config);
-
-        /**
-         * Private constructor/operators to prevent copying
-         * of this object
-         */
-        OCPlatform(const OCPlatform& other)= delete;
-        OCPlatform& operator=(const OCPlatform&) = delete;
-        OCPlatform& operator=(const OCPlatform&&) = delete;
-    };
+    }
 }
 
 #endif //__OCPLATFORM_H
diff --git a/include/OCPlatformHandler.h b/include/OCPlatformHandler.h
deleted file mode 100644 (file)
index 4fa6d2d..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-//******************************************************************
-//
-// Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//      http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-/// @file OCPlatformHandler.h 
-
-/// @brief     This file contains the declaration of classes and its members related to 
-///                    OCPlatformHandler.
-
-#ifndef __OCPLATFORMHANDLER_H
-#define __OCPLATFORMHANDLER_H
-
-#include "OCApi.h"
-
-namespace OC
-{
-       class OCPlatform;
-
-       /**
-       * @brief        OCPlatformHandler is a pure abstract class and it can be used for 
-       *                       registering and getting callbacks
-       */
-       class OCPlatformHandler
-       {
-       public:
-               OCPlatformHandler(void);
-
-               virtual ~OCPlatformHandler(void);
-
-               /**
-               * @fn   This function is called when the platform gets initialzed
-               * 
-               * @param platform pointer to OCPlatform object
-               */
-               virtual void onPlatformInitialized(OCPlatform *platform) = 0;
-
-               /**
-               * @fn   This function is called when platform status is changed
-               * 
-               * @param platform - pointer to OCPlatform object
-               * @param status - OCPlatform status
-               */
-               virtual void onPlatformStatusChanged(OCPlatform *platform, OCPlatformStatus status) = 0;
-       };
-}
-
-#endif // __OCPLATFORMHANDLER_H
diff --git a/include/OCPlatform_impl.h b/include/OCPlatform_impl.h
new file mode 100644 (file)
index 0000000..27e383b
--- /dev/null
@@ -0,0 +1,445 @@
+//******************************************************************
+//
+// Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+/// @file OCPlatform_impl.h
+
+/// @brief Implementation of the OCPlatform functionality.  It contains
+/// a singleton interface that is used only by the OCPlatform namespace and is the
+/// central entrance to the stack.
+
+#ifndef __OCPLATFORM_IMPL_H
+#define __OCPLATFORM_IMPL_H
+
+#include <map>
+
+#include "OCApi.h"
+#include "OCResource.h"
+#include "WrapperFactory.h"
+#include "OCResourceRequest.h"
+#include "OCResourceResponse.h"
+#include "OCRepresentation.h"
+
+#include "oc_logger.hpp"
+
+namespace OC
+{
+    /**
+    *   @brief Both server and client must initialize the core platform by instantiating OCPlatform.
+    *          On successful initialization, an instance of the OCPlatform is returned.
+    *          APIs in OCPlatform provide mechanism to register a resource and host the resource
+    *          on the server, find resources on the network etc.
+    */
+    class OCPlatform_impl
+    {
+    private:
+        static PlatformConfig& globalConfig();
+    public:
+        /**
+         * API for overwriting the default configuration of the OCPlatform object.
+         * Note: Any calls made to this AFTER the first call to OCPlatform::Instance
+         * will have no affect
+         */
+        static void Configure(const PlatformConfig& config);
+
+        /**
+         * API for retrieving the current OCPlatform object.  This will use the
+         * default platform config, unless the default is over-written using the
+         * Configure method before the first call to instance.
+         */
+        static OCPlatform_impl& Instance();
+
+    public:
+        // typedef for handle to cancel presence info with
+        typedef OCDoHandle OCPresenceHandle;
+
+        /**
+        * Virtual destructor
+        */
+        virtual ~OCPlatform_impl(void);
+
+        /**
+        * API for notifying base that resource's attributes have changed.
+        *
+        * @param OCResourceHandle resource handle of the resource
+        * @param QualityOfService the quality of communication
+        *
+        * @return OCStackResult return value of this API. Returns OC_STACK_OK if success.
+        * NOTE: This API is for server side only.
+        * NOTE: OCResourceHandle is defined in ocstack.h.
+        * NOTE: OCStackResult is defined in ocstack.h.
+        */
+        OCStackResult notifyAllObservers(OCResourceHandle resourceHandle);
+        OCStackResult notifyAllObservers(OCResourceHandle resourceHandle, QualityOfService QoS);
+
+        /**
+        * API for notifying only specific clients that resource's attributes have changed.
+        *
+        * @param OCResourceHandle resource handle of the resource
+        * @param observationIds std vector of observationIds. These set of ids are ones which
+        * which will be notified upon resource change.
+        * @param responsePtr OCResourceResponse pointer used by app to fill the response for this
+        * resource change.
+        * @param QualityOfService the quality of communication
+        *
+        * @return OCStackResult return value of this API. Returns OC_STACK_OK if success.
+        *
+        * NOTE: This API is for server side only.
+        * NOTE: OCResourceHandle is defined in ocstack.h.
+        * NOTE: OCStackResult is defined in ocstack.h.
+        */
+        OCStackResult notifyListOfObservers(
+                    OCResourceHandle resourceHandle,
+                    ObservationIds& observationIds,
+                    const std::shared_ptr<OCResourceResponse> responsePtr);
+        OCStackResult notifyListOfObservers(
+                    OCResourceHandle resourceHandle,
+                    ObservationIds& observationIds,
+                    const std::shared_ptr<OCResourceResponse> responsePtr,
+                    QualityOfService QoS);
+
+        /**
+        * API for Service and Resource Discovery.
+        * NOTE: This API applies to client side only.
+        *
+        * @param host - Host IP Address of a service to direct resource discovery query. If null or
+        *        empty, performs multicast resource discovery query
+        * @param resourceURI - name of the resource. If null or empty, performs search for all
+        *        resource names
+        * @param handler - Handles callbacks, success states and failure states.
+        *
+        *        Four modes of discovery defined as follows:
+        *        (NULL/Empty, NULL/Empty) - Performs ALL service discovery AND ALL resource
+        *                                   discovery.
+        *        (NULL/Empty, Not Empty) - Performs query for a filtered/scoped/particular
+        *                                   resource(s) from ALL services.
+        *        (Not Empty, NULL/Empty) - Performs ALL resource discovery on a particular service.
+        *        (Not Empty, Not Empty) - Performs query for a filtered/scoped/particular
+        *                                   resource(s) from a particular service.
+        * @param QualityOfService the quality of communication
+        *
+        * @return OCStackResult return value of this API. Returns OC_STACK_OK if success.
+        * NOTE: First parameter 'host' currently represents an IP address. This will change in
+        * future and will refer to endpoint interface so that we can refer to other transports such
+        * as BTH etc.
+        * NOTE: OCStackResult is defined in ocstack.h.
+        */
+        OCStackResult findResource(const std::string& host, const std::string& resourceURI,
+                    FindCallback resourceHandler);
+        OCStackResult findResource(const std::string& host, const std::string& resourceURI,
+                    FindCallback resourceHandler, QualityOfService QoS);
+
+        /**
+        * This API registers a resource with the server
+        * NOTE: This API applies to server side only.
+        *
+        * @param resourceHandle - Upon successful registration, resourceHandle will be filled
+        * @param resourceURI - The URI of the resource. Example: "a/light". See NOTE below
+        * @param resourceTypeName - The resource type. Example: "light"
+        * @param resourceInterface - The resource interface (whether it is collection etc).
+        * @param entityHandler - entity handler callback.
+        * @param resourceProperty - indicates the property of the resource. Defined in ocstack.h.
+        * setting resourceProperty as OC_DISCOVERABLE will allow Discovery of this resource
+        * setting resourceProperty as OC_OBSERVABLE will allow observation
+        * settings resourceProperty as OC_DISCOVERABLE | OC_OBSERVABLE will allow both discovery
+        * and observation
+        *
+        * @return OCStackResult return value of this API. Returns OC_STACK_OK if success.
+        * NOTE: "a/light" is a relative URI.
+        * Above relative URI will be prepended (by core) with a host IP + namespace "oc"
+        * Therefore, fully qualified URI format would be //HostIP-Address/namespace/relativeURI"
+        * Example, a relative URI: 'a/light' will result in a fully qualified URI:
+        *   //192.168.1.1/oc/a/light"
+        * First parameter can take a relative URI and core will take care of preparing the fully
+        * qualified URI OR
+        * first paramter can take fully qualified URI and core will take that as is for further
+        * operations
+        * NOTE: OCStackResult is defined in ocstack.h.
+        */
+        OCStackResult registerResource(OCResourceHandle& resourceHandle,
+                        std::string& resourceURI,
+                        const std::string& resourceTypeName,
+                        const std::string& resourceInterface,
+                        EntityHandler entityHandler,
+                        uint8_t resourceProperty);
+
+        /**
+        * Set default device entity handler
+        *
+        * @param entityHandler - entity handler to handle requests for
+        *                        any undefined resources or default actions.
+        *                        if NULL is passed it removes the device default entity handler.
+        *
+        * @return
+        *     OC_STACK_OK    - no errors
+        *     OC_STACK_ERROR - stack process error
+        */
+        OCStackResult setDefaultDeviceEntityHandler(EntityHandler entityHandler);
+
+        /**
+        * This API unregisters a resource with the server
+        * NOTE: This API applies to server side only.
+        *
+        * @param resourceHandle - This is the resource handle which we which to unregister from the
+        *                           server
+        *
+        * @return OCStackResult return value of this API. Returns OC_STACK_OK if success.
+        * NOTE: OCStackResult is defined in ocstack.h.
+        */
+        OCStackResult unregisterResource(const OCResourceHandle& resourceHandle) const;
+
+        /**
+        * Add a resource to a collection resource.
+        *
+        * @param collectionHandle - handle to the collection resource
+        * @param addedResourceHandle - handle to resource to be added to the collection resource
+        *
+        * @return OCStackResult return value of this API. Returns OC_STACK_OK if success.<br>
+        * NOTE: OCStackResult is defined in ocstack.h. <br>
+        * NOTE: bindResource must be used only after the both collection resource and
+        * resource to add under a collections are created and respective handles obtained<br>
+        * <b>Example:</b> <br>
+        * Step 1: registerResource(homeResourceHandle, "a/home", "home", Link_Interface,
+        *               entityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
+        * Step 2: registerResource(kitchenResourceHandle, "a/kitchen", "kitchen", Link_Interface,
+        *               entityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
+        * Step 3: bindResource(homeResourceHandle, kitchenResourceHandle);<br>
+        * At the end of Step 3, resource "a/home" will contain a reference to "a/kitchen".<br>
+        */
+        OCStackResult bindResource(const OCResourceHandle collectionHandle,
+                    const OCResourceHandle resourceHandle);
+
+        /**
+        * Add multiple resources to a collection resource.
+        *
+        * @param collectionHandle - handle to the collection resource
+        * @param addedResourceHandleList reference to list of resource handles to be added to
+        *       the collection resource
+        *
+        * @return OCStackResult return value of this API. Returns OC_STACK_OK if success. <br>
+        * NOTE: OCStackResult is defined in ocstack.h. <br>
+        * NOTE: bindResources must be used only after the both collection resource and
+        * list of resources to add under a collection are created and respective handles
+        * obtained<br>
+        * <b> Example: </b> <br>
+        * Step 1: registerResource(homeResourceHandle, "a/home", "home", Link_Interface,
+        *           homeEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
+        * Step 2: registerResource(kitchenResourceHandle, "a/kitchen", "kitchen", Link_Interface,
+        *           kitchenEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
+        * Step 3: registerResource(roomResourceHandle, "a/room", "room", Link_Interface,
+        *           roomEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
+        * Step 4: std::vector<OCResourceHandle> rList; rList.push_back(kitchenResourceHandle);
+        *           rList.push_back(roomResourceHandle);<br>
+        * Step 5: bindResource(homeResourceHandle, rList);<br>
+        * At the end of Step 5, resource "a/home" will contain a references to "a/kitchen"
+        *           and "a/room" <br>
+        */
+        OCStackResult bindResources(const OCResourceHandle collectionHandle,
+                    const std::vector<OCResourceHandle>& addedResourceHandleList);
+
+        /**
+        * Unbind a resource from a collection resource.
+        *
+        * @param collectionHandle - handle to the collection resource
+        * @param resourceHandle resource handle to be unbound from the collection resource
+        *
+        * @return OCStackResult return value of this API. Returns OC_STACK_OK if success. <br>
+        * NOTE: OCStackResult is defined in ocstack.h.<br>
+        * NOTE: unbindResource must be used only after the both collection resource and
+        * resource to unbind from a collection are created and respective handles obtained<br>
+        * <b> Example </b> <br>
+        * Step 1: registerResource(homeResourceHandle, "a/home", "home", Link_Interface,
+        *       entityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
+        * Step 2: registerResource(kitchenResourceHandle, "a/kitchen", "kitchen", Link_Interface,
+        *       entityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
+        * Step 3: bindResource(homeResourceHandle, kitchenResourceHandle);<br>
+        * Step 4: unbindResource(homeResourceHandle, kitchenResourceHandle);<br>
+        * At the end of Step 4, resource "a/home" will no longer reference "a/kitchen". <br>
+        */
+        OCStackResult unbindResource(const OCResourceHandle collectionHandle,
+                    const OCResourceHandle resourceHandle);
+
+        /**
+        * Unbind resources from a collection resource.
+        *
+        * @param collectionHandle - handle to the collection resource
+        * @param resourceHandleList List of resource handles to be unbound from the collection
+        *   resource
+        *
+        * @return OCStackResult return value of this API. Returns OC_STACK_OK if success. <br>
+        *
+        * NOTE: OCStackResult is defined in ocstack.h.<br>
+        * NOTE: unbindResources must be used only after the both collection resource and
+        * list of resources resource to unbind from a collection are created and respective handles
+        * obtained. <br>
+        * <b>Example</b> <br>
+        * Step 1: registerResource(homeResourceHandle, "a/home", "home", Link_Interface,
+        *       homeEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
+        * Step 2: registerResource(kitchenResourceHandle, "a/kitchen", "kitchen", Link_Interface,
+        *       kitchenEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
+        * Step 3: registerResource(roomResourceHandle, "a/room", "room", Link_Interface,
+        *       roomEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
+        * Step 4: std::vector<OCResourceHandle> rList; rList.push_back(kitchenResourceHandle);
+        *       rList.push_back(roomResourceHandle);<br>
+        * Step 5: bindResource(homeResourceHandle, rList);<br>
+        * Step 6: unbindResources(homeResourceHandle, rList);<br>
+        * At the end of Step 6, resource "a/home" will no longer reference to "a/kitchen"
+        *       and "a/room"<br>
+        */
+        OCStackResult unbindResources(const OCResourceHandle collectionHandle,
+                        const std::vector<OCResourceHandle>& resourceHandleList);
+
+        /**
+        * Binds a type to a particular resource
+        * @param resourceHandle - handle to the resource
+        * @param resourceTypeName - new typename to bind to the resource
+
+        * @return OCStackResult - return value of the API. Returns OCSTACK_OK if success <br>
+        */
+        OCStackResult bindTypeToResource(const OCResourceHandle& resourceHandle,
+                        const std::string& resourceTypeName) const;
+
+        /**
+        * Binds an interface to a particular resource
+        * @param resourceHandle - handle to the resource
+        * @param resourceTypeName - new interface  to bind to the resource
+
+        * @return OCStackResult - return value of the API. Returns OCSTACK_OK if success <br>
+        */
+        OCStackResult bindInterfaceToResource(const OCResourceHandle& resourceHandle,
+                        const std::string& resourceInterfaceName) const;
+
+        /**
+        * Start Presence announcements.
+        *
+        * @param ttl - time to live
+        * @return OCStackResult - Returns OCSTACK_OK if success <br>
+        *
+        * Server can call this function when it comes online for the
+        * first time, or when it comes back online from offline mode,
+        * or when it re enters network.
+        *
+        */
+        OCStackResult startPresence(const unsigned int ttl);
+
+        /**
+        * Stop Presence announcements.
+        *
+        * @return OCStackResult - Returns OCSTACK_OK if success <br>
+        *
+        * Server can call this function when it is terminating,
+        * going offline, or when going away from network.
+        *
+        */
+        OCStackResult stopPresence();
+
+        /**
+        * subscribes to a server's presence change events.  By making this subscription,
+        * every time a server adds/removes/alters a resource, starts or is intentionally
+        * stopped (potentially more to be added later).
+        *
+        * @param presenceHandle - a handle object that can be used to identify this subscription
+        *               request.  It can be used to unsubscribe from these events in the future.
+        *               It will be set upon successful return of this method.
+        * @param host - The IP address/addressable name of the server to subscribe to.
+        * @param presenceHandler - callback function that will receive notifications/subscription
+        *                           events
+        *
+        * @return OCStackResult - return value of the API.  Returns OCSTACK_OK if success <br>
+        */
+        OCStackResult subscribePresence(OCPresenceHandle& presenceHandle, const std::string& host,
+                        SubscribeCallback presenceHandler);
+
+        /**
+        * unsubscribes from a previously subscribed server's presence events. Note that
+        * you may for a short time still receive events from the server since it may take time
+        * for the unsubscribe to take effect.
+        *
+        * @param presenceHandle - the handle object provided by the subscribePresence call that
+        *               identifies this subscription.
+        *
+        * @return OCStackResult - return value of the API.  Returns OCSTACK_OK if success <br>
+        */
+        OCStackResult unsubscribePresence(OCPresenceHandle presenceHandle);
+
+        /**
+        * Creates a resource proxy object so that get/put/observe functionality
+        * can be used without discovering the object in advance.  Note that the
+        * consumer of this method needs to provide all of the details required to
+        * correctly contact and observe the object. If the consumer lacks any of
+        * this information, they should discover the resource object normally.
+        * Additionally, you can only create this object if OCPlatform was initialized
+        * to be a Client or Client/Server.  Otherwise, this will return an empty
+        * shared ptr.
+        *
+        * @param host - a string containing a resolvable host address of the server
+        *           holding the resource. Currently this should be in the format
+        *           coap://address:port, though in the future, we expect this to
+        *           change to //address:port
+        *
+        * @param uri - the rest of the resource's URI that will permit messages to be
+        *           properly routed.  Example: /a/light
+        *
+        * @param isObservable - a boolean containing whether the resource supports observation
+        *
+        * @param resourceTypes - a collection of resource types implemented by the resource
+        *
+        * @param interfaces - a collection of interfaces that the resource supports/implements
+        * @return OCResource::Ptr - a shared pointer to the new resource object
+        */
+        OCResource::Ptr constructResourceObject(const std::string& host, const std::string& uri,
+                        bool isObservable, const std::vector<std::string>& resourceTypes,
+                        const std::vector<std::string>& interfaces);
+
+    private:
+        PlatformConfig m_cfg;
+
+    private:
+        std::unique_ptr<WrapperFactory> m_WrapperInstance;
+        IServerWrapper::Ptr m_server;
+        IClientWrapper::Ptr m_client;
+        std::shared_ptr<std::recursive_mutex> m_csdkLock;
+
+    private:
+        /**
+        * Constructor for OCPlatform. Constructs a new OCPlatform from a given PlatformConfig with
+        * appropriate fields
+        * @param config PlatformConfig struct which has details such as modeType
+        * (server/client/both), in-proc/out-of-proc etc.
+        */
+        OCPlatform_impl(const PlatformConfig& config);
+
+        /**
+        *  Private function to initalize the platfrom
+        */
+        void init(const PlatformConfig& config);
+
+        /**
+         * Private constructor/operators to prevent copying
+         * of this object
+         */
+        OCPlatform_impl(const OCPlatform_impl& other)= delete;
+        OCPlatform_impl& operator=(const OCPlatform_impl&) = delete;
+        OCPlatform_impl& operator=(const OCPlatform_impl&&) = delete;
+    };
+}
+
+#endif //__OCPLATFORM_IMPL_H
+
+
index db4f80c..5d5802c 100644 (file)
@@ -51,7 +51,7 @@ namespace OC
     */
     class OCResource
     {
-    friend class OCPlatform;
+    friend class OCPlatform_impl;
     friend class InProcClientWrapper;
 
     public:
index 8580d2b..4f88207 100644 (file)
@@ -28,7 +28,7 @@ namespace OC
     class OutOfProcClientWrapper : public IClientWrapper
     {
     public:
-        OutOfProcClientWrapper(OC::OCPlatform& owner, std::weak_ptr<std::recursive_mutex> csdkLock,
+        OutOfProcClientWrapper(OC::OCPlatform_impl& owner, std::weak_ptr<std::recursive_mutex> csdkLock,
                                 PlatformConfig cfg)
          : IClientWrapper(owner)
         {}
index a3bf64d..0e7666e 100644 (file)
@@ -28,7 +28,7 @@ namespace OC
     class OutOfProcServerWrapper : public IServerWrapper
     {
     public:
-        OutOfProcServerWrapper(OC::OCPlatform& owner, PlatformConfig cfg)
+        OutOfProcServerWrapper(OC::OCPlatform_impl& owner, PlatformConfig cfg)
          : IServerWrapper(owner)
         {};
 
index c4923e4..5aa23a2 100644 (file)
@@ -39,9 +39,9 @@ namespace OC
     public:
         typedef std::shared_ptr<IWrapperFactory> Ptr;
 
-        virtual IClientWrapper::Ptr CreateClientWrapper(OC::OCPlatform& owner,
+        virtual IClientWrapper::Ptr CreateClientWrapper(OC::OCPlatform_impl& owner,
             std::weak_ptr<std::recursive_mutex> csdkLock, PlatformConfig cfg) =0;
-        virtual IServerWrapper::Ptr CreateServerWrapper(OC::OCPlatform& owner,
+        virtual IServerWrapper::Ptr CreateServerWrapper(OC::OCPlatform_impl& owner,
             std::weak_ptr<std::recursive_mutex> csdkLock, PlatformConfig cfg) =0;
         virtual ~IWrapperFactory(){}
     };
@@ -52,7 +52,7 @@ namespace OC
     public:
         WrapperFactory(){}
 
-        virtual IClientWrapper::Ptr CreateClientWrapper(OC::OCPlatform& owner,
+        virtual IClientWrapper::Ptr CreateClientWrapper(OC::OCPlatform_impl& owner,
             std::weak_ptr<std::recursive_mutex> csdkLock, PlatformConfig cfg)
         {
             switch(cfg.serviceType)
@@ -67,7 +67,7 @@ namespace OC
                        return nullptr;
         }
 
-        virtual IServerWrapper::Ptr CreateServerWrapper(OC::OCPlatform& owner,
+        virtual IServerWrapper::Ptr CreateServerWrapper(OC::OCPlatform_impl& owner,
             std::weak_ptr<std::recursive_mutex> csdkLock, PlatformConfig cfg)
         {
             switch(cfg.serviceType)
index f93c3c8..3d3d3bd 100644 (file)
--- a/makefile
+++ b/makefile
@@ -70,8 +70,11 @@ cpp_sdk: prep_dirs c_sdk liboc.a
 examples: liboc.a
        cd examples && $(MAKE) apps "BUILD=$(BUILD)"
 
-liboc.a: OCPlatform.o OCResource.o OCException.o OCUtilities.o InProcServerWrapper.o InProcClientWrapper.o
-       ar -cvq $(OBJ_DIR)/liboc.a $(OBJ_DIR)/OCPlatform.o $(OBJ_DIR)/OCResource.o $(OBJ_DIR)/OCException.o $(OBJ_DIR)/OCUtilities.o $(OBJ_DIR)/InProcServerWrapper.o $(OBJ_DIR)/InProcClientWrapper.o
+liboc.a: OCPlatform_impl.o OCPlatform.o OCResource.o OCException.o OCUtilities.o InProcServerWrapper.o InProcClientWrapper.o
+       ar -cvq $(OBJ_DIR)/liboc.a $(OBJ_DIR)/OCPlatform_impl.o $(OBJ_DIR)/OCPlatform.o $(OBJ_DIR)/OCResource.o $(OBJ_DIR)/OCException.o $(OBJ_DIR)/OCUtilities.o $(OBJ_DIR)/InProcServerWrapper.o $(OBJ_DIR)/InProcClientWrapper.o
+
+OCPlatform_impl.o: src/OCPlatform_impl.cpp
+       $(CXX) $(CXX_FLAGS.$(BUILD)) -o $(OBJ_DIR)/$@ -c src/OCPlatform_impl.cpp $(CXX_INC)
 
 OCPlatform.o: src/OCPlatform.cpp
        $(CXX) $(CXX_FLAGS.$(BUILD)) -o $(OBJ_DIR)/$@ -c src/OCPlatform.cpp $(CXX_INC)
index 0526ab4..a56833a 100644 (file)
@@ -30,7 +30,7 @@ using namespace std;
 
 namespace OC
 {
-    InProcClientWrapper::InProcClientWrapper(OC::OCPlatform& owner,
+    InProcClientWrapper::InProcClientWrapper(OC::OCPlatform_impl& owner,
         std::weak_ptr<std::recursive_mutex> csdkLock, PlatformConfig cfg)
             : IClientWrapper(owner),
               m_threadRun(false), m_csdkLock(csdkLock),
@@ -115,7 +115,6 @@ namespace OC
     {
         FindCallback              callback;
         IClientWrapper::Ptr       clientWrapper;
-        OC::OCPlatform const*     owner;          // observing ptr
     };
 
 
@@ -220,7 +219,6 @@ namespace OC
         ListenContext* context = new ListenContext();
         context->callback = callback;
         context->clientWrapper = shared_from_this();
-        context->owner = &m_owner;
 
         cbdata.context =  static_cast<void*>(context);
         cbdata.cb = listenCallback;
index 6f68b1a..80a3d7f 100644 (file)
@@ -280,7 +280,7 @@ OCEntityHandlerResult EntityHandlerWrapper(OCEntityHandlerFlag flag,
 
 namespace OC
 {
-    InProcServerWrapper::InProcServerWrapper(OC::OCPlatform& owner,
+    InProcServerWrapper::InProcServerWrapper(OC::OCPlatform_impl& owner,
         std::weak_ptr<std::recursive_mutex> csdkLock, PlatformConfig cfg)
      : IServerWrapper(owner),
        m_csdkLock(csdkLock)
index bf254a6..6c7691e 100644 (file)
 //
 //
 //*********************************************************************
-
-#include <random>
-#include <utility>
-#include <functional>
-
-#include "ocstack.h"
-
-#include "OCPlatform.h"
-#include "OCApi.h"
-#include "OCException.h"
-#include "OCUtilities.h"
-
-#include "oc_logger.hpp"
-
+#include <OCPlatform.h>
 namespace OC
 {
-void OCPlatform::init(const PlatformConfig& config)
-{
-    switch(config.mode)
-     {
-       case ModeType::Server:
-                       m_server = m_WrapperInstance->CreateServerWrapper(*this, m_csdkLock, config);
-                       break;
-
-       case ModeType::Client:
-                      m_client = m_WrapperInstance->CreateClientWrapper(*this, m_csdkLock, config);
-                      break;
-
-       case ModeType::Both:
-                       m_server = m_WrapperInstance->CreateServerWrapper(*this, m_csdkLock, config);
-                       m_client = m_WrapperInstance->CreateClientWrapper(*this, m_csdkLock, config);
-                       break;
-     }
-}
-
-OCPlatform::OCPlatform(const PlatformConfig& config)
- : m_cfg             { config },
-   m_WrapperInstance { make_unique<WrapperFactory>() },
-   m_csdkLock        { make_shared<std::recursive_mutex>() }
-{
-    init(m_cfg);
-}
-
-OCPlatform::~OCPlatform(void)
-{
-}
-
-OCStackResult OCPlatform::setDefaultDeviceEntityHandler(EntityHandler entityHandler)
-{
-    return checked_guard(m_server, &IServerWrapper::setDefaultDeviceEntityHandler,
-                         entityHandler);
-}
-
-OCStackResult OCPlatform::notifyAllObservers(OCResourceHandle resourceHandle, QualityOfService QoS)
-{
-    return result_guard(OCNotifyAllObservers(resourceHandle, static_cast<OCQualityOfService>(QoS)));
-}
-
-OCStackResult OCPlatform::notifyAllObservers(OCResourceHandle resourceHandle)
-{
-    return notifyAllObservers(resourceHandle, m_cfg.QoS);
-}
-
-OCStackResult OCPlatform::notifyListOfObservers(OCResourceHandle resourceHandle,
-                                            ObservationIds& observationIds,
-                                            const std::shared_ptr<OCResourceResponse> pResponse)
-{
-    return notifyListOfObservers(resourceHandle, observationIds, pResponse, m_cfg.QoS);
-}
-
-OCStackResult OCPlatform::notifyListOfObservers(OCResourceHandle resourceHandle,
-                                            ObservationIds& observationIds,
-                                            const std::shared_ptr<OCResourceResponse> pResponse,
-                                            QualityOfService QoS)
-{
-    if(!pResponse)
-    {
-     return result_guard(OC_STACK_ERROR);
-    }
-
-    std::string payload(pResponse->getPayload());
-
-    return result_guard(
-               OCNotifyListOfObservers(resourceHandle,
-                                       &observationIds[0], observationIds.size(),
-                                       reinterpret_cast<unsigned char *>(const_cast<char *>(payload.c_str())),
-                                       static_cast<OCQualityOfService>(QoS)));
-}
-
-OCResource::Ptr OCPlatform::constructResourceObject(const std::string& host, const std::string& uri,
-                                                    bool isObservable, const std::vector<std::string>& resourceTypes,
-                                                    const std::vector<std::string>& interfaces)
-{
-    if(!m_client)
+    namespace OCPlatform
     {
-        return std::shared_ptr<OCResource>();
-    }
-
-    return std::shared_ptr<OCResource>(new OCResource(m_client, host, uri, isObservable, resourceTypes, interfaces));
-}
-
-OCStackResult OCPlatform::findResource(const std::string& host, const std::string& resourceName,
-                                       FindCallback resourceHandler)
-{
-    return findResource(host, resourceName, resourceHandler, m_cfg.QoS);
-}
-
-OCStackResult OCPlatform::findResource(const std::string& host, const std::string& resourceName,
-                                       FindCallback resourceHandler, QualityOfService QoS)
-{
-    return checked_guard(m_client, &IClientWrapper::ListenForResource,
-                         host, resourceName, resourceHandler, QoS);
-}
-
-
-OCStackResult OCPlatform::registerResource(OCResourceHandle& resourceHandle,
-                                           std::string& resourceURI,
-                                           const std::string& resourceTypeName,
-                                           const std::string& resourceInterface,
-                                           EntityHandler entityHandler,
-                                           uint8_t resourceProperty)
-{
-    return checked_guard(m_server, &IServerWrapper::registerResource,
-                         ref(resourceHandle), resourceURI, resourceTypeName,
-                         resourceInterface, entityHandler, resourceProperty);
-}
-
-OCStackResult OCPlatform::unregisterResource(const OCResourceHandle& resourceHandle) const
-{
-    return checked_guard(m_server, &IServerWrapper::unregisterResource,
-                         resourceHandle);
-}
-
-OCStackResult OCPlatform::unbindResource(OCResourceHandle collectionHandle, OCResourceHandle resourceHandle)
-{
-    return result_guard(OCUnBindResource(ref(collectionHandle), ref(resourceHandle)));
-}
-
-OCStackResult OCPlatform::unbindResources(const OCResourceHandle collectionHandle, const std::vector<OCResourceHandle>& resourceHandles)
-{
-    for(const auto& h : resourceHandles)
-    {
-       OCStackResult r;
-
-       if(OC_STACK_OK != (r = result_guard(OCUnBindResource(collectionHandle, h))))
-       {
-           return r;
-       }
-    }
-
-    return OC_STACK_OK;
-}
-
-OCStackResult OCPlatform::bindResource(const OCResourceHandle collectionHandle, const OCResourceHandle resourceHandle)
-{
-    return result_guard(OCBindResource(collectionHandle, resourceHandle));
-}
-
-OCStackResult OCPlatform::bindResources(const OCResourceHandle collectionHandle, const std::vector<OCResourceHandle>& resourceHandles)
-{
-    for(const auto& h : resourceHandles)
-    {
-       OCStackResult r;
-
-       if(OC_STACK_OK != (r = result_guard(OCBindResource(collectionHandle, h))))
-       {
-           return r;
-       }
-    }
-
-    return OC_STACK_OK;
-}
-
-OCStackResult OCPlatform::bindTypeToResource(const OCResourceHandle& resourceHandle,
-                                             const std::string& resourceTypeName) const
-{
-    return checked_guard(m_server, &IServerWrapper::bindTypeToResource,
-                         resourceHandle, resourceTypeName);
-}
-
-OCStackResult OCPlatform::bindInterfaceToResource(const OCResourceHandle& resourceHandle,
-                                                  const std::string& resourceInterfaceName) const
-{
-    return checked_guard(m_server, &IServerWrapper::bindInterfaceToResource,
-                         resourceHandle, resourceInterfaceName);
-}
-
-OCStackResult OCPlatform::startPresence(const unsigned int announceDurationSeconds)
-{
-    return checked_guard(m_server, &IServerWrapper::startPresence,
-                         announceDurationSeconds);
-}
-
-OCStackResult OCPlatform::stopPresence()
-{
-    return checked_guard(m_server, &IServerWrapper::stopPresence);
-}
-
-OCStackResult OCPlatform::subscribePresence(OCPresenceHandle& presenceHandle, const std::string& host,
-                                            SubscribeCallback presenceHandler)
-{
-    return checked_guard(m_client, &IClientWrapper::SubscribePresence,
-                         &presenceHandle, host, presenceHandler);
-}
-
-OCStackResult OCPlatform::unsubscribePresence(OCPresenceHandle presenceHandle)
-{
-    return checked_guard(m_client, &IClientWrapper::UnsubscribePresence,
-                         ref(presenceHandle));
-}
-
+        void Configure(const PlatformConfig& config)
+        {
+            OCPlatform_impl::Configure(config);
+        }
+
+        OCStackResult setDefaultDeviceEntityHandler(EntityHandler entityHandler)
+        {
+            return OCPlatform_impl::Instance().setDefaultDeviceEntityHandler(entityHandler);
+        }
+
+        OCStackResult notifyAllObservers(OCResourceHandle resourceHandle,
+                                                QualityOfService QoS)
+        {
+            return OCPlatform_impl::Instance().notifyAllObservers(resourceHandle, QoS);
+        }
+
+        OCStackResult notifyAllObservers(OCResourceHandle resourceHandle)
+        {
+            return OCPlatform_impl::Instance().notifyAllObservers(resourceHandle);
+        }
+
+        OCStackResult notifyListOfObservers(OCResourceHandle resourceHandle,
+                                                ObservationIds& observationIds,
+                                                const std::shared_ptr<OCResourceResponse> pResponse)
+        {
+            return OCPlatform_impl::Instance().notifyListOfObservers(resourceHandle,
+                                                observationIds, pResponse);
+        }
+
+        OCStackResult notifyListOfObservers(OCResourceHandle resourceHandle,
+                                                ObservationIds& observationIds,
+                                                const std::shared_ptr<OCResourceResponse> pResponse,
+                                                QualityOfService QoS)
+        {
+            return OCPlatform_impl::Instance().notifyListOfObservers(resourceHandle,
+                                                    observationIds, pResponse, QoS);
+        }
+
+        OCResource::Ptr constructResourceObject(const std::string& host,
+                                                const std::string& uri,
+                                                bool isObservable,
+                                                const std::vector<std::string>& resourceTypes,
+                                                const std::vector<std::string>& interfaces)
+        {
+            return OCPlatform_impl::Instance().constructResourceObject(host, uri, isObservable,
+                                                resourceTypes, interfaces);
+        }
+
+        OCStackResult findResource(const std::string& host,
+                                                const std::string& resourceName,
+                                                FindCallback resourceHandler)
+        {
+            return OCPlatform_impl::Instance().findResource(host, resourceName, resourceHandler);
+        }
+
+        OCStackResult findResource(const std::string& host,
+                                                const std::string& resourceName,
+                                                FindCallback resourceHandler, QualityOfService QoS)
+        {
+            return OCPlatform_impl::Instance().findResource(host, resourceName,
+                                                resourceHandler, QoS);
+        }
+
+
+        OCStackResult registerResource(OCResourceHandle& resourceHandle,
+                                                std::string& resourceURI,
+                                                const std::string& resourceTypeName,
+                                                const std::string& resourceInterface,
+                                                EntityHandler entityHandler,
+                                                uint8_t resourceProperty)
+        {
+            return OCPlatform_impl::Instance().registerResource(resourceHandle, resourceURI,
+                                                resourceTypeName, resourceInterface,
+                                                entityHandler, resourceProperty);
+        }
+
+        OCStackResult unregisterResource(const OCResourceHandle& resourceHandle)
+        {
+            return OCPlatform_impl::Instance().unregisterResource(resourceHandle);
+        }
+
+        OCStackResult unbindResource(OCResourceHandle collectionHandle,
+                                                OCResourceHandle resourceHandle)
+        {
+            return OCPlatform_impl::Instance().unbindResource(collectionHandle, resourceHandle);
+        }
+
+        OCStackResult unbindResources(const OCResourceHandle collectionHandle,
+                                                const std::vector<OCResourceHandle>& resourceHandles
+                                                )
+        {
+            return OCPlatform_impl::Instance().unbindResources(collectionHandle, resourceHandles);
+        }
+
+        OCStackResult bindResource(const OCResourceHandle collectionHandle,
+                                                const OCResourceHandle resourceHandle)
+        {
+            return OCPlatform_impl::Instance().bindResource(collectionHandle, resourceHandle);
+        }
+
+        OCStackResult bindResources(const OCResourceHandle collectionHandle,
+                                                const std::vector<OCResourceHandle>& resourceHandles
+                                                )
+        {
+            return OCPlatform_impl::Instance().bindResources(collectionHandle, resourceHandles);
+        }
+
+        OCStackResult bindTypeToResource(const OCResourceHandle& resourceHandle,
+                                                const std::string& resourceTypeName)
+        {
+            return OCPlatform_impl::Instance().bindTypeToResource(resourceHandle,resourceTypeName);
+        }
+
+        OCStackResult bindInterfaceToResource(const OCResourceHandle& resourceHandle,
+                                                const std::string& resourceInterfaceName)
+        {
+            return OCPlatform_impl::Instance().bindInterfaceToResource(resourceHandle,
+                                                resourceInterfaceName);
+        }
+
+        OCStackResult startPresence(const unsigned int announceDurationSeconds)
+        {
+            return OCPlatform_impl::Instance().startPresence(announceDurationSeconds);
+        }
+
+        OCStackResult stopPresence()
+        {
+            return OCPlatform_impl::Instance().stopPresence();
+        }
+
+        OCStackResult subscribePresence(OCPresenceHandle& presenceHandle,
+                                                const std::string& host,
+                                                SubscribeCallback presenceHandler)
+        {
+            return OCPlatform_impl::Instance().subscribePresence(presenceHandle, host,
+                                                presenceHandler);
+        }
+
+        OCStackResult unsubscribePresence(OCPresenceHandle presenceHandle)
+        {
+            return OCPlatform_impl::Instance().unsubscribePresence(presenceHandle);
+        }
+    } // namespace OCPlatform
 } //namespace OC
diff --git a/src/OCPlatform_impl.cpp b/src/OCPlatform_impl.cpp
new file mode 100644 (file)
index 0000000..d41154c
--- /dev/null
@@ -0,0 +1,277 @@
+//******************************************************************
+//
+// Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+//******************************************************************
+// File name:
+//     OCPlatform_impl.cpp
+//
+// Description: Implementation of the OCPlatform functionality.  It contains
+// a singleton interface that is used only by the OCPlatform namespace and is the
+// central entrance to the stack.
+//
+//
+//
+//*********************************************************************
+
+#include <random>
+#include <utility>
+#include <functional>
+
+#include "ocstack.h"
+
+#include "OCPlatform.h"
+#include "OCApi.h"
+#include "OCException.h"
+#include "OCUtilities.h"
+
+#include "oc_logger.hpp"
+
+namespace OC
+{
+
+    PlatformConfig& OCPlatform_impl::globalConfig()
+    {
+        static PlatformConfig s_config;
+        return s_config;
+    }
+
+    void OCPlatform_impl::Configure(const PlatformConfig& config)
+    {
+        globalConfig() = config;
+    }
+
+    OCPlatform_impl& OCPlatform_impl::Instance()
+    {
+        static OCPlatform_impl platform(globalConfig());
+        return platform;
+    }
+
+    void OCPlatform_impl::init(const PlatformConfig& config)
+    {
+        switch(config.mode)
+        {
+            case ModeType::Server:
+                m_server = m_WrapperInstance->CreateServerWrapper(*this, m_csdkLock, config);
+                break;
+
+            case ModeType::Client:
+                m_client = m_WrapperInstance->CreateClientWrapper(*this, m_csdkLock, config);
+                break;
+
+            case ModeType::Both:
+                m_server = m_WrapperInstance->CreateServerWrapper(*this, m_csdkLock, config);
+                m_client = m_WrapperInstance->CreateClientWrapper(*this, m_csdkLock, config);
+                break;
+         }
+    }
+
+    OCPlatform_impl::OCPlatform_impl(const PlatformConfig& config)
+     : m_cfg             { config },
+       m_WrapperInstance { make_unique<WrapperFactory>() },
+       m_csdkLock        { make_shared<std::recursive_mutex>() }
+    {
+        init(m_cfg);
+    }
+
+    OCPlatform_impl::~OCPlatform_impl(void)
+    {
+    }
+
+    OCStackResult OCPlatform_impl::setDefaultDeviceEntityHandler(EntityHandler entityHandler)
+    {
+        return checked_guard(m_server, &IServerWrapper::setDefaultDeviceEntityHandler,
+                             entityHandler);
+    }
+
+    OCStackResult OCPlatform_impl::notifyAllObservers(OCResourceHandle resourceHandle,
+                                                QualityOfService QoS)
+    {
+        return result_guard(OCNotifyAllObservers(resourceHandle,
+                    static_cast<OCQualityOfService>(QoS)));
+    }
+
+    OCStackResult OCPlatform_impl::notifyAllObservers(OCResourceHandle resourceHandle)
+    {
+        return notifyAllObservers(resourceHandle, m_cfg.QoS);
+    }
+
+    OCStackResult OCPlatform_impl::notifyListOfObservers(OCResourceHandle resourceHandle,
+                                                ObservationIds& observationIds,
+                                                const std::shared_ptr<OCResourceResponse> pResponse)
+    {
+        return notifyListOfObservers(resourceHandle, observationIds, pResponse, m_cfg.QoS);
+    }
+
+    OCStackResult OCPlatform_impl::notifyListOfObservers(OCResourceHandle resourceHandle,
+                                                ObservationIds& observationIds,
+                                                const std::shared_ptr<OCResourceResponse> pResponse,
+                                                QualityOfService QoS)
+    {
+        if(!pResponse)
+        {
+         return result_guard(OC_STACK_ERROR);
+        }
+
+        std::string payload(pResponse->getPayload());
+
+        return result_guard(
+                   OCNotifyListOfObservers(resourceHandle,
+                            &observationIds[0], observationIds.size(),
+                            reinterpret_cast<unsigned char *>(const_cast<char *>(payload.c_str())),
+                            static_cast<OCQualityOfService>(QoS)));
+    }
+
+    OCResource::Ptr OCPlatform_impl::constructResourceObject(const std::string& host,
+                                                const std::string& uri,
+                                                bool isObservable,
+                                                const std::vector<std::string>& resourceTypes,
+                                                const std::vector<std::string>& interfaces)
+    {
+        if(!m_client)
+        {
+            return std::shared_ptr<OCResource>();
+        }
+
+        return std::shared_ptr<OCResource>(new OCResource(m_client,
+                                            host,
+                                            uri,
+                                            isObservable,
+                                            resourceTypes,
+                                            interfaces));
+    }
+
+    OCStackResult OCPlatform_impl::findResource(const std::string& host,
+                                            const std::string& resourceName,
+                                            FindCallback resourceHandler)
+    {
+        return findResource(host, resourceName, resourceHandler, m_cfg.QoS);
+    }
+
+    OCStackResult OCPlatform_impl::findResource(const std::string& host,
+                                            const std::string& resourceName,
+                                            FindCallback resourceHandler, QualityOfService QoS)
+    {
+        return checked_guard(m_client, &IClientWrapper::ListenForResource,
+                             host, resourceName, resourceHandler, QoS);
+    }
+
+
+    OCStackResult OCPlatform_impl::registerResource(OCResourceHandle& resourceHandle,
+                                            std::string& resourceURI,
+                                            const std::string& resourceTypeName,
+                                            const std::string& resourceInterface,
+                                            EntityHandler entityHandler,
+                                            uint8_t resourceProperty)
+    {
+        return checked_guard(m_server, &IServerWrapper::registerResource,
+                             ref(resourceHandle), resourceURI, resourceTypeName,
+                             resourceInterface, entityHandler, resourceProperty);
+    }
+
+    OCStackResult OCPlatform_impl::unregisterResource(const OCResourceHandle& resourceHandle) const
+    {
+        return checked_guard(m_server, &IServerWrapper::unregisterResource,
+                             resourceHandle);
+    }
+
+    OCStackResult OCPlatform_impl::unbindResource(OCResourceHandle collectionHandle,
+                                            OCResourceHandle resourceHandle)
+    {
+        return result_guard(OCUnBindResource(ref(collectionHandle), ref(resourceHandle)));
+    }
+
+    OCStackResult OCPlatform_impl::unbindResources(const OCResourceHandle collectionHandle,
+                                            const std::vector<OCResourceHandle>& resourceHandles)
+    {
+        for(const auto& h : resourceHandles)
+        {
+           OCStackResult r;
+
+           if(OC_STACK_OK != (r = result_guard(OCUnBindResource(collectionHandle, h))))
+           {
+               return r;
+           }
+        }
+
+        return OC_STACK_OK;
+    }
+
+    OCStackResult OCPlatform_impl::bindResource(const OCResourceHandle collectionHandle,
+                                            const OCResourceHandle resourceHandle)
+    {
+        return result_guard(OCBindResource(collectionHandle, resourceHandle));
+    }
+
+    OCStackResult OCPlatform_impl::bindResources(const OCResourceHandle collectionHandle,
+                                            const std::vector<OCResourceHandle>& resourceHandles)
+    {
+        for(const auto& h : resourceHandles)
+        {
+           OCStackResult r;
+
+           if(OC_STACK_OK != (r = result_guard(OCBindResource(collectionHandle, h))))
+           {
+               return r;
+           }
+        }
+
+        return OC_STACK_OK;
+    }
+
+    OCStackResult OCPlatform_impl::bindTypeToResource(const OCResourceHandle& resourceHandle,
+                                             const std::string& resourceTypeName) const
+    {
+        return checked_guard(m_server, &IServerWrapper::bindTypeToResource,
+                             resourceHandle, resourceTypeName);
+    }
+
+    OCStackResult OCPlatform_impl::bindInterfaceToResource(const OCResourceHandle& resourceHandle,
+                                             const std::string& resourceInterfaceName) const
+    {
+        return checked_guard(m_server, &IServerWrapper::bindInterfaceToResource,
+                             resourceHandle, resourceInterfaceName);
+    }
+
+    OCStackResult OCPlatform_impl::startPresence(const unsigned int announceDurationSeconds)
+    {
+        return checked_guard(m_server, &IServerWrapper::startPresence,
+                             announceDurationSeconds);
+    }
+
+    OCStackResult OCPlatform_impl::stopPresence()
+    {
+        return checked_guard(m_server, &IServerWrapper::stopPresence);
+    }
+
+    OCStackResult OCPlatform_impl::subscribePresence(OCPresenceHandle& presenceHandle,
+                                            const std::string& host,
+                                            SubscribeCallback presenceHandler)
+    {
+        return checked_guard(m_client, &IClientWrapper::SubscribePresence,
+                             &presenceHandle, host, presenceHandler);
+    }
+
+    OCStackResult OCPlatform_impl::unsubscribePresence(OCPresenceHandle presenceHandle)
+    {
+        return checked_guard(m_client, &IClientWrapper::UnsubscribePresence,
+                             ref(presenceHandle));
+    }
+
+} //namespace OC
index 8275592..1b9c601 100644 (file)
@@ -65,7 +65,7 @@ TEST(Resource, rf) {
         0,         // Uses randomly available port
         OC::QualityOfService::LowQos
     };
-    OCPlatform platform(cfg);
+    OCPlatform::Configure(cfg);
 
     std::string resourceURI = "/a/res";
     std::string resourceTypeName = "core.res";
@@ -76,11 +76,11 @@ TEST(Resource, rf) {
     OCResourceHandle resourceHandle;
 
     // This will internally create and register the resource.
-    if(OC_STACK_OK == platform.registerResource(
+    if(OC_STACK_OK == OCPlatform::registerResource(
                                     resourceHandle, resourceURI, resourceTypeName,
                                     resourceInterface, entityHandler_rf, resourceProperty))
     {
-        platform.findResource("","coap://224.0.1.187/oc/core?rt=core.res", foundResource_rf);
+        OCPlatform::findResource("","coap://224.0.1.187/oc/core?rt=core.res", foundResource_rf);
 
         {
             std::unique_lock<std::mutex> lk(mutex_rf);