client-cpp  0.0.1-SNAPSHOT
EndpointRegistrationManager.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2014 CyberVision, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ENDPOINTREGISTRATIONMANAGER_HPP_
18 #define ENDPOINTREGISTRATIONMANAGER_HPP_
19 
20 #include <map>
21 #include <list>
22 #include <string>
23 
24 #include <boost/signals2.hpp>
25 #include <boost/shared_ptr.hpp>
26 #include <boost/thread/recursive_mutex.hpp>
27 
29 
34 
35 namespace kaa {
36 
37 class ClientStatus;
38 class SyncResponse;
39 class UserAttachRequest;
40 class IAttachedEndpointListListener;
41 
43  , public IRegistrationProcessor
44 {
45 public:
47 
48  virtual void regenerateEndpointAccessToken();
49 
50  virtual const std::string& getEndpointAccessToken() {
51  return endpointAccessToken_;
52  }
53 
54  virtual void attachEndpoint(const std::string& endpointAccessToken
55  , IEndpointAttachStatusListener* listener = nullptr);
56 
57  virtual void detachEndpoint(const std::string& endpointKeyHash
58  , IEndpointAttachStatusListener* listener = nullptr);
59 
60  virtual void detachEndpoint(IEndpointAttachStatusListener* listener = nullptr);
61 
62  virtual void attachUser(const std::string& userExternalId
63  , const std::string& userAccessToken
64  , IEndpointAttachStatusListener* listener = nullptr);
65 
66  virtual const AttachedEndpoints& getAttachedEndpoints();
67 
69 
71 
72  virtual std::map<std::string, std::string> getEndpointsToAttach();
73  virtual std::map<std::string, std::string> getEndpointsToDetach();
75 
76  virtual void onUserAttach(const UserSyncResponse::userAttachResponse_t& response);
77 
78  virtual void onEndpointsAttach(const std::vector<EndpointAttachResponse>& endpoints);
79  virtual void onEndpointsDetach(const std::vector<EndpointDetachResponse>& endpoints);
80 
81  virtual void onCurrentEndpointAttach(const UserAttachNotification& response);
82  virtual void onCurrentEndpointDetach(const UserDetachNotification& response);
83 
84  virtual bool isCurrentEndpointAttached() {
85  return status_->getEndpointAttachStatus();
86  }
87 
88  virtual void setTransport(UserTransport * transport) {
89  userTransport_ = transport;
90  if (userTransport_ != nullptr && (userAttachRequest_.get() != nullptr || !attachingEndpoints_.empty() || !detachingEndpoints_.empty())) {
91  userTransport_->sync();
92  }
93  }
94 
96  if (listener != nullptr) {
97  attachStatusListener_ = listener;
98  }
99  }
100 
101 private:
102  void onEndpointAccessTokenChanged(const std::string& old);
103 
104 private:
105  struct EndpointOperationInfo {
106  std::string endpointData_;/* endpoint's token or hash */
108  };
109 
110 
111 private:
112  typedef boost::recursive_mutex mutex_type;
113  typedef boost::unique_lock<mutex_type> lock_type;
114 
116 
117  std::string endpointAccessToken_;
118  std::string endpointKeyHash_;
119 
120  UserAttachRequestPtr userAttachRequest_;
121 
122  std::map<std::string/*requestId*/, EndpointOperationInfo> attachingEndpoints_;
123  std::map<std::string/*requestId*/, EndpointOperationInfo> detachingEndpoints_;
124  std::map<std::string/*epToken*/, std::string/*epHash*/> attachedEndpoints_;
125  mutex_type endpointsGuard_;
126 
127  UserTransport * userTransport_;
128 
129  boost::signals2::signal<void (const AttachedEndpoints&)> attachedEPListListeners;
130  mutex_type listenerGuard_;
131 
132  IEndpointAttachStatusListener* attachStatusListener_;
133 };
134 
135 }
136 
137 #endif /* ENDPOINTREGISTRATIONMANAGER_HPP_ */
virtual void onEndpointsDetach(const std::vector< EndpointDetachResponse > &endpoints)
virtual void onCurrentEndpointDetach(const UserDetachNotification &response)
std::map< std::string, std::string > AttachedEndpoints
virtual void detachEndpoint(const std::string &endpointKeyHash, IEndpointAttachStatusListener *listener=nullptr)
boost::shared_ptr< IKaaClientStateStorage > IKaaClientStateStoragePtr
virtual const AttachedEndpoints & getAttachedEndpoints()
virtual void setAttachStatusListener(IEndpointAttachStatusListener *listener)
EndpointRegistrationManager(IKaaClientStateStoragePtr status)
virtual void onEndpointsAttach(const std::vector< EndpointAttachResponse > &endpoints)
boost::shared_ptr< UserAttachRequest > UserAttachRequestPtr
virtual std::map< std::string, std::string > getEndpointsToDetach()
virtual void addAttachedEndpointListListener(IAttachedEndpointListListener *listener)
virtual void onCurrentEndpointAttach(const UserAttachNotification &response)
virtual void removeAttachedEndpointListListener(IAttachedEndpointListListener *listener)
virtual void attachUser(const std::string &userExternalId, const std::string &userAccessToken, IEndpointAttachStatusListener *listener=nullptr)
virtual void regenerateEndpointAccessToken()
virtual void setTransport(UserTransport *transport)
virtual void onUserAttach(const UserSyncResponse::userAttachResponse_t &response)
virtual void attachEndpoint(const std::string &endpointAccessToken, IEndpointAttachStatusListener *listener=nullptr)
virtual const std::string & getEndpointAccessToken()
virtual UserAttachRequestPtr getUserAttachRequest()
virtual std::map< std::string, std::string > getEndpointsToAttach()