The old_tests folder is not used.
Change-Id: I194ba0d7a11b38b682d62f3a95cd86406955f1fb
Signed-off-by: Sakthivel Samidurai <sakthivel.samidurai@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/645
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Erich Keane <erich.keane@intel.com>
+++ /dev/null
-//******************************************************************
-//
-// 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.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-#include <iostream>
-
-#include "ocapi.h"
-#include "OCReflect.h"
-#include "OCObserver.h"
-#include "OCException.h"
-#include "MyMultiResourceHandler.h"
-
-namespace {
-
-void log(const std::string& msg)
-{
- std::cerr << msg << '\n';
-}
-
-} // namespace
-
-void OC::MyMultiResourceHandler::onFoundResource(OCResourceResult *update, void *params){
-
- //Step1: Find a specific resource that also contains OCReflect byte stream of methods and properties
- for( auto &resource : update->resources )
- {
- if(resource.getURI() == "/garage/dimmer/a")
- {
- performDimmerOperations(resource, update);
- }
- else if(resource.getURI() == "/garage/door/a")
- {
- performDoorOperations(resource, update);
- }
- }
-}
-
-void OC::MyMultiResourceHandler::performDimmerOperations(OC::OCResource myResource, OC::OCResourceResult *update)
-{
- using OC::OCReflect::entity;
- using OC::OCReflect::method;
- using OC::OCReflect::remote_resource;
-
- using OC::bind_observer;
- using OC::unbind_observer;
-
- try
- {
- // Perform resource operation
- // Note that this resource dimmer has
- // 'manufacturer' as a property
- // 'powerState' as a observable property
- // 'setPowered' as a method
- // 'getPowered' as a method
-
- //Step1: Find a specific method and invoke it. or Find a specific property and use it.
-
- // Canonical one-step approach to get a callable function object:
- // OCReflect::method throw OC::OCReflect::reflect_exception if there is no setLevel method in the myResource
- auto setPowered = OCReflect::method(myResource, "setPowered");
-
- // invoke the remote method,
- // invalid arguments return as an OC::OCReflect::reflect_exception
- setPowered(true);
-
- // Canonical one-step approach to get a callable function object:
- // OCReflect::method throw OC::OCReflect::reflect_exception if there is no setLevel method in the myResource
- auto getPowered = OCReflect::method(myResource, "getPowered");
-
- // invoke the remote method,
- // invalid arguments return as an OC::OCReflect::reflect_exception
- // bool power = getPowered(); // Use power variable to do other operations
-
- // Canonical one-step approach to access a property:
- std::string manufacturer = update->property<std::string>("manufacturer");
-
- //Example to observe a property
- bind_observer(&myObserverHandler, myResource, "powerState");
-
- //Example to unobserve a property
- unbind_observer(&myObserverHandler, myResource, "powerState");
- }
- catch(OC::reflection_exception& e)
- {
- log(e.what());
- }
- catch(std::exception& e)
- {
- log(e.what());
- }
-}
-
-void OC::MyMultiResourceHandler::performDoorOperations(OC::OCResource myResource, OC::OCResourceResult *update)
-{
- // Perform resource operation
- // Note that this resource door has
- // 'manufacturer' as a property
- // 'setLockState' as a method
- // 'getLockState' as a method
-
- try
- {
- // Step1: Find a specific method and invoke it or find a specific property and use it.
-
- // Canonical one-step approach to get a callable function object:
- // OCReflect::method throw OC::OCReflect::reflect_exception if there is no setLevel method in the myResource
- auto setLockState = OCReflect::method(myResource, "setLockState");
-
- // invoke the remote method,
- // invalid arguments return as an OC::OCReflect::reflect_exception
- setLockState(true);
-
- // Canonical one-step approach to get a callable function object:
- // OCReflect::method throw OC::OCReflect::reflect_exception if there is no setLevel method in the myResource
- auto getLockState = OCReflect::method(myResource, "getLockState");
-
- // invoke the remote method,
- // invalid arguments return as an OC::OCReflect::reflect_exception
- // bool lockState = getLockState(); // use lockState variable for any other operations
-
- // Canonical one-step approach to access a property
- std::string manufacturer = update->property<std::string>("manufacturer");
- }
- catch(OC::reflection_exception& e)
- {
- log(e.what());
- }
- catch(std::exception& e)
- {
- log(e.what());
- }
-}
-
-void OC::MyMultiResourceHandler::MyMultiResourceHandler::onCompleted()
-{
-
-}
-
-void OC::MyMultiResourceHandler::MyMultiResourceHandler::onFailed()
-{
-
-}
+++ /dev/null
-//******************************************************************
-//
-// 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.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-#include "ocapi.h"
-#include "OCResourceHandler.h"
-#include "MyObserverHandler.h"
-
-namespace OC {
-
-class MyMultiResourceHandler :
- public OCResourceHandler
-{
-public:
- void onFoundResource(OCResourceResult *update, void *params);
- void onCompleted();
- void onFailed();
-
-private:
- MyObserverHandler myObserverHandler;
-
- /// This is a private function to perform operations related to dimmer resource
- void performDimmerOperations(OCResource myResource, OCResourceResult *update);
-
- /// This is a private function to perform operations related to door resource
- void performDoorOperations(OCResource myResource, OCResourceResult *update);
-};
-
-} // namespace OC
+++ /dev/null
-//******************************************************************
-//
-// 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.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-#include "MyObserverHandler.h"
-
-void OC::MyObserverHandler::onObserverUpdate(std::string propertyName, void *value)
-{
-
-}
+++ /dev/null
-//******************************************************************
-//
-// 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.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-#include "OCApi.h"
-#include "OCObserverHandler.h"
-
-namespace OC {
-
-class MyObserverHandler :
- public OC::OCObserverHandler
-{
-public:
- void onObserverUpdate(std::string propertyName, void *value);
-};
-
-} // namespace OC
+++ /dev/null
-//******************************************************************
-//
-// 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.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-
-#include <iostream>
-
-#include "ocapi.h"
-#include "OCReflect.h"
-#include "OCObserver.h"
-#include "OCException.h"
-#include "MyResourceHandler.h"
-
-void log(const std::string& msg)
-{
- std::cerr << msg << '\n';
-}
-
-MyResourceHandler::MyResourceHandler(void)
-{
-}
-
-
-MyResourceHandler::~MyResourceHandler(void)
-{
-}
-
-void MyResourceHandler::onFoundResource(OCResourceResult *update, void *params){
- using OC::OCReflect::entity;
- using OC::OCReflect::method;
- using OC::OCReflect::remote_resource;
-
- using OC::bind_observer;
- using OC::unbind_observer;
-
- try
- {
- //Step1: Find a specific resource that also contains OCReflect byte stream of methods and properties
- OCResource myResource;
- for ( auto &resource : update->resources ) {
- if(resource.getURI() == "/light/a"){
- myResource = resource;
- break;
- }
- }
-
- //Step2: Find a specific method and invoke it. or Find a specific property and use it.
-
- // Canonical one-step approach to get a callable function object:
- // OCReflect::method throw OC::OCReflect::reflect_exception if there is no setLevel method in the myResource
- auto setLevel = OC::OCReflect::method(myResource, "setLevel");
-
- setLevel(75, 255);
-
- // Individual steps-- each may throw on failure:
- remote_resource myLight(myResource, "lights/a"); // JFW: this may be subsumed by type OCResource
-
- entity e_setPowered = myLight("setPowered");
-
- method setPowered = OC::OCReflect::narrow<OCReflect::method>(e_setPowered);
-
- setPowered(true);
-
- // Canonical one-step approach to access a property:
- std::string manufacturer = update->property<std::string>("manufacturer");
-
- // Individual steps:
- entity e_manufacturer = myResource.property("manufacturer");
- std::string manufacturer_2 = OC::OCReflect::narrow<std::string>(e_manufacturer);
-
- //Example to observe a property
- bind_observer(&myObserverHandler, myResource, "PowerState");
-
- //Example to unobserve a property
- unbind_observer(&myObserverHandler, myResource, "PowerState");
- }
- catch(OC::reflection_exception& e)
- {
- log(e.what());
- }
- catch(std::exception& e)
- {
- log(e.what());
- }
-}
-
-void MyResourceHandler::onCompleted(){
-}
-
-void MyResourceHandler::onFailed(){
-}
+++ /dev/null
-//******************************************************************
-//
-// 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.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-#include "ocapi.h"
-#include "OCResourceHandler.h"
-#include "MyObserverHandler.h"
-
-using namespace OC;
-
-class MyResourceHandler :
- public OCResourceHandler
-{
-public:
- MyResourceHandler(void);
- virtual ~MyResourceHandler(void);
- void onFoundResource(OCResourceResult *update, void *params);
- void onCompleted();
- void onFailed();
-
-private:
- MyObserverHandler myObserverHandler;
-
-};
-
+++ /dev/null
-# //******************************************************************
-# //
-# // 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.
-# //
-# //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-#
-CXX=g++
-CXX_FLAGS=-std=c++0x -Wall -pthread
-
-final: server client serverApp
-
-serverApp: InProcServerWrapper.o testServerApp.o ocstack_stub.o OCResource.o InProcClientWrapper.o OCReflect.o OCPlatform.o
- $(CXX) $(CXX_FLAGS) -o serverApp InProcServerWrapper.o testServerApp.o ocstack_stub.o OCResource.o InProcClientWrapper.o OCReflect.o OCPlatform.o
-
-server: InProcServerWrapper.o testServer.o ocstack_stub.o OCResource.o InProcClientWrapper.o OCReflect.o
- $(CXX) $(CXX_FLAGS) -o server InProcServerWrapper.o testServer.o ocstack_stub.o OCResource.o InProcClientWrapper.o OCReflect.o
-
-client: InProcServerWrapper.o testClient.o ocstack_stub.o OCResource.o InProcClientWrapper.o OCReflect.o
- $(CXX) $(CXX_FLAGS) -o client InProcServerWrapper.o testClient.o ocstack_stub.o OCResource.o InProcClientWrapper.o OCReflect.o
-
-OCReflect.o: ../../../OCLib/OCReflect.cpp
- $(CXX) $(CXX_FLAGS) -c ../../../OCLib/OCReflect.cpp -I../../../csdk/ -I../../../include -I../
-
-OCPlatform.o: ../../../OCLib/OCPlatform.cpp
- $(CXX) $(CXX_FLAGS) -c ../../../OCLib/OCPlatform.cpp -I../../../csdk/ -I../../../include/ -I../ -I../client/ -I../server/
-
-OCResource.o: ../../../OCLib/OCResource.cpp
- $(CXX) $(CXX_FLAGS) -c ../../../OCLib/OCResource.cpp -I../../../csdk/ -I../../../include/ -I../ -I../client/ -I../server/
-
-ocstack_stub.o : ../../../csdk/ocstack_stub.c
- gcc -c ../../../csdk/ocstack_stub.c -I../../../csdk/
-
-InProcServerWrapper.o: ../server/InProcServerWrapper.cpp
- $(CXX) $(CXX_FLAGS) -c ../server/InProcServerWrapper.cpp -I../../../csdk/ -I../../../include -I../
-
-InProcClientWrapper.o: ../client/InProcClientWrapper.cpp
- $(CXX) $(CXX_FLAGS) -c ../client/InProcClientWrapper.cpp -I../../../csdk/ -I../../../include -I../
-
-testServer.o : testServer.cpp
- $(CXX) $(CXX_FLAGS) -c testServer.cpp -I../../../csdk/ -I../../../include -I../ -I../client/ -I../server/
-
-testServerApp.o : testServerApp.cpp
- $(CXX) $(CXX_FLAGS) -c testServerApp.cpp -I../../../csdk/ -I../../../include -I../ -I../client/ -I../server/
-
-testClient.o : testClient.cpp
- $(CXX) $(CXX_FLAGS) -c testClient.cpp -I../../../csdk/ -I../../../include -I../ -I../client/ -I../server/
-
-clean:
- rm *.o server client serverApp
-
+++ /dev/null
-//******************************************************************
-//
-// 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.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-#include <iostream>
-#include <boost/property_tree/ptree.hpp>
-#include <boost/property_tree/json_parser.hpp>
-
-using namespace std;
-using namespace boost::property_tree;
-
-void parseResource(ptree resource)
-{
- cout<<"\t\tParsing Resource with "<< resource.size() <<" facts:"<<endl;
- cout << "\t\tAddress is "<< resource.get<std::string>("href", "") <<endl;
- cout << "\t\tIs Observable? : "<< (resource.get<int>("obs",0)==1)<<endl;
-
- // types:
- cout << "\t\tResource Type Count : "<<resource.get_child("rt", ptree()).size()<<endl;
- for(auto resourceItr : resource.get_child("rt", ptree()))
- {
- cout << "\t\t\tResource Type: "<< resourceItr.second.data()<<endl;
- }
-
- // interfaces:
- cout << "\t\tInterface Count : "<<resource.get_child("if", ptree()).size()<<endl;
- for(auto resourceItr : resource.get_child("if", ptree()))
- {
- cout << "\t\t\tInterface: "<< resourceItr.second.data()<<endl;
- }
-
- cout<<endl;
-}
-
-void parseTest(const char* data)
-{
-
- std::stringstream requestStream;
- requestStream << data;
-
- ptree root;
- boost::property_tree::read_json(requestStream, root);
-
- ptree payload = root.get_child("oc.payload", ptree());
- cout << "\tResource Count:" << payload.size()<<endl;
-
- for(auto itr : payload)
- {
- parseResource(itr.second);
- }
-
-// cout << "PTree Size: " << requestTree.size() << " DATA: "<<requestTree.get_value<string>() <<endl;
- //cout << "\t Child:"<<requestTree.front().first.data()<<" " << requestTree.front().second.data()<<endl;
-}
-
-
-int main()
-{
- const char* data1 = "{\"oc\": {\
- \"payload\": [{\
- \"href\":\"/a/tube\",\
- \"rt\":[\"alpha.act.tb\"],\
- \"if\":[\"oc.mi.a\"]\
- },\
- {\
- \"href\":\"/b/tube\",\
- \"rt\":[\"alpha.act.tb\"],\
- \"if\":[\"oc.mi.a\"],\
- \"obs\" : 1\
- }\
- ]\
- }\
-}";
-
- const char* data2 = "{\"oc\": {\
- \"payload\": [{\
- \"href\":\"/temp-sensor\",\
- \"rt\":[\"beta.sensor.temp\"],\
- \"if\":[\"oc.mi.s\"],\
- \"obs\" : 1\
- }\
- ]\
- }\
-} ";
-
- const char* data3 = "{\"oc\": {\
- \"payload\": [{\
- \"href\":\"/room-lights\",\
- \"rt\":[\"gamma.lights\"],\
- \"if\":[\"oc.mi.ll\", \"oc.mi.b\"]\
- }\
- ]\
- }\
-} ";
-
- cout<<"Data1:\n";
- parseTest(data1);
- cout<<"Data2:\n";
- parseTest(data2);
- cout<<"Data3:\n";
- parseTest(data3);
-
- return 0;
-}
\ No newline at end of file
+++ /dev/null
-//******************************************************************
-//
-// 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.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-
-#include <WrapperFactory.h>
-#include <OCApi.h>
-#include <IServerWrapper.h>
-#include <IClientWrapper.h>
-
-using namespace OC;
-
-void testClient()
-{
- PlatformConfig cfg;
- cfg.ipAddress = "192.168.1.5";
- cfg.port = 8080;
- cfg.mode = ModeType::Client;
- cfg.serviceType = ServiceType::InProc;
-
- IWrapperFactory::Ptr pFactory = std::make_shared<WrapperFactory>();
- IClientWrapper::Ptr pWrapper = pFactory->CreateClientWrapper(cfg);
-}
-
-int main()
-{
- testClient();
-}
+++ /dev/null
-//******************************************************************
-//
-// 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.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-
-#include <WrapperFactory.h>
-#include <OCApi.h>
-#include <IServerWrapper.h>
-#include <IClientWrapper.h>
-#include <OCReflect.h>
-
-#include <algorithm>
-#include <cstring>
-#include <cstdlib>
-
-using namespace OC;
-using namespace OC::OCReflect;
-
-// Demo of how to generate OCStack stuff:
-void rep_test()
-{
- using OC::OCReflect::property_type;
- using OC::OCReflect::named_property_binding;
-
- named_property_binding_vector sigs {
- named_property_binding("state", property_type::boolean),
- named_property_binding("power", property_type::integer),
- };
-
- using namespace OC::OCReflect::OCStack;
-
- std::vector<std::string> reps { convert(sigs) };
-
- for(const auto& r : reps)
- std::cout << r << '\n';
-
- char **LEDrep = convert(reps);
-
- std::for_each(LEDrep, LEDrep + length(LEDrep), [](const char *s) { std::cout << s << '\n'; });
-
-
-
-
- OCEntityHandler entityHandler;
- OCResourceHandle resourceHandle;
-
- OCCreateResource( &resourceHandle, // OCResourceHandle *handl
- "core.led", // const char * resourceTypeName
- "state:oc.bt.b;power:oc.bt.i", //const char * resourceTypeRepresentation
- "core.rw", //const char * resourceInterfaceName
- OC_REST_GET | OC_REST_PUT, // uint8_t allowedMethods
- "/a/led", // const char * uri
- entityHandler, // OCEntityHandler entityHandler
- OC_DISCOVERABLE | OC_OBSERVABLE // uint8_t resourceProperties
- );
-
-
-
- release(LEDrep);
-}
-
-void testServer()
-{
- PlatformConfig cfg;
- cfg.ipAddress = "192.168.1.5";
- cfg.port = 8080;
- cfg.mode = ModeType::Server;
- cfg.serviceType = ServiceType::InProc;
-
- IWrapperFactory::Ptr pFactory= std::make_shared<WrapperFactory>();
-
- IServerWrapper::Ptr pServer = pFactory->CreateServerWrapper(cfg);
-
- //pServer->bindTo
-}
-
-int main()
-{
- rep_test();
- testServer();
-}
+++ /dev/null
-//******************************************************************
-//
-// 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.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-///
-/// This sample provides steps to define an interface for a resource
-/// (properties and methods) and host this resource on the server.
-///
-
-#include <functional>
-
-#include <OCServer.h>
-#include <OCReflect.h>
-#include <OCPlatform.h>
-#include <OCApi.h>
-#include <iostream>
-
-using namespace std;
-
-using namespace OC;
-using namespace OC::OCReflect;
-
-/// This class represents a single resource named 'light'. This resource has
-/// two simple properties named 'state' and 'power' and they have respective setter
-/// and getter methods.
-
-class light
-{
-private:
- /// Access this property from a TB client
- bool m_state;
- int m_power;
-
-public:
- light()
- : m_power(0),
- m_state(false)
- {}
-
-public:
- /// Setter method for the setting the power of this light resource
- void setPower(int powerValue)
- {
- m_power = powerValue;
- }
-
- /// Getter method for the getting the power of this light resource
- int getPower() const
- {
- return m_power;
- }
-
- /// Setter method for the setting the state of this light resource
- void setState(bool state)
- {
- m_state = state;
- }
-
- /// Getter method for the getting the state of this light resource
- bool getState() const
- {
- return m_state;
- }
-
-public:
- /* Note that this does not need to be a member function: for classes you do not have
- access to, you can accomplish this with a free function: */
-
- /// This function binds the properties and methods to the server.
- void bindTo(OC::OCPlatform& platform)
- {
- using OC::OCReflect::property_type;
- using OC::OCReflect::property_binding;
-
- property_binding_vector properties {
- property_binding("state", property_type::boolean),
- property_binding("power", property_type::integer)
- };
-
- std::string resourceURI = "/a/light";
- std::string resourceTypeName = "light";
- platform.registerResource(resourceURI, resourceTypeName, properties);
- }
-};
-
-int main()
-{
- // Step1: Create a OCPlatform instance.
- // Step1.1: The constructor of OCPlatform class takes PlatformConfig object.
- // Note: Platform creation is synchronous call.
-
- PlatformConfig cfg;
- cfg.ipAddress = "192.168.1.5";
- cfg.port = 8080;
- cfg.mode = ModeType::Server;
- cfg.serviceType = ServiceType::InProc;
-
- cout << "Creating OCPlatform .. \n";
-
- OCPlatform platform(cfg);
-
- // Step2: Create the instance of the resource class (in this case instance of class 'light').
- // Step2.1: Invoke bindTo function of class light.
-
- light myLight;
- myLight.bindTo(platform);
-
- while(true)
- {
- //some tasks
- }
-
- // No explicit call to stop the platform.
- // When OCPlatform destructor is invoked, internally we do platform cleanup
-}
+++ /dev/null
-//******************************************************************
-//
-// 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.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-///
-/// This sample provides steps to define an interface for multiple resources
-/// (properties and methods) and host these resources on the server.
-///
-#include <functional>
-
-#include "OCServer.h"
-#include "OCReflect.h"
-
-using namespace OC::OCReflect;
-
-class dimmer
-{
-private:
- int m_level;
- int m_color;
-
-public:
- bool m_powered; // This is an observable property
- std::string manufacturer; // This is a non-observable property
-
-public:
- dimmer()
- : m_level(0),
- m_color(0),
- m_powered(false),
- manufacturer("Integrated Electronics")
- {}
-
-public:
- /// Setter method for the setting the power state of this dimmer resource
- void setPowered(const bool newState)
- {
- m_powered = newState;
- }
-
- /// Getter method for the setting the power state of this dimmer resource
- bool getPowered() const
- {
- return m_powered;
- }
-
- /// Setter method for the setting the intensity level of this dimmer resource
- /// Along with above basic method, this method takes two arguments
- /// with first argument as intensity level and second level as color.
- void setLevel(const int newLevel, int color)
- {
- m_level = newLevel;
- m_color = color;
- }
-
- /// Getter method for getting the intensity level of the dimmer resoruce
- int getLevel() const
- {
- return m_level;
- }
-
- /// Note that this does not need to be a member function: for classes you do not have
- /// access to, you can accomplish this with a free function:
-public:
- void bindTo(OC::OCServer& server, const std::string& base_URI)
- {
- /*using OC::OCReflect::method_signature;
- using OC::OCReflect::method_binding;
- using OC::OCReflect::property_signature;
- using OC::OCReflect::property_binding;
- using OC::OCReflect::bind_service;
- using OC::OCReflect::bind_property;
-
- using OC::OCReflect::property_type;*/
-
- // Register the URI with the server
- server.registerResource(this, base_URI);
-
- // Steps to map the property
-
- // The canonical way to bind a property to a server in one step:
- bind_property(
- server, // server to bind to
- this->manufacturer, // pointer to property
- "manufacturer", // property binding name
- OC::OCReflect::property_type::string, // property
- OC::OCReflect::property_attribute::r // type decoration
- );
-
- // The canonical way to bind a property to a server in one step:
- bind_property(
- server, // server to bind to
- this->m_powered, // pointer to property
- "powerState", // property binding name
- OC::OCReflect::property_type::boolean, // property
- OC::OCReflect::property_attribute::r // type decoration
- );
-
- // Steps to map the methods
-
- // Example to map getPowered method using the canonical way in one step:
- bind_service(server, // server to bind to
- this, // instance (ourself) to bind
- &dimmer::getPowered, // address of the method to bind
- "getPowered", // name to bind with service URL
- property_type::boolean); // return type of the method
-
- // Example to map setPowered method using the canonical way in one step:
- bind_service(server, // server to bind to
- this, // instance (ourself) to bind
- &dimmer::setPowered, // address of the method to bind
- "setPowered", // name to bind with service URL
- property_type::nil, // return type of the method
- property_type::boolean); // parameter type for setPowered method
-
- // Example to map setLevel method using the canonical way in one step:
- bind_service(
- server, // server to bind with
- this, // instance to bind
- &dimmer::setLevel, // method to bind
- "setLevel", // service name
- property_type::nil, // input type
- property_type::integer, // parameter list starts (parameter type for level)
- property_type::integer); // parameter list (parameter type for color)
-
- // Example to map getLevel method using the canonical way in one step:
- bind_service(server, this, &dimmer::getLevel, "getLevel", property_type::integer);
- }
-};
-
-class door
-{
- bool m_locked;
-
-public:
- std::string manufacturer;
-
-public:
- door()
- : m_locked(true),
- manufacturer("Integrated Electronics")
- {}
-
-public:
- /// Setter method for the setting the lock state of this door resource
- void setLockState(const bool lockState)
- {
- m_locked = lockState;
- }
-
- /// Getter method for the setting the lock state of this door resource
- bool getLockState() const
- {
- return m_locked;
- }
-
- /* Note that this does not need to be a member function: for classes you do not have
- access to, you can accomplish this with a free function: */
-public:
- void bindTo(OC::OCServer& server, const std::string& base_URI)
- {
- /*using OC::OCReflect::method_signature;
- using OC::OCReflect::method_binding;
- using OC::OCReflect::property_signature;
- using OC::OCReflect::property_binding;
- using OC::OCReflect::bind_service;
- using OC::OCReflect::bind_property;
-
- using OC::OCReflect::property_type;*/
-
- // Register the URI with the server
- server.registerResource(this, base_URI);
-
- // Steps to map the property
-
- // The canonical way to bind a property to a server in one step:
- bind_property(
- server, // server to bind to
- this->manufacturer, // pointer to property
- "manufacturer", // property binding name
- OC::OCReflect::property_type::string, // property
- OC::OCReflect::property_attribute::r // type decoration
- );
-
- // Steps to map the methods
-
- // Example to map getPowered method using the canonical way in one step:
- bind_service(server, // server to bind to
- this, // instance (ourself) to bind
- &door::getLockState, // address of the method to bind
- "getLockState", // name to bind with service URL
- property_type::boolean); // return type of the method
-
- // Example to map setPowered method using the canonical way in one step:
- bind_service(server, // server to bind to
- this, // instance (ourself) to bind
- &door::setLockState, // address of the method to bind
- "setLockState", // name to bind with service URL
- property_type::nil, // return type of the method
- property_type::boolean); // parameter type for setPowered method
- }
-};
-
-class garage
-{
-private:
- dimmer myDimmer;
- door myDoor;
-
-public:
- void bindTo(OC::OCServer& server, const std::string& base_URI)
- {
- // Register the URI with the server
- server.registerResource(this, base_URI);
-
- // Bind child resource 'dimmer' to the server
- myDimmer.bindTo(server, base_URI + "/dimmer/a");
-
- // Bind child resource 'door' to the server
- myDoor.bindTo(server, base_URI + "/door/a");
- }
-};
-
-int main()
-{
- //Step1: create a server
- OC::OCSecurityModel securityModel;
- OC::OCServer server;
- server.setSecurityModel(securityModel);
-
- //Step2: Create a Garage resource
- garage myGarage;
-
- //Step3: Bind garage resource to the server
- //Note: Garage resource has child resources -- dimmer and door.
- myGarage.bindTo(server, "/garage/");
-
- //Step4: Start the server
- server.start();
-
- while(true)
- {
- //do something here
- }
-
- //Step4: Stop the server
- server.stop();
-}