1 //******************************************************************
3 // Copyright 2014 Intel Corporation All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 /// @file OCPlatform.h
23 /// @brief This file contains the declaration of classes and its members related to
26 #ifndef __OCPLATFORM_H
27 #define __OCPLATFORM_H
32 #include "OCResource.h"
33 #include "OCPlatformHandler.h"
34 #include "WrapperFactory.h"
35 #include <OCReflect.h>
37 using namespace OC::OCReflect;
41 using OC::OCReflect::property_type;
42 using OC::OCReflect::named_property_binding;
45 * @brief The core OC platform object initialized by the application or service via a static accessor.
46 * On successful initialization an instance of the OCPlatform is returned.
47 * Handler registered that receives various platform/stack updates. The stack object
48 * also provides methods for managing advertisement and discovery.
54 * @fn Constructor for OCPlatform. Constructs a new OCPlatform from a given PlatformConfig with
56 * @param config - PlatformConfig struct which has details such as modeType (server/client/both),
57 * in-proc/out-of-proc etc.
59 OCPlatform(const PlatformConfig& config);
62 * @fn Virtual destructor
64 virtual ~OCPlatform(void);
67 * @fn API for Service and Resource Discovery
69 * @param host - Host IP Address of a service to direct resource discovery query. If null or
70 * empty, performs service discovery OR resource discovery query to ALL group members.
71 * @param filter<std::string FilterType, std::string Value> - Filter Type - Can be one of two of the link
72 * format equivalent attribute types declared in table 7 of the
73 * OC-Lite-Product-Specification-V1 Document. Either "n" (i.e. Resource Name) or "rt"
74 * (i.e. Resource Type). Value - Can be any valid std::string that's defined to work with CoRE
75 * Link Attributes as defined in the RFC6690.
76 * @param handler - Handles callbacks, success states and failure states.
78 * Four modes of discovery defined as follows:
79 * (NULL/Empty, NULL/Empty) - Performs ALL service discovery AND ALL resource discovery.
80 * (NULL/Empty, Not Empty) - Performs query for a filtered/scoped/particular resource(s)
82 * (Not Empty, NULL/Empty) - Performs ALL resource discovery on a particular service.
83 * (Not Empty, Not Empty) - Performs query for a filtered/scoped/particular resource(s)
84 * from a particular service.
86 * Thread-Safety: TODO Determine if it is going to be safe to call in a UI thread
88 void findResource(const std::string& host, const std::string& resourceName,
89 std::function<void(OCResource::Ptr)> resourceHandler);
92 * @fn Queries the network for available resources.
94 * NOTE: This gets posted to a new thread so it doesn't hold the UI or network thread.
96 * @param serviceURL - The URL to the service. NULL for a broadcast/multicast.
97 * @param resourceType - The resource type filter. NULL for match any.
99 * @throws This may throw if the service is not started, network is bad, etc.
101 * Thread-Safety: TODO Determine if it is going to be safe to call in a UI thread
103 void findResourceByType(const std::string& serviceURL, const std::string& resourceType,
104 std::function<void(OCResource::Ptr)> resourceHandler);
107 * @fn Registers the resource with its name, type and list of properties
109 * NOTE: Properties are prepared prior to this call using generic functions from OCReflect
111 * @param resourceURI - The URI of the resoruce.
112 * @param resourceTypeName - The resource type.
113 * @param properties - vector of properties for this resource
116 void registerResource(const std::string& resourceURI, const std::string& resourceTypeName,
117 named_property_binding_vector properties);
120 std::unique_ptr<WrapperFactory> m_WrapperInstance;
121 IServerWrapper::Ptr m_server;
122 IClientWrapper::Ptr m_client;
125 * @fn Private function to initalize the platfrom
127 void init(const PlatformConfig& config);
130 * @fn Private function cleanup the platform
136 #endif //__OCPLATFORM_H