4 //******************************************************************
6 // Copyright 2014 Intel Corporation.
8 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
10 // Licensed under the Apache License, Version 2.0 (the "License");
11 // you may not use this file except in compliance with the License.
12 // You may obtain a copy of the License at
14 // http://www.apache.org/licenses/LICENSE-2.0
16 // Unless required by applicable law or agreed to in writing, software
17 // distributed under the License is distributed on an "AS IS" BASIS,
18 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 // See the License for the specific language governing permissions and
20 // limitations under the License.
22 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
26 #include <condition_variable>
28 #include "OCPlatform.h"
31 #include "OICMiddle.h"
45 typedef std::shared_ptr<OCResource> ocresource_t;
46 typedef std::map<token_t, WrapRequest *> requestmap_t;
47 typedef std::function<void(const token_t token, const HeaderOptions&, const OCRepresentation&, const int, const int)> observecb_t;
52 WrapResource(string resourceID, ocresource_t resource);
54 token_t getResource();
55 token_t putResource(OCRepresentation& rep);
56 token_t observeResource(observecb_t& callback);
57 string getResourceID();
59 std::vector<std::string> getResourceTypes();
60 std::vector<std::string> getResourceInterfaces();
61 WrapRequest *waitResource(token_t token);
62 const stringmap_t& getFormats();
64 friend class WrapRequest;
65 friend class MiddleClient;
68 WrapRequest *newRequest(RequestType type);
69 void resourceCallback(WrapRequest *wreq);
70 void parseJSON(WrapRequest *wreq);
74 ocresource_t m_ocResource;
81 observecb_t m_observeCB;
82 bool m_callbackRunning;
84 requestmap_t m_requestMap;
85 WrapRequest *m_observeRequest; // can only be one
86 stringmap_t m_typeMap;
87 vector<WrapRequest *> m_typeResults;
88 WrapRequest *m_typeRequest;
93 WrapRequest(WrapResource *wres, RequestType type, token_t token);
95 friend class WrapResource;
97 HeaderOptions m_headerOptions;
98 OCRepresentation m_rep;
100 int m_sequenceNumber;
101 stringmap_t m_valueMap;
102 unsigned long m_touchTime;
105 WrapResource *m_parent;
108 condition_variable m_cvGet;
112 void getCB(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode);
113 void putCB(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode);
114 void observeCB(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode, const int sequenceNumber);
118 ObserveCallback m_obsCB;
121 #endif // WRAPRESOURCE_H