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