1 //******************************************************************
3 // Copyright 2014 Intel Corporation All Rights Reserved.
4 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //******************************************************************
10 // Description: Implementation of the OCPlatform.
14 //*********************************************************************
18 #include "OCPlatform.h"
22 // Constructor. Internally calls private init function
23 OCPlatform::OCPlatform(const PlatformConfig& config)
29 OCPlatform::~OCPlatform(void)
31 std::cout << "platform destructor called" << std::endl;
35 void OCPlatform::init(const PlatformConfig& config)
37 std::unique_ptr<WrapperFactory> wrapperInstance(new WrapperFactory());
38 m_WrapperInstance = std::move(wrapperInstance);
40 if(config.mode == ModeType::Server)
42 // Call server wrapper init
43 m_server = m_WrapperInstance->CreateServerWrapper(config);
45 else if(config.mode == ModeType::Client)
47 // Call client wrapper init
48 m_client = m_WrapperInstance->CreateClientWrapper(config);
52 // This must be both server and client
53 m_server = m_WrapperInstance->CreateServerWrapper(config);
54 m_client = m_WrapperInstance->CreateClientWrapper(config);
58 void OCPlatform::cleanup()
72 void OCPlatform::findResource(const std::string& host, const std::string& resourceName,
73 std::function<void(OCResource::Ptr)> resourceHandler)
77 m_client->ListenForResource(host, resourceName, resourceHandler);
82 void OCPlatform::registerResource(const std::string& resourceURI, const std::string& resourceTypeName,
83 named_property_binding_vector properties)
88 m_server->registerResource(resourceURI, resourceTypeName, properties);
89 }catch(std::exception e) // define our own expception.