Initial merge-commit of the OIC code. Should successfully do discovery for single...
[platform/upstream/iotivity.git] / include / OCPlatform.h
1 //******************************************************************
2 //
3 // Copyright 2014 Intel Corporation All Rights Reserved.
4 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
5
6 /// @file OCPlatform.h 
7
8 /// @brief      This file contains the declaration of classes and its members related to 
9 ///                     OCPlatform.
10
11 #ifndef __OCPLATFORM_H
12 #define __OCPLATFORM_H
13
14 #include <map>
15
16 #include "OCApi.h"
17 #include "OCResource.h"
18 #include "OCPlatformHandler.h"
19 #include "WrapperFactory.h"
20 #include <OCReflect.h>
21
22 using namespace OC::OCReflect;
23
24 namespace OC
25 {
26         using OC::OCReflect::property_type;
27         using OC::OCReflect::named_property_binding;
28
29         /**
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.  
34         */
35         class OCPlatform
36         {
37         public:
38                 /**
39                 * @fn    Constructor for OCPlatform. Constructs a new OCPlatform from a given PlatformConfig with 
40                 *                appropriate fields
41                 * @param config - PlatformConfig struct which has details such as modeType (server/client/both),
42                 *                                 in-proc/out-of-proc etc. 
43                 */
44                 OCPlatform(const PlatformConfig& config);
45
46                 /**
47                 * @fn    Virtual destructor
48                 */
49                 virtual ~OCPlatform(void);
50
51                 /**
52                 * @fn    API for Service and Resource Discovery
53                 * 
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.
62                 * 
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) 
66                 *                                  from ALL services. 
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.
70                 * 
71                 *        Thread-Safety: TODO Determine if it is going to be safe to call in a UI thread
72                 */
73                 void findResource(const std::string& host, const std::string& resourceName, 
74                         std::function<void(OCResource::Ptr)> resourceHandler);
75
76                 /**
77                 * @fn   Queries the network for available resources.
78                 * 
79                 * NOTE: This gets posted to a new thread so it doesn't hold the UI or network thread.
80                 * 
81                 * @param serviceURL - The URL to the service. NULL for a broadcast/multicast.
82                 * @param resourceType - The resource type filter. NULL for match any.
83                 * 
84                 * @throws This may throw if the service is not started, network is bad, etc.
85                 * 
86                 *         Thread-Safety: TODO Determine if it is going to be safe to call in a UI thread
87                 */
88                 void findResourceByType(const std::string& serviceURL, const std::string& resourceType,
89                         std::function<void(OCResource::Ptr)> resourceHandler);
90
91                 /**
92                 * @fn   Registers the resource with its name, type and list of properties
93                 * 
94                 * NOTE: Properties are prepared prior to this call using generic functions from OCReflect
95                 * 
96                 * @param resourceURI - The URI of the resoruce.
97                 * @param resourceTypeName - The resource type. 
98                 * @param properties - vector of properties for this resource
99                 * 
100                 */
101                 void registerResource(const std::string& resourceURI, const std::string& resourceTypeName, 
102                         named_property_binding_vector properties);
103
104         private:
105                 std::unique_ptr<WrapperFactory> m_WrapperInstance;
106                 IServerWrapper::Ptr m_server;
107                 IClientWrapper::Ptr m_client;
108
109                 /**
110                 *  @fn  Private function to initalize the platfrom 
111                 */
112                 void init(const PlatformConfig& config);
113
114                 /**
115                 *  @fn  Private function cleanup the platform
116                 */
117                 void cleanup();
118         };
119 }
120
121 #endif //__OCPLATFORM_H