From 0eb0dfb9f975abe3781882daf434ee23be341e99 Mon Sep 17 00:00:00 2001 From: Erich Keane Date: Mon, 8 Sep 2014 15:37:28 -0700 Subject: [PATCH] Deleting OCReflect and OCServer, which are boht dead code. Had to remove references from a few files and fix some other includes Fixed OCResource's line lengths Change-Id: Ica6e66a1ab3ecffd6c93d8f4787a3be8a9ed1128 --- examples/reflect/test_OCClient.cpp | 29 --- examples/reflect/test_OCReflect.cpp | 265 ----------------------- examples/reflect/test_properties.cpp | 407 ----------------------------------- include/IServerWrapper.h | 2 +- include/OCProperties.h | 199 ----------------- include/OCPropertyTypes.h | 248 --------------------- include/OCReflect.h | 128 ----------- include/OCServer.h | 124 ----------- makefile | 19 +- src/InProcServerWrapper.cpp | 5 +- src/OCReflect.cpp | 263 ---------------------- src/OCResource.cpp | 51 +++-- src/OCServer.cpp | 62 ------ 13 files changed, 42 insertions(+), 1760 deletions(-) delete mode 100644 examples/reflect/test_OCClient.cpp delete mode 100644 examples/reflect/test_OCReflect.cpp delete mode 100644 examples/reflect/test_properties.cpp delete mode 100644 include/OCProperties.h delete mode 100644 include/OCPropertyTypes.h delete mode 100644 include/OCReflect.h delete mode 100644 include/OCServer.h delete mode 100644 src/OCReflect.cpp delete mode 100644 src/OCServer.cpp diff --git a/examples/reflect/test_OCClient.cpp b/examples/reflect/test_OCClient.cpp deleted file mode 100644 index 248e58e..0000000 --- a/examples/reflect/test_OCClient.cpp +++ /dev/null @@ -1,29 +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. -// -//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - - -#include - -#include "OCPlatform.h" - -int main() -{ - //MyResourceHandler mrh; -} diff --git a/examples/reflect/test_OCReflect.cpp b/examples/reflect/test_OCReflect.cpp deleted file mode 100644 index 3335be1..0000000 --- a/examples/reflect/test_OCReflect.cpp +++ /dev/null @@ -1,265 +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. -// -//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - - -#include -#include - -#include "OCServer.h" -#include "OCReflect.h" -#include "OCException.h" -#include "OCProperties.h" - -namespace OC { namespace OCReflect { - -// JFW: -/* -template -struct call_through -{ - BoundF& f; - - const property_type return_type; - const property_type_vector param_types; - - call_through(BoundF& f_, const property_type& return_type_, const property_type_vector param_types_) - : f(f_), return_type(return_type_), param_types(param_types_) - {} - - property operator()() - { - return make_property(f(), "return value"); // JFW: need a version of this for anonymous properties - } - - template - property operator()(const XS& ...params) - { - // switch(p0_type) - //return make_property(f(), "foo"); - - f(params...); - -// return make_property(f(params...), "fancy result name"); - - return make_property("Hello, World!", "fancy result name"); - } -}; -*/ - -template -OC::OCReflect::bound_function bind_function(InstanceT *self, MethodT const& method) -{ - return [self, method](const property_vector& args) -> property - { - auto b = std::bind(method, self); - return OC::OCReflect::make_property::apply(b(args), "_ret_"); - }; -} - -template -void bind_service(OC::OCServer& server, InstanceT *self, MethodT const& method, const std::string& binding_name, const property_type& return_type, const ParameterT& ...param_types) -{ - OC::OCReflect::bound_function f { - [method, self](const property_vector& args) -> property - { - // JFW: auto b = std::bind(method, self); - -/* JFW: eventually, map parameters in to e return OC::OCReflect::make_property::apply(b(args), "_ret_"); - ...this is tricky, so we' punting on it for the Tuesday release. */ - - return OC::OCReflect::make_property::apply("hello from your friendly neighborhood lambda", "return value"); - } - }; - - OC::OCReflect::method_binding fmb(binding_name, f, - return_type, property_type_vector { param_types... }); - - server.bind(fmb); -} - -template -void bind_property(OC::OCServer& server, PropertyT& property, const std::string& binding_name, const property_type& pt, const property_attribute& pa) -{ - - OC::OCReflect::property_binding npb { binding_name, { pt, pa } }; - OC::OCReflect::property_binding pb { binding_name, - npb }; //{ binding_name, { pt, pa } } }; - - server.bind(pb); - -/* - server.bind({ binding_name, - { binding_name, { pt, pa } } }); -*/ -} - -}} // namespace OC::OCReflect - -class light -{ - bool m_powered; - int m_level; - int m_color; - - public: - std::string manufacturer; - - public: - light() - : m_powered(false), - m_level(0), - m_color(0), - manufacturer("Integrated Electronics") - {} - - public: - void update_things() { std::cout << "light::update_things()\n"; } - - void set_powered(const bool new_state) { m_powered = new_state; } - bool get_powered() const { return m_powered; } - - void set_level(const int new_level, int color) { m_level = new_level; m_color = color; } - int get_level() const { return m_level; } - - /* An example of server-side service binding. 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; - - server.registerResource(this, base_URI); - - // Bind a nullary method: - bind_service( server, - this, - &light::update_things, - "updateThings", - property_type::nil, - property_type::nil); - - // Bind an unary method: - bind_service( server, - this, &light::set_powered, - "setPowered", - property_type::nil, - property_type::boolean); - - // Example to map setLevel method using the canonical way in one step: - bind_service( - server, // server to bind with - this, // instance to bind - &light::set_level, // method to bind - "setLevel", // service name - property_type::nil, // input type - property_type::integer, // parameter list starts (level) - property_type::integer); // parameter list (color) - - - bind_service(server, this, &light::get_level, "getLevel", - property_type::integer); - - bind_service(server, this, &light::get_powered, "isPowered", - property_type::boolean); - - bind_service(server, this, &light::set_powered, "setPowered", - property_type::nil, - property_type::boolean); - - // Map powered() as a service: - method_signature m_setPowered( - property_type::nil, // return type - property_type::boolean // parameter list (here, just arity 1) - ); - - // JFW: below is to say a wrapper for: std::bind(&light::set_powered, this); we'll need - // to pretty these up: - OC::OCReflect::bound_function f = - [](const OC::OCReflect::property_vector& args) -> OC::OCReflect::property - { return OC::OCReflect::make_property::apply(nullptr, "ret"); }; - - method_binding b_setPowered( - "setPowered", // name to bind with service URL - f, // function to bind to the service - m_setPowered); // method signature (metadata) - - server.bind(b_setPowered); // request binding -/* - // Example to bind a read-only property in individual steps: - property_signature p_manufacturer_signature(property_type::string, OC::OCReflect::property_attribute::r); // read-only - - OC::OCReflect::property_binding p_manufacturer("manufacturer", p_manufacturer_signature); - - property_binding b_manufacturer( - this->manufacturer, - p_manufacturer); - - server.bind(b_manufacturer); -*/ -/* - // 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 - ); -*/ - } -}; - -void show_bindings(const OC::OCServer& server) -{ - using namespace std; - - const auto& methods = server.methods(); - - cout << "Bound methods:\n"; - for(const auto& m : methods) - { - cout << m.first << ':' << m.second << '\n'; - } -} - -int main() -{ - OC::OCServer server; - - try - { - light l; - l.bindTo(server, "/foo/"); - } - catch(OC::reflection_exception& e) - { - std::cerr << "Oops: " << e.what() << '\n'; - } - - show_bindings(server); -} diff --git a/examples/reflect/test_properties.cpp b/examples/reflect/test_properties.cpp deleted file mode 100644 index 03bb585..0000000 --- a/examples/reflect/test_properties.cpp +++ /dev/null @@ -1,407 +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. -// -//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - -/* To avoid confusion: These are not unit tests, these are "test programs". */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "OCReflect.h" - -using namespace OC::OCReflect; - -using std::cout; - -template -void convert_and_compare(const InputT& input, const std::string name = "property") -{ - auto p = make_property::apply(input, name); - - cout << p << '\n'; - - auto x = concretize(p); - - cout << x << '\n'; - - assert(input == x); -} - -// Convert a native type to a property: -void convert_test() -{ - using std::cout; - using namespace OC::OCReflect; -/* - // Nil (JSON: null): - { - property_signature ps(property_type::nil); - property_binding npb("nil_property", ps); - } -*/ - - // Boolean: - { - convert_and_compare(true, "bool"); - convert_and_compare(false, "bool"); - } - - // Integer: - { - const int64_t input { 1024 }; - convert_and_compare(input, "int64_t"); - } - - // Rational (JSON: number): - { - const double input { 1024.0 }; - convert_and_compare(input, "double"); - } - - // String: - { - const std::string input { "Hello, World!" }; - convert_and_compare(input, "string"); - } - -/* - // List (JSON: array): - { - property_signature(property_type::list); - } -*/ -/* JFW: - // Dictionary (JSON: object): - { - property_signature(property_type::dictionary); - } -*/ - - // test with attributes: -} - -typedef property return_property; - -template -return_property make_return_property(const InT& in) -{ - return OC::OCReflect::make_property::apply(in, "__RETURN_VALUE__"); // ugly-- avert your eyes! -} - -typedef std::function bound_call; - -struct server -{ - std::map methods; -}; - -std::string test_fn(const std::string s0, const std::string s1) -{ - return s0 + " " + s1; -} - -/* -template -void check_signature(const property_signature_vector& param_types, ParamsT ...params) -{ - -} - -struct call -{ - template - static return_property operator()(bound_call& f, const property_signature return_type, const property_signature_vector& param_types, ParamsT ...params) - { - check_signature(param_types, params...); - - auto result = f(params...); - - check_signature(return_type, result); - - return result; - } -*/ - -/* - match type - - if type is concrete type - - return curried function for that thing - - this binds eventually to property(property_list), but calls underlying fn -*/ - -OC::OCReflect::property_signature head(const OC::OCReflect::property_signature_vector& psv) -{ - return psv[0]; -} - -// sloooow, but it will suit our purpose: -OC::OCReflect::property_signature_vector tail(const OC::OCReflect::property_signature_vector psv) -{ - return OC::OCReflect::property_signature_vector(1 + psv.begin(), psv.end()); -} - -bool type_matches(const OC::OCReflect::property_type& expected_pt, const OC::OCReflect::property_data& in) -{ - auto begin = in.begin(); - - auto found_pt = static_cast(*begin); - - std::cout << "val ept=" << (int)expected_pt << ", ept: " << (int)found_pt << '\n'; - - return expected_pt == found_pt; -} - -bool type_matches(const OC::OCReflect::property_type expected_pt, const OC::OCReflect::property& in) -{ - return type_matches(expected_pt, std::get<1>(in)); -} - -bool signature_matches(const OC::OCReflect::property_signature&) -{ - return true; -} - -/* JFW: tmp -template -bool signature_matches(const OC::OCReflect::property_signature& expected, X x) -{ - return type_matches(expected.type, OC::OCReflect::make_property::apply(x, "_")); -} - -template -bool signature_matches(const OC::OCReflect::property_signature_vector expected, X x, XS ...xs) -{ - return signature_matches(head(expected), x) && signature_matches(tail(expected), xs...); -} - -template -bool signature_matches(const OC::OCReflect::property_signature_vector expected, XS ...xs) -{ - return signature_matches(head(expected), x) && signature_matches(tail(expected), xs...); - // return signature_matches(expected, xs...); -} -*/ - -void call_test() -{ - server s; - - s.methods["test_fn"] = - [](const property_vector& in) -> return_property - { - for(const auto& p : in) - std::cout << p << '\n'; - - auto s0 = concretize(in[0]); - auto s1 = concretize(in[1]); - - return make_return_property(test_fn(s0, s1)); - }; - - property_vector pv; - pv.emplace_back(make_property::apply("Hello", "s0")); - pv.emplace_back(make_property::apply("World", "s1")); - - std::cout << "INPUT:\n" << pv << '\n'; - - auto result = s.methods["test_fn"](pv); - - std::cout << concretize(std::get<1>(result)); - - using namespace OC::OCReflect; - - // typechecking: - { - auto foo = make_property::apply("Hi there", "s0"); - assert(false == type_matches(property_type::boolean, foo)); - assert(true == type_matches(property_type::string, foo)); - } - -/* JFW: tmp - // signature typechecking: - { - property_signature_vector sig { - { property_type::string }, - { property_type::integer } - }; - - assert(false == signature_matches(sig, 5, "Hello")); - assert(true == signature_matches(sig, "Hello", 5)); - } -*/ - -/* - auto sig = make_fun_sig(property_type::string, // result - property_type::string, property_type::string); // params - std::cout << sig << '\n'; -*/ -/* - auto f = make_fun(test_fn, - property_type::string, // result - property_type::string, property_type::string); // params -*/ -} - -// Demo of how to generate OCStack stuff (talk to the C library): -void rep_test() -{ - using OC::OCReflect::property_type; - using OC::OCReflect::property_binding; - - property_binding_vector sigs { - property_binding("state", property_type::boolean), - property_binding("power", property_type::integer) - }; - - using namespace OC::OCReflect::OCStack; - - /* JFW: note: - char *LEDrep[] = { "state;b", "power;i", NULL}; - - char **LEDrep = convert(convert(sigs)); - - if(0 == LEDrep) - error(); - - CREATE_RESOURCE_TYPE(LED, "core.led", LEDrep); - */ - - std::vector reps { convert(sigs) }; - for(const auto& r : reps) - std::cout << "converted representation: " << r << '\n'; - - // Example of flattening to a single string: - char *flattened = flatten(reps); - if(nullptr == flattened) - throw std::runtime_error("couldn't flatten"); - - std::cout << "FLATTENED: " << flattened << '\n'; - - // Example of converting to an array of char*s: - char **handle = convert(reps); - - if(nullptr == handle) - { - release(flattened); - throw std::runtime_error("handle is a nullptr"); - } - - std::for_each(handle, handle + length(handle), [](const char *s) { std::cout << s << '\n'; }); - - /* ...or, you could do it this way (sad panda!): - for(char **cursor = handle; nullptr != *cursor; ++cursor) - printf("%s\n", *cursor); - */ - - release(handle); // remember to free the memory! (Note: nobody said you couldn't wrap this in a smart ptr --JFW) - release(flattened); -} - -// Convert to and from OCStack representation: -void from_rep_test() -{ - property_binding_vector sigs { - property_binding("state", property_type::boolean), - property_binding("power", property_type::integer) - }; - - using OC::OCReflect::OCStack::length; - using OC::OCReflect::OCStack::convert; - - using OC::OCReflect::OCStack::expand; - using OC::OCReflect::OCStack::flatten; - - using OC::OCReflect::OCStack::as_property_binding_vector; - - std::vector reps { convert(sigs) }; // convert a property_binding_vector to a std::vector of std::string - - /* First, let's make some C data from OCReflect stuff: - IMPORTANT: error checking is ignored below, DO NOT do this in real code. :-) */ - char *flattened = flatten(reps); // convert a vector of std::string to a single C string - char **handle = convert(reps); // convert a vector of std::string into a C array of C strings - - /* Great, now let's convert back to OCReflect: */ - // C array to std::vector of std::string (just normal C++): - std::vector reps_in1 { handle, length(handle) + handle }; - - std::cout << "Retreived from C array:\n"; - for(const auto& s : reps_in1) - std::cout << s << '\n'; - - // C string into std::vector of std::string: - std::vector reps_in2 { expand(flattened) }; - - std::cout << "Retrieved from flattened C string:\n"; - for(const auto& s : reps_in2) - std::cout << s << '\n'; - - /* Now, convert a std::vector of std::string into a vector of property bindings: */ - property_binding_vector sigs_in1 { as_property_binding_vector(reps_in1) }; - std::cout << "Retreived properties from vector:\n"; - for(const auto sig : sigs_in1) - std::cout << sig << '\n'; - - // Notice that either representation /source/ is fine, it's just a vector of strings! - property_binding_vector sigs_in2 { as_property_binding_vector(reps_in2) }; - for(const auto sig : sigs_in1) - std::cout << sig << '\n'; -} - -void simple_test() -{ - using namespace std; - - OC::OCReflect::property p = make_property::apply("Sashi", "p_first_name"); - - string lname = "Penta"; - - auto p2 = make_property::apply(lname, "p_last_name"); - - cout << p << '\n'; - - std::string fname = concretize(p); - cout << "string back from property: " << fname << '\n'; -} - -/* Note: -template -void concretize(const property& p, OutT& out) -{ - out = concretize(p); -} -*/ - -int main() -{ - - convert_test(); - - call_test(); - - simple_test(); - - rep_test(); - - from_rep_test(); -} diff --git a/include/IServerWrapper.h b/include/IServerWrapper.h index fb6d710..85fe31f 100644 --- a/include/IServerWrapper.h +++ b/include/IServerWrapper.h @@ -24,9 +24,9 @@ #include #include -#include #include #include +#include #include using namespace OC::OCReflect; diff --git a/include/OCProperties.h b/include/OCProperties.h deleted file mode 100644 index 74264cd..0000000 --- a/include/OCProperties.h +++ /dev/null @@ -1,199 +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. -// -//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= -#ifndef __INTEL_OCPROPERTIES_H_20140708 - #define __INTEL_OCPROPERTIES_H_20140708 - -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include -#include - -#include "OCException.h" -#include "OCPropertyTypes.h" - -// Prettyprinters: -namespace OC { namespace OCReflect { - -std::ostream& operator<<(std::ostream& os, const OC::OCReflect::property_type& pt); -std::ostream& operator<<(std::ostream& os, const OC::OCReflect::property_attribute& pa); -std::ostream& operator<<(std::ostream& os, const OC::OCReflect::property_signature& ps); -std::ostream& operator<<(std::ostream& os, const OC::OCReflect::property_binding& pb); -std::ostream& operator<<(std::ostream& os, const OC::OCReflect::property& p); - -std::ostream& operator<<(std::ostream& os, const OC::OCReflect::property_type_vector& pv); -std::ostream& operator<<(std::ostream& os, const OC::OCReflect::property_vector& p); - -std::ostream& operator<<(std::ostream& os, const OC::OCReflect::method_binding& mb); - -}} // namespace OC::OCReflect - -// Convert from a concrete type to a property: -namespace OC { namespace OCReflect { namespace to_property { - -OC::OCReflect::tagged_property convert(const bool& in); -OC::OCReflect::tagged_property convert(const int& in); -OC::OCReflect::tagged_property convert(const int64_t& in); -OC::OCReflect::tagged_property convert(const double& in); -OC::OCReflect::tagged_property convert(const std::string& in); - -}}} // namespace OC::OCReflect::to_property - -// Convert from a property to a concrete type: -namespace OC { namespace OCReflect { namespace from_property { - -typedef OC::OCReflect::property_data::const_iterator pdci; -typedef std::tuple pd_iter_pair; - -/* We need to use a struct to get around the fact that we can't partially specialize against a -free function's signature-- nothing else special happening here: */ -struct conversion { - -static void convert(const pd_iter_pair& in, bool& out) -{ - out = static_cast(static_cast(*(std::get<0>(in)))); -} - -static void convert(const pd_iter_pair& in, int64_t& out) -{ - std::copy(std::get<0>(in), std::get<1>(in), reinterpret_cast(&out)); -} - -static void convert(const pd_iter_pair& in, double& out) -{ - std::copy(std::get<0>(in), std::get<1>(in), reinterpret_cast(&out)); -} - -static void convert(const pd_iter_pair& in, std::string& out) -{ - out.assign(std::get<0>(in), std::get<1>(in)); -} - -}; - -}}} // namespace OC::OCReflect::from_property - -// Run-time typechecking: -namespace OC { namespace OCReflect { - -typedef std::tuple pd_iter_tuple; -pd_iter_tuple consume_typecheck(const OC::OCReflect::property_type expected_pt, const OC::OCReflect::property_data& in); - -}} // namespace OC::OCReflect - -// Property binding factory: -namespace OC { namespace OCReflect { - -inline OC::OCReflect::property_binding make_property_binding(const std::string& name, const OC::OCReflect::property_signature ps) -{ - return OC::OCReflect::property_binding { name, ps }; -} - -inline OC::OCReflect::property_binding make_property_binding(const std::string& name, const OC::OCReflect::property_type pt, const OC::OCReflect::property_attribute pa = OC::OCReflect::property_attribute::rw) -{ - return OC::OCReflect::property_binding { name, { pt, pa } }; -} - -}} // namespace OC::OCReflect - -// ...probably not-so-efficent, but we want it "working" for now: -namespace OC { namespace OCReflect { - -// ...a class just to facilitate the usual ADL trick: -struct make_property { - -// ...work around array->bool conversion: -static OC::OCReflect::property apply(const char *in, const std::string& name) -{ - return apply(std::string(in), name); -} - -template -static OC::OCReflect::property apply(const InT& in, const std::string& name) -{ - OC::OCReflect::tagged_property tp { OC::OCReflect::to_property::convert(in) }; - OC::OCReflect::property_binding npb { OC::OCReflect::make_property_binding(name, std::get<0>(tp)) }; - - OC::OCReflect::property_data& tp_data = std::get<1>(tp); - - // Encode the type, followed by the data: - OC::OCReflect::property_data encoded_data; - - encoded_data.push_back(OC::OCReflect::map_property_type::value); - std::copy(std::begin(tp_data), std::end(tp_data), std::back_inserter(encoded_data)); - - return OC::OCReflect::property(npb, encoded_data); -} - -}; // struct make_property - -}} // namespace OC::OCReflect - -namespace OC { namespace OCReflect { - -template -OutT concretize(const OC::OCReflect::property_data& pd) -{ - OutT ret; - - OC::OCReflect::from_property::conversion::convert( - consume_typecheck( - static_cast( - OC::OCReflect::map_property_type::value), pd), ret); - - return ret; -} - -template -OutT concretize(const OC::OCReflect::tagged_property& tp) -{ - return concretize(std::get<1>(tp)); -} - -template -OutT concretize(const OC::OCReflect::property& p) -{ - return concretize(std::get<1>(p)); -} - -}} // namespace OC::OCReflect - -/* JFW: We are using concretize<> to fill this niche-- candidate for removal: -namespace OC { namespace OCReflect { - -// Runtime dynamic cast from entities to concrete types: -template -OutT narrow(const entity& e) -{ - return OutT(); // placeholder -} - -}} // namespace OC::OCReflect -*/ - -#endif diff --git a/include/OCPropertyTypes.h b/include/OCPropertyTypes.h deleted file mode 100644 index 523fa98..0000000 --- a/include/OCPropertyTypes.h +++ /dev/null @@ -1,248 +0,0 @@ - -#ifndef __INTEL_OCPROPERTY_TYPES_H_20140723 - #define __INTEL_OCPROPERTY_TYPES_H_20140723 - -#include -#include -#include -#include - -namespace OC { namespace OCReflect { - -enum class property_type : uint8_t { - nil = 1, - boolean, - integer, - rational, - string, - list, - - INVALID -}; - -enum class property_attribute : uint8_t { - r, - w, - rw -}; - -struct property_signature -{ - OC::OCReflect::property_type type; - OC::OCReflect::property_attribute attribute; - - public: - property_signature() - : type(OC::OCReflect::property_type::nil), - attribute(OC::OCReflect::property_attribute::rw) - {} - - property_signature(const OC::OCReflect::property_type& type_) - : type(type_), - attribute(OC::OCReflect::property_attribute::rw) - {} - - property_signature(const OC::OCReflect::property_type type_, const OC::OCReflect::property_attribute attribute_) - : type(type_), - attribute(attribute_) - {} -}; - -typedef std::vector property_type_vector; - -typedef std::vector property_signature_vector; - -typedef std::vector property_data; - -typedef std::tuple property_binding; // ie. name + signature -typedef std::vector property_binding_vector; - -typedef std::tuple property; -typedef std::tuple tagged_property; // eg. a return value - -typedef std::vector property_vector; - -typedef std::function bound_function; - - -}} // namespace OC::OCReflect - -namespace OC { namespace OCReflect { - -namespace detail { - -// zip a property type vector against an attribute: -inline property_signature_vector typev2signaturev(const property_type_vector& ptv, const property_attribute pa = property_attribute::rw) -{ - property_signature_vector psv(ptv.size()); - - std::transform(std::begin(ptv), std::end(ptv), std::back_inserter(psv), - [&pa](const property_type& pt) -> property_signature { return property_signature(pt, pa); }); - - return psv; -} - -// Helper for constructing sequences (like vector) from a parameter pack: -template -SeqT make_seq(const T& x) -{ - return SeqT { x }; -} - -template -SeqT make_seq(const T& x, const TS&... xs) -{ - SeqT s { x }; - - auto vs = make_seq(xs...); - - s.insert(s.end(), std::make_move_iterator(vs.begin()), std::make_move_iterator(vs.end())); - - return s; -} - -} // namespace OC::OCReflect::detail - -struct method_signature -{ - property_signature ret_signature; - property_signature_vector param_signatures; - - public: - method_signature(const property_type& return_type, const property_signature_vector& param_types_) - : ret_signature(return_type, OC::OCReflect::property_attribute::r), - param_signatures(param_types_) - {} - - method_signature(const property_type& return_type, const property_type_vector& param_types_) - : ret_signature(return_type, OC::OCReflect::property_attribute::r), - param_signatures(detail::typev2signaturev(param_types_)) - {} - - template - method_signature(const property_type& return_type, const ParameterT& ...params_) - : ret_signature(return_type, OC::OCReflect::property_attribute::r), - param_signatures { detail::make_seq(params_...) } - {} -}; - -}} // namespace OC::OCReflect - -namespace OC { namespace OCReflect { - -struct method_binding -{ - friend std::ostream& operator<<(std::ostream& os, const OC::OCReflect::method_binding& mb); - - public: - std::string name; - bound_function f; - method_signature signature; - - private: - static unsigned long long anon; - - public: - method_binding() - : name("__ANONYMOUS__"), - signature { property_type::nil, {{ property_type::nil, property_attribute::r }} } - {} - - method_binding(bound_function& f, - method_signature& signature_) - : signature(signature_) - {} - - method_binding(const std::string& name_, bound_function& f_, - const property_type& return_type_, const property_type_vector& param_types_) - : name(name_), - f(f_), - signature { return_type_, param_types_ } - {} - - method_binding(const std::string& name_, bound_function& f_, - const method_signature& signature_) - : name(name_), - f(f_), - signature(signature_) - {} -}; - -}} // namespace OC::OCReflect - - -// Map concerete to property type enumerations (used for returning runtime types from compile time types): -namespace OC { namespace OCReflect { - -template -struct map_property_type -{ - static const uint8_t value = static_cast(OC::OCReflect::property_type::INVALID); -}; - -template <> -struct map_property_type -{ - static const uint8_t value = static_cast(OC::OCReflect::property_type::boolean); -}; - -template <> -struct map_property_type -{ - static const uint8_t value = static_cast(OC::OCReflect::property_type::integer); -}; - -template <> -struct map_property_type -{ - static const uint8_t value = static_cast(OC::OCReflect::property_type::rational); -}; - -template <> -struct map_property_type -{ - static const uint8_t value = static_cast(OC::OCReflect::property_type::string); -}; - -template <> -struct map_property_type -{ - static const uint8_t value = static_cast(OC::OCReflect::property_type::string); -}; - -/* -// Sequence containers: -template <> -struct map_property_type< template > -{ - static const uint8_t value = static_const(OC::OCReflect::property_type::list); -}; - -template <> -struct map_property_type -{ - static const uint8_t value = static_const(OC::OCReflect::property_type::list); -}; - -template <> -struct map_property_type -{ - static const uint8_t value = static_const(OC::OCReflect::property_type::list); -}; - -template <> -struct map_property_type -{ - static const uint8_t value = static_const(OC::OCReflect::property_type::list); -}; - -template <> -struct map_property_type -{ - static const uint8_t value = static_const(OC::OCReflect::property_type::list); -}; -*/ - -}} // namespace OC::OCReflect - -#endif diff --git a/include/OCReflect.h b/include/OCReflect.h deleted file mode 100644 index 827216c..0000000 --- a/include/OCReflect.h +++ /dev/null @@ -1,128 +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. -// -//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - -#ifndef __INTEL_OCREFLECT_H_20140708 - #define __INTEL_OCREFLECT_H_20140708 - -#include - -/* Runtime reflection support. */ - -#include -#include -#include -#include -#include -#include -#include - -#include "OCServer.h" -#include "OCProperties.h" - -namespace OC { namespace OCReflect { - -struct service; -class remote_resource; -struct entity; -class method; - -struct service -{ - template - NarrowT property(const OC::OCReflect::entity& entity); - - OC::OCReflect::method method(const std::string& name); -}; - -/* This type originally represented a binding to a server-- I think it can probably -be factored out soon: */ -class remote_resource -{ - OC::OCResource& resource; - - std::string resource_location; - - public: - remote_resource(OC::OCResource& resource_, const std::string& resource_location_) - : resource(resource_), - resource_location(resource_location_) - {} - - public: - OC::OCReflect::entity operator()(const std::string& name); -}; - -struct entity -{ - // underlying type; data buffer; ctor may only be invoked from a remote resource -}; - -class method -{ - OC::OCResource *resource; // observing ptr - - std::string name; - - public: - /* This default ctor will go away once real narrowing is functional-- here to placate the compiler for now. - - Ultimately, you should never be able to construct one of these in an invalid state. */ - method() - : resource { nullptr } - {} - - method(OC::OCResource& resource_, const std::string& name_) - : resource(&resource_), - name(name_) - {} - - public: - /* Note that this declaration will likely change in the near future: */ - template - OC::OCReflect::tagged_property operator()(TS ...xs) - { - return OC::OCReflect::tagged_property(); - }; -}; - -}} // namespace OC::OCReflect - -// Convert to underlying OCStack C API (and, some handy C-wrangling utilities): -namespace OC { namespace OCReflect { namespace OCStack { - -void release(char *in); -void release(char **in); -char *strdup(const char *s); -char *strdup(const std::string& s); -size_t length(char **in); -char **convert(const std::vector& vs); - -std::string convert(const property_binding& npb); -std::vector convert(const property_binding_vector& psv); - -OC::OCReflect::property_type as_property_type(const std::string& pt_rep); -OC::OCReflect::property_binding as_property_binding(const std::string& pb_rep); -OC::OCReflect::property_binding_vector as_property_binding_vector(const std::vector& pb_reps); - -char *flatten(const std::vector& input, const std::string& delim = ";"); -std::vector expand(const char *flattened_string, const std::string& delim = ";"); - -}}} // namespace OC::OCReflect::OCStack - -#endif diff --git a/include/OCServer.h b/include/OCServer.h deleted file mode 100644 index 47b4e08..0000000 --- a/include/OCServer.h +++ /dev/null @@ -1,124 +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 OCServer.h - -/// @brief This file contains the declaration of classes and its members required to provide -/// functionality of a server. A server role supports resoruce registration, binding -/// and advertisement. - -#ifndef __OCSERVER_H -#define __OCSERVER_H - -#include -#include - -#include "OCObject.h" -#include "OCPropertyTypes.h" -#include "OCSecurityModel.h" - -namespace OC -{ - /** - @brief A server instance which is the starting point for a UB device that wishes to host a - set of resource(s) for other devices. - */ - class OCServer - { - /* 1) It may be worth considering Boost's lock-free containers here; - 2) The only reason bindings rather than the "real things" are shown in this case is because of - an assumption that the real things lie within the C layer. In practice, there's no firm reason - why it needs to be one way or the other-- in fact, a pure C++ implementation might as well - just store all the actual methods and properties in one place: */ - private: - std::map method_bindings; - std::map property_bindings; - - public: - OCServer(void); - virtual ~OCServer(void); - - /** - * @fn This registers a security model for access control to resources under this service. - * - * @param model - Security Model required for access to this service and control/view of it's - * services. - */ - void setSecurityModel(OCSecurityModel model) ; - - /** - * @fn Registers a resource with the service. - * - * @param object - The OCObject that handles the resource requests - * @param url - The URL under the resource. - * @param accessControl - The access control handler that determines whether the remote device is - * allowed to access this resource. If NULL, all access is granted. - */ - void registerResource(OCObject *object, std::string url/* TODO: , AccessControl accessControl */); - - /** - * @fn Unregisters a resource with the service. - * - * @param object - The OCObject to be unregistered. - */ - void unregisterResource(OCObject *object); - - /** - * @fn Starts the open connectivity service. - * - * Thread-Safety: TODO Determine if it is going to be safe to call in a UI thread - */ - void start(); - - /** - * Stops the open connectivity service. - * - * Thread-Safety: TODO Determine if it is going to be safe to call in a UI thread - */ - void stop(); - - public: - void bind(const OC::OCReflect::method_binding& mb); - void bind(const OC::OCReflect::property_binding& pb); - - template - void registerResource(T *object, const std::string& base_URI) - {} - - // Note that these transfer the /binding information/ (signatures, etc.) not data (which could be /very/ expensive): - public: - const std::map& methods() const { return method_bindings; } - const std::map& properties() const { return property_bindings; } - - // Transfer data: - public: - // Look up the method from the binding, call the function, return a full property as result: - // OC::OCReflect::property call(const std::pair& method); // other signatures possible, this is an example - - // Look up the property from the binding, return a full property (ie. with a data value): - OC::OCReflect::property get(const std::string& p_name); - OC::OCReflect::property get(const OC::OCReflect::property_binding& pb); - - // Set a property's value: - void set(const OC::OCReflect::property& p); - }; -} - -#endif //__OCSERVER_H diff --git a/makefile b/makefile index 4a22ec8..a185996 100644 --- a/makefile +++ b/makefile @@ -6,8 +6,8 @@ CXX := g++ OUT_DIR := $(PWD)/$(BUILD) OBJ_DIR := $(OUT_DIR)/obj -CXX_FLAGS.debug := -g3 -std=c++0x -Wall -pthread -O0 -CXX_FLAGS.release := -std=c++0x -Wall -pthread -O3 +CXX_FLAGS.debug := -g3 -std=c++0x -Wall -pthread -O0 +CXX_FLAGS.release := -std=c++0x -Wall -pthread -O3 CXX_INC := -I./include/ CXX_INC += -I./csdk/stack/include @@ -17,7 +17,7 @@ CXX_INC += -I./csdk/logger/include CXX_INC += -I./csdk/libcoap # Force metatargets to build: -.PHONY: prep_dirs c_sdk liboc.a examples +.PHONY: prep_dirs c_sdk liboc.a examples all: .PHONY @@ -25,17 +25,14 @@ prep_dirs: -mkdir -p $(OUT_DIR) -mkdir -p $(OBJ_DIR) -c_sdk: +c_sdk: cd csdk && $(MAKE) "BUILD=$(BUILD)" -examples: +examples: cd examples && $(MAKE) "BUILD=$(BUILD)" -liboc.a: OCPlatform.o OCResource.o OCReflect.o OCUtilities.o InProcServerWrapper.o InProcClientWrapper.o - ar -cvq $(OBJ_DIR)/liboc.a $(OBJ_DIR)/OCPlatform.o $(OBJ_DIR)/OCResource.o $(OBJ_DIR)/OCReflect.o $(OBJ_DIR)/OCUtilities.o $(OBJ_DIR)/InProcServerWrapper.o $(OBJ_DIR)/InProcClientWrapper.o - -OCReflect.o: src/OCReflect.cpp - $(CXX) $(CXX_FLAGS.$(BUILD)) -o $(OBJ_DIR)/$@ -c src/OCReflect.cpp $(CXX_INC) +liboc.a: OCPlatform.o OCResource.o OCUtilities.o InProcServerWrapper.o InProcClientWrapper.o + ar -cvq $(OBJ_DIR)/liboc.a $(OBJ_DIR)/OCPlatform.o $(OBJ_DIR)/OCResource.o $(OBJ_DIR)/OCUtilities.o $(OBJ_DIR)/InProcServerWrapper.o $(OBJ_DIR)/InProcClientWrapper.o OCPlatform.o: src/OCPlatform.cpp $(CXX) $(CXX_FLAGS.$(BUILD)) -o $(OBJ_DIR)/$@ -c src/OCPlatform.cpp $(CXX_INC) @@ -59,4 +56,4 @@ clean: clean_legacy cd csdk && $(MAKE) deepclean cd examples && $(MAKE) clean clean_legacy: - -rm -f -v $(OBJ_DIR)/liboc.a $(OBJ_DIR)/*.o + -rm -f -v $(OBJ_DIR)/liboc.a $(OBJ_DIR)/*.o diff --git a/src/InProcServerWrapper.cpp b/src/InProcServerWrapper.cpp index 7721543..cb172f5 100644 --- a/src/InProcServerWrapper.cpp +++ b/src/InProcServerWrapper.cpp @@ -29,7 +29,6 @@ #include #include -#include #include #include #include @@ -344,7 +343,7 @@ namespace OC std::lock_guard lock(*cLock); result = OCStartPresence(seconds); } - + if(result != OC_STACK_OK) { throw OCException("startPresence failed", result); @@ -361,7 +360,7 @@ namespace OC std::lock_guard lock(*cLock); result = OCStopPresence(); } - + if(result != OC_STACK_OK) { throw OCException("stopPresence failed", result); diff --git a/src/OCReflect.cpp b/src/OCReflect.cpp deleted file mode 100644 index 4727b40..0000000 --- a/src/OCReflect.cpp +++ /dev/null @@ -1,263 +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. -// -//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - - -#include -#include -#include -#include - -#include -#include - -#include "OCReflect.h" - -OC::OCReflect::entity OC::OCReflect::remote_resource::operator()(const std::string& name) -{ - return OC::OCReflect::entity(); -} - -namespace OC { namespace OCReflect { namespace OCStack { - -// Free a char *: -void release(char *in) -{ - if(nullptr == in) - return; - - free(in); -} - -// Free a C array of char *: -void release(char **in) -{ - if(nullptr == in) - return; - - for(char **cursor = in; nullptr != *cursor; ++cursor) - release(*cursor); - - free(in); -} - -char *strdup(const char *s) -{ - if(nullptr == s) - return nullptr; - - char *ret = static_cast(malloc(1 + strlen(s))); - - if(nullptr == ret) - return nullptr; - - return strcpy(ret, s); -} - -char *strdup(const std::string& s) -{ - char *ret = static_cast(malloc(1 + s.length())); - - if(nullptr == ret) - return nullptr; - - return strcpy(ret, s.c_str()); -} - -// Count the number of elements in a NULL-terminated C array of char*: -size_t length(char **in) -{ - if(nullptr == in) - return 0; - - size_t ret = 0; - - for(char **cursor = in; nullptr != *cursor; ++cursor) - ++ret; - - return ret; -} - -// Note: caller is responsible for the returned memory: -char **convert(const std::vector& vs) -{ - char **out; - - try - { - out = (char **)malloc(vs.size()*sizeof(char *)); - - if(nullptr == out) - throw; - - size_t i = 0; - for(; vs.size() != i; ++i) - { - out[i] = OCStack::strdup(vs[i]); - - if(nullptr == out[i]) - throw; - } - - out[i] = nullptr; - - return out; - } - catch(...) - { - if(nullptr != out) - release(out); - } - - return nullptr; -} - -std::string convert(const OC::OCReflect::property_binding& npb) -{ - const std::string& name = std::get<0>(npb); - const OC::OCReflect::property_signature ps = std::get<1>(npb); - - std::ostringstream os; - - os << name << ':' << "oc."; - - using OC::OCReflect::property_type; - - switch(ps.type) - { - case property_type::nil: - case property_type::rational: - case property_type::list: - case property_type::string: - // Sashi commented this line to fix the build error - //os << "convert(): request to convert valid, but unimplemented type: " << ps.type; - throw std::runtime_error(os.str()); - break; - - case property_type::INVALID: - throw std::runtime_error("convert(): request to convert invalid type"); - break; - - case property_type::boolean: os << "bt." << 'b'; - break; - - case property_type::integer: os << "bt." << 'i'; - break; - } - - return os.str(); -} - -OC::OCReflect::property_type as_property_type(const std::string& pb_code) -{ - // We expect: "oc.bt.": - const size_t code_length = 7, - code_pos = 6; - - if(code_length != pb_code.length()) - return OC::OCReflect::property_type::INVALID; - - switch(pb_code[code_pos]) - { - default: break; - - case 'b': return OC::OCReflect::property_type::boolean; - case 'i': return OC::OCReflect::property_type::integer; - -/* These don't have codes yet: - case property_type::nil: - case property_type::rational: - case property_type::string: - case property_type::list: -*/ - } - - return OC::OCReflect::property_type::INVALID; -} - -OC::OCReflect::property_binding as_property_binding(const std::string& pb_rep) -{ - auto delim_pos = pb_rep.find_first_of(':'); - - if(pb_rep.length() == delim_pos) - throw OC::reflection_exception("convert(): invalid property string (missing delimiter)"); - - std::string pname { pb_rep.substr(0, delim_pos) }; - - auto ptype = as_property_type(pb_rep.substr(1 + delim_pos)); - - auto pattr = OC::OCReflect::property_attribute::rw; // We aren't handling attributes right now... - - return OC::OCReflect::property_binding { pname, { ptype, pattr } }; -} - -OC::OCReflect::property_binding_vector as_property_binding_vector(const std::vector& pb_reps) -{ - OC::OCReflect::property_binding_vector pbv; - - for(const auto& s : pb_reps) - pbv.emplace_back(as_property_binding(s)); - - return pbv; -} - -std::vector convert(const OC::OCReflect::property_binding_vector& psv) -{ - std::vector out; - - for(const auto& ps : psv) - out.push_back(convert(ps)); - - return out; -} - -char *flatten(const std::vector& input, const std::string& delim) -try -{ - std::string out; - - for(size_t i = 0; input.size() != i; ++i) - { - out += input[i]; - - if(i < input.size() - 1) - out += delim; - } - - return OC::OCReflect::OCStack::strdup(out); -} -catch(...) -{ - return nullptr; -} - -// Note: expects output of flatten(): -std::vector expand(const char *flattened_string, const std::string& delim) -{ - if(nullptr == flattened_string) - throw OC::reflection_exception("nullptr passed to expand()"); - - std::vector ret; - std::string flattened = flattened_string; - boost::split(ret, flattened, boost::is_any_of(delim)); - - return ret; -} - -}}} // namespace OC::OCReflect::OCStack diff --git a/src/OCResource.cpp b/src/OCResource.cpp index 564965f..b369155 100644 --- a/src/OCResource.cpp +++ b/src/OCResource.cpp @@ -19,17 +19,23 @@ //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= #include "OCResource.h" -#include "OCReflect.h" namespace OC { - OCResource::OCResource(std::weak_ptr clientWrapper, const std::string& host, const std::string& uri, bool observable, const std::vector& resourceTypes, const std::vector& interfaces) : - m_clientWrapper(clientWrapper), m_uri(uri), m_host(host), m_isObservable(observable), m_isCollection(false), m_resourceTypes(resourceTypes), m_interfaces(interfaces), m_observeHandle(nullptr) + OCResource::OCResource(std::weak_ptr clientWrapper, const std::string& host, + const std::string& uri, bool observable, const std::vector& resourceTypes, + const std::vector& interfaces) : + m_clientWrapper(clientWrapper), m_uri(uri), m_host(host), m_isObservable(observable), + m_isCollection(false), m_resourceTypes(resourceTypes), m_interfaces(interfaces), + m_observeHandle(nullptr) { - m_isCollection = std::find(m_interfaces.begin(), m_interfaces.end(), LINK_INTERFACE) != m_interfaces.end(); + m_isCollection = std::find(m_interfaces.begin(), m_interfaces.end(), LINK_INTERFACE) + != m_interfaces.end(); - if (m_uri.empty() || resourceTypes.empty() || interfaces.empty()|| m_clientWrapper.expired()) + if (m_uri.empty() || resourceTypes.empty() + || interfaces.empty()|| m_clientWrapper.expired()) { - throw ResourceInitException(m_uri.empty(), resourceTypes.empty(), interfaces.empty(), m_clientWrapper.expired()); + throw ResourceInitException(m_uri.empty(), resourceTypes.empty(), + interfaces.empty(), m_clientWrapper.expired()); } } @@ -37,7 +43,8 @@ namespace OC { { } - OCStackResult OCResource::get(const QueryParamsMap& queryParametersMap, GetCallback attributeHandler) + OCStackResult OCResource::get(const QueryParamsMap& queryParametersMap, + GetCallback attributeHandler) { auto cw = m_clientWrapper.lock(); @@ -51,8 +58,9 @@ namespace OC { } } - OCStackResult OCResource::get(const std::string& resourceType, const std::string& resourceInterface, - const QueryParamsMap& queryParametersMap, GetCallback attributeHandler) + OCStackResult OCResource::get(const std::string& resourceType, + const std::string& resourceInterface, const QueryParamsMap& queryParametersMap, + GetCallback attributeHandler) { auto cw = m_clientWrapper.lock(); @@ -77,14 +85,15 @@ namespace OC { } } - OCStackResult OCResource::put(const OCRepresentation& rep, const QueryParamsMap& queryParametersMap, - PutCallback attributeHandler) + OCStackResult OCResource::put(const OCRepresentation& rep, + const QueryParamsMap& queryParametersMap, PutCallback attributeHandler) { auto cw = m_clientWrapper.lock(); if(cw) { - return cw->SetResourceAttributes(m_host, m_uri, rep, queryParametersMap, attributeHandler); + return cw->SetResourceAttributes(m_host, m_uri, rep, queryParametersMap, + attributeHandler); } else { @@ -92,8 +101,9 @@ namespace OC { } } - OCStackResult OCResource::put(const std::string& resourceType, const std::string& resourceInterface, - const OCRepresentation& rep, const QueryParamsMap& queryParametersMap, + OCStackResult OCResource::put(const std::string& resourceType, + const std::string& resourceInterface, const OCRepresentation& rep, + const QueryParamsMap& queryParametersMap, PutCallback attributeHandler) { auto cw = m_clientWrapper.lock(); @@ -119,8 +129,8 @@ namespace OC { } } - OCStackResult OCResource::observe(ObserveType observeType, const QueryParamsMap& queryParametersMap, - ObserveCallback observeHandler) + OCStackResult OCResource::observe(ObserveType observeType, + const QueryParamsMap& queryParametersMap, ObserveCallback observeHandler) { if(m_observeHandle != nullptr) { @@ -132,7 +142,8 @@ namespace OC { if(cw) { - return cw->ObserveResource(observeType, &m_observeHandle, m_host, m_uri, queryParametersMap, observeHandler); + return cw->ObserveResource(observeType, &m_observeHandle, m_host, + m_uri, queryParametersMap, observeHandler); } else { @@ -164,15 +175,15 @@ namespace OC { } } - std::string OCResource::host() const + std::string OCResource::host() const { return m_host; } - std::string OCResource::uri() const + std::string OCResource::uri() const { return m_uri; } - bool OCResource::isObservable() const + bool OCResource::isObservable() const { return m_isObservable; } diff --git a/src/OCServer.cpp b/src/OCServer.cpp deleted file mode 100644 index 64453b3..0000000 --- a/src/OCServer.cpp +++ /dev/null @@ -1,62 +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. -// -//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - -#include "OCServer.h" -#include "OCReflect.h" -#include "OCProperties.h" - -namespace OC { - - OCServer::OCServer(void) - { - } - - - OCServer::~OCServer(void) - { - } - - void OCServer::setSecurityModel(OCSecurityModel model) { - } - - void OCServer::registerResource(OCObject *object, std::string url/* TODO: , AccessControl accessControl */) { - } - - void OCServer::unregisterResource(OCObject *object) { - } - - void OCServer::start() { - } - - void OCServer::stop() { - } - - // Method and property wrangling: - void OCServer::bind(const OC::OCReflect::method_binding& mb) - { - method_bindings[mb.name] = mb; - } - - void OCServer::bind(const OC::OCReflect::property_binding& pb) - { -std::cout << "OCServer::bind() property " << std::get<0>(pb) << '\n'; - property_bindings[std::get<0>(pb)] = pb; - } -} -- 2.7.4