Initial merge-commit of the OIC code. Should successfully do discovery for single...
[platform/upstream/iotivity.git] / csdk / ubstack / src / ocmodelimpl.h
1 //******************************************************************
2 //
3 // Copyright 2014 Intel Corporation All Rights Reserved.
4 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
5
6
7 #ifndef OCMODELIMPL_H_
8 #define OCMODELIMPL_H_
9
10 // ============================================================================
11 // Includes
12 // ============================================================================
13 #include <memory>
14 #include <map>
15 #include <stdint.h>
16
17 #include "ocinternalapi.h"
18
19 extern "C" {
20     #include "ocstack.h"
21 }
22 // ============================================================================
23 // Namespace
24 // ============================================================================
25 namespace oc {
26 namespace ub {
27
28 class OCModelImpl : public OCModel {
29 public:
30         typedef std::shared_ptr<OCModelImpl> SharedPtr;
31         typedef std::weak_ptr<OCModelImpl> WeakPtr;
32
33 public:
34         /**
35          * Factory pattern to create a OCModel singleton
36          * @return Shared pointer to the OCModel
37          */
38         static SharedPtr createModel();
39
40 public:
41         /**
42          * Constructor
43          */
44         OCModelImpl();
45
46         /**
47          * Destructor
48          */
49         virtual ~OCModelImpl();
50
51     /**
52      * Start the OC Stack.
53      *
54      * @param ipAddr
55      *     IP Address of host device
56      * @param port
57      *     Port of host device*
58      * @param mode
59      *     Host device is client, server, or client-server
60      *
61      * @return
62      *     true  - successfully started the OC Stack
63      *     false - error starting the OC Stack
64      */
65     virtual bool start(const std::string ipAddr, int16_t port, OCStackMode mode);
66
67     /**
68      * Get all services that have been discovered at time of call
69      *
70      * @param asyncReturnFunc - asynchronous callback function that is invoked
71      *                          by the OCModelImpl when service discovery
72      *                          is complete.  The callback will include
73      *                          status and a list of all discovered services
74      */
75         virtual void discoverServices(OCDiscoverServicesFunction& asyncReturnFunc);
76
77     /**
78      * Add a service to the OCModelImpl
79      *
80      * @param url - URL of the service
81      * @return Total number of services in the OCModelImpl
82      */
83         virtual uint16_t addService(const std::string url);
84
85 private:
86     typedef std::list<std::string> ServiceList;
87
88 private:
89     /**
90      * Internal methods that invokes the client callback (if it was previously set via discoverServices)
91      * Called when a new service is discovered.
92      */
93     virtual void invokeDiscoverCallback();
94
95     /**
96      * Asynchronous callback friend function invoked by the OC Stack upon service discovery
97      *
98      * @param result         - OC stack result
99      * @param representation - handle to the representation of the resource
100      */
101     friend void asyncDoResourcesCallback(OCStackResult result, OCRepresentationHandle representation);
102 private:
103     ServiceList serviceList;
104     mutex serviceListMutex;
105     OCDiscoverServicesFunction discoverCallback;
106 };
107
108 }
109 }
110 #endif /* OCMODELIMPL_H_ */