1 //******************************************************************
3 // Copyright 2014 Intel Corporation All Rights Reserved.
4 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
8 /// @brief This file contains the declaration of classes and its members related to
11 #ifndef __OCPLATFORM_H
12 #define __OCPLATFORM_H
17 #include "OCResource.h"
18 #include "OCPlatformHandler.h"
19 #include "WrapperFactory.h"
20 #include <OCReflect.h>
22 using namespace OC::OCReflect;
26 using OC::OCReflect::property_type;
27 using OC::OCReflect::named_property_binding;
30 * @brief The core OC platform object initialized by the application or service via a static accessor.
31 * On successful initialization an instance of the OCPlatform is returned.
32 * Handler registered that receives various platform/stack updates. The stack object
33 * also provides methods for managing advertisement and discovery.
39 * @fn Constructor for OCPlatform. Constructs a new OCPlatform from a given PlatformConfig with
41 * @param config - PlatformConfig struct which has details such as modeType (server/client/both),
42 * in-proc/out-of-proc etc.
44 OCPlatform(const PlatformConfig& config);
47 * @fn Virtual destructor
49 virtual ~OCPlatform(void);
52 * @fn API for Service and Resource Discovery
54 * @param host - Host IP Address of a service to direct resource discovery query. If null or
55 * empty, performs service discovery OR resource discovery query to ALL group members.
56 * @param filter<std::string FilterType, std::string Value> - Filter Type - Can be one of two of the link
57 * format equivalent attribute types declared in table 7 of the
58 * OC-Lite-Product-Specification-V1 Document. Either "n" (i.e. Resource Name) or "rt"
59 * (i.e. Resource Type). Value - Can be any valid std::string that's defined to work with CoRE
60 * Link Attributes as defined in the RFC6690.
61 * @param handler - Handles callbacks, success states and failure states.
63 * Four modes of discovery defined as follows:
64 * (NULL/Empty, NULL/Empty) - Performs ALL service discovery AND ALL resource discovery.
65 * (NULL/Empty, Not Empty) - Performs query for a filtered/scoped/particular resource(s)
67 * (Not Empty, NULL/Empty) - Performs ALL resource discovery on a particular service.
68 * (Not Empty, Not Empty) - Performs query for a filtered/scoped/particular resource(s)
69 * from a particular service.
71 * Thread-Safety: TODO Determine if it is going to be safe to call in a UI thread
73 void findResource(const std::string& host, const std::string& resourceName,
74 std::function<void(OCResource::Ptr)> resourceHandler);
77 * @fn Queries the network for available resources.
79 * NOTE: This gets posted to a new thread so it doesn't hold the UI or network thread.
81 * @param serviceURL - The URL to the service. NULL for a broadcast/multicast.
82 * @param resourceType - The resource type filter. NULL for match any.
84 * @throws This may throw if the service is not started, network is bad, etc.
86 * Thread-Safety: TODO Determine if it is going to be safe to call in a UI thread
88 void findResourceByType(const std::string& serviceURL, const std::string& resourceType,
89 std::function<void(OCResource::Ptr)> resourceHandler);
92 * @fn Registers the resource with its name, type and list of properties
94 * NOTE: Properties are prepared prior to this call using generic functions from OCReflect
96 * @param resourceURI - The URI of the resoruce.
97 * @param resourceTypeName - The resource type.
98 * @param properties - vector of properties for this resource
101 void registerResource(const std::string& resourceURI, const std::string& resourceTypeName,
102 named_property_binding_vector properties);
105 std::unique_ptr<WrapperFactory> m_WrapperInstance;
106 IServerWrapper::Ptr m_server;
107 IClientWrapper::Ptr m_client;
110 * @fn Private function to initalize the platfrom
112 void init(const PlatformConfig& config);
115 * @fn Private function cleanup the platform
121 #endif //__OCPLATFORM_H