Initial merge-commit of the OIC code. Should successfully do discovery for single...
[platform/upstream/iotivity.git] / csdk / controller / src / remoting / LiteRemoting.h
1 //******************************************************************
2 //
3 // Copyright 2014 Intel Corporation All Rights Reserved.
4 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
5
6 #ifndef LITEREMOTING_H_
7 #define LITEREMOTING_H_
8
9 // ============================================================================
10 // Includes
11 // ============================================================================
12 #include <boost/shared_ptr.hpp>
13 #include <boost/thread.hpp>
14 #include <uuid.h>
15 #include <map>
16 #include <set>
17 #include "api.h"
18 using namespace Intel::STC;
19
20 #include "LiteSessionImpl.h"
21 #include "LiteUUIDLess.hpp"
22 #include "LiteTargetDevice.hpp"
23 #include "LiteTargetDeviceProxy.h"
24
25 // ============================================================================
26 // Namespace
27 // ============================================================================
28 namespace remoting {
29
30   // ==========================================================================
31   // Class
32   // ==========================================================================
33   class LiteRemoting {
34     // ============================================================
35     // Constants
36     // ============================================================
37     public:
38       static const std::string APPLICATION_UUID_STRING;
39
40     // ============================================================
41     // Type Definition
42     // ============================================================
43     public:
44       typedef boost::shared_ptr<LiteRemoting> Ptr;
45
46     // ============================================================
47     // Singleton
48     // ============================================================
49     public:
50       static boost::shared_ptr<LiteRemoting> getInstance();
51
52     // ============================================================
53     // Private key for Singleton with shared_ptr
54     // LiteRemoting ctor must be public for make_ptr.
55           // But since we are a singleton, we don't want to allow clients
56     // to call the ctor.  Since client can't access
57     // PrivateConstructKey, it can't call the public ctor.
58     // ============================================================
59     private:
60       struct PrivateConstructKey {};
61
62     // ============================================================
63     // Constructor and Destructor
64     // ============================================================
65     public:
66       LiteRemoting(PrivateConstructKey key);
67       virtual ~LiteRemoting();
68
69     // ============================================================
70     // Public Method(s)
71     // ============================================================
72     public:
73
74
75     // ============================================================
76     // Private copy constructor for Singleton
77     // ============================================================
78     private:
79       LiteRemoting(const LiteRemoting&);
80
81     // ============================================================
82     // Private Attributes
83     // ============================================================
84     private:
85       // CCF API Interface
86       API::Service::SharedPtr pCCFService_;
87       API::Context::SharedPtr pCCFContext_;
88
89       UUID_t mySessionId_;
90       std::map <UUID_t, boost::shared_ptr<LiteSessionImpl>, LiteUUIDLess> sessionMap_;
91       std::map <UUID_t, boost::shared_ptr<LiteTargetDeviceProxy>, LiteUUIDLess> targetDeviceProxyMap_;
92       boost::condition_variable cond_;
93       boost::mutex mutex_;
94       bool apiResultReady_;
95
96     // ============================================================
97     // Private Methods
98     // ============================================================
99     private:
100       void doStartup();
101       void queryMySessionId();
102       void queryMySessionInfo();
103       void addSessionToMap(UUID_t sessionId);
104       boost::shared_ptr<LiteSessionImpl> getSessionFromMap(UUID_t sessionId);
105       void addTargetDeviceToMap(UUID_t targetDeviceId);
106       boost::shared_ptr<LiteTargetDeviceProxy> getTargetDeviceFromMap(UUID_t targetDeviceId);
107       void handleNewConnection(UUID_t sessionId, int socket);
108       void handleNewTargetDevice(UUID_t targetDeviceId);
109
110     // ============================================================
111     // Observers
112     // ============================================================
113     private:
114       void sessionObserver(const API::SessionEvent& sessionEvent);
115
116         };
117 }
118 #endif /* LITEREMOTING_H_ */