1 //******************************************************************
3 // Copyright 2014 Intel Mobile Communications GmbH 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 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
22 #ifndef OCMODELIMPL_H_
23 #define OCMODELIMPL_H_
25 // ============================================================================
27 // ============================================================================
32 #include "ocinternalapi.h"
37 // ============================================================================
39 // ============================================================================
43 class OCModelImpl : public OCModel {
45 typedef std::shared_ptr<OCModelImpl> SharedPtr;
46 typedef std::weak_ptr<OCModelImpl> WeakPtr;
50 * Factory pattern to create a OCModel singleton
51 * @return Shared pointer to the OCModel
53 static SharedPtr createModel();
64 virtual ~OCModelImpl();
70 * IP Address of host device
72 * Port of host device*
74 * Host device is client, server, or client-server
77 * true - successfully started the OC Stack
78 * false - error starting the OC Stack
80 virtual bool start(const std::string ipAddr, int16_t port, OCStackMode mode);
83 * Get all services that have been discovered at time of call
85 * @param asyncReturnFunc - asynchronous callback function that is invoked
86 * by the OCModelImpl when service discovery
87 * is complete. The callback will include
88 * status and a list of all discovered services
90 virtual void discoverServices(OCDiscoverServicesFunction& asyncReturnFunc);
93 * Add a service to the OCModelImpl
95 * @param url - URL of the service
96 * @return Total number of services in the OCModelImpl
98 virtual uint16_t addService(const std::string url);
101 typedef std::list<std::string> ServiceList;
105 * Internal methods that invokes the client callback (if it was previously set via discoverServices)
106 * Called when a new service is discovered.
108 virtual void invokeDiscoverCallback();
111 * Asynchronous callback friend function invoked by the OC Stack upon service discovery
113 * @param result - OC stack result
114 * @param representation - handle to the representation of the resource
116 friend void asyncDoResourcesCallback(OCStackResult result, OCRepresentationHandle representation);
118 ServiceList serviceList;
119 mutex serviceListMutex;
120 OCDiscoverServicesFunction discoverCallback;
125 #endif /* OCMODELIMPL_H_ */