client-cpp  0.7.4
EndpointRegistrationManager.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2014-2015 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 "kaa/KaaDefaults.hpp"
21 
22 #include <atomic>
23 #include <string>
24 #include <memory>
25 #include <unordered_map>
26 
27 #include "kaa/KaaThread.hpp"
32 
33 namespace kaa {
34 
35 struct UserAttachRequest;
36 struct EndpointAttachResponse;
37 struct EndpointDetachResponse;
38 struct UserAttachNotification;
39 struct UserDetachNotification;
40 
41 class IExecutorContext;
42 
44  , public IRegistrationProcessor
45 {
46 public:
48 
49  virtual void attachEndpoint(const std::string& endpointAccessToken
51 
52  virtual void detachEndpoint(const std::string& endpointKeyHash
54 
55  virtual void attachUser(const std::string& userExternalId
56  , const std::string& userAccessToken
58 
59  virtual void attachUser(const std::string& userExternalId
60  , const std::string& userAccessToken
61  , const std::string& userVerifierToken
63 
64  virtual bool isAttachedToUser() { return status_->getEndpointAttachStatus(); }
65 
66  virtual void setAttachStatusListener(IAttachStatusListenerPtr listener) { attachStatusListener_ = listener; }
67 
69 
70  virtual std::unordered_map<std::int32_t, std::string> getEndpointsToAttach();
71  virtual std::unordered_map<std::int32_t, std::string> getEndpointsToDetach();
72 
73  virtual void onUserAttach(const UserAttachResponse& response);
74 
75  virtual void onEndpointsAttach(const std::vector<EndpointAttachResponse>& endpoints);
76  virtual void onEndpointsDetach(const std::vector<EndpointDetachResponse>& endpoints);
77 
78  virtual void onCurrentEndpointAttach(const UserAttachNotification& response);
79  virtual void onCurrentEndpointDetach(const UserDetachNotification& response);
80 
81  void setTransport(UserTransport * transport) { userTransport_ = transport; }
82 
83 private:
84  void doSync();
85 
86 private:
87 #ifdef KAA_THREADSAFE
88  typedef std::atomic_int_fast32_t RequestId;
89 #else
90  typedef std::int32_t RequestId;
91 #endif
92 
93 private:
94  UserTransport* userTransport_;
96 
97  std::shared_ptr<UserAttachRequest> userAttachRequest_;
98  KAA_MUTEX_DECLARE(userAttachRequestGuard_);
99 
100  IUserAttachCallbackPtr userAttachResponseListener_;
101  IAttachStatusListenerPtr attachStatusListener_;
102 
103  RequestId attachRequestId_;
104  RequestId detachRequestId_;
105 
106  KAA_MUTEX_DECLARE(attachEndpointGuard_);
107  KAA_MUTEX_DECLARE(detachEndpointGuard_);
108 
109  std::unordered_map<std::int32_t, std::string/* endpoint access token */> attachEndpointRequests_;
110  std::unordered_map<std::int32_t, std::string/* endpoint key hash */> detachEndpointRequests_;
111 
112  std::unordered_map<std::int32_t, IAttachEndpointCallbackPtr> attachEndpointListeners_;
113  std::unordered_map<std::int32_t, IDetachEndpointCallbackPtr> detachEndpointListeners_;
114 
115  IExecutorContext& executorContext_;
116 };
117 
118 }
119 
120 #endif /* ENDPOINTREGISTRATIONMANAGER_HPP_ */
void setTransport(UserTransport *transport)
virtual void onEndpointsDetach(const std::vector< EndpointDetachResponse > &endpoints)
virtual void onCurrentEndpointDetach(const UserDetachNotification &response)
virtual void setAttachStatusListener(IAttachStatusListenerPtr listener)
Sets listener to notify of the current endpoint is attached/detached by another one.
virtual bool isAttachedToUser()
Checks if the current endpoint is already attached to some user.
virtual void attachUser(const std::string &userExternalId, const std::string &userAccessToken, IUserAttachCallbackPtr listener=IUserAttachCallbackPtr())
Attaches the current endpoint to the specifier user. The user verification is carried out by the defa...
std::shared_ptr< IDetachEndpointCallback > IDetachEndpointCallbackPtr
virtual void onEndpointsAttach(const std::vector< EndpointAttachResponse > &endpoints)
virtual void onCurrentEndpointAttach(const UserAttachNotification &response)
virtual std::unordered_map< std::int32_t, std::string > getEndpointsToDetach()
EndpointRegistrationManager(IKaaClientStateStoragePtr status, IExecutorContext &executorContext)
std::shared_ptr< IKaaClientStateStorage > IKaaClientStateStoragePtr
std::shared_ptr< IAttachStatusListener > IAttachStatusListenerPtr
virtual void onUserAttach(const UserAttachResponse &response)
std::shared_ptr< IUserAttachCallback > IUserAttachCallbackPtr
std::atomic_int_fast32_t RequestId
Definition: KaaThread.hpp:56
The interface to a module which associates endpoints with users.
virtual std::unordered_map< std::int32_t, std::string > getEndpointsToAttach()
virtual UserAttachRequestPtr getUserAttachRequest()
std::shared_ptr< UserAttachRequest > UserAttachRequestPtr
std::shared_ptr< IAttachEndpointCallback > IAttachEndpointCallbackPtr
virtual void attachEndpoint(const std::string &endpointAccessToken, IAttachEndpointCallbackPtr listener=IAttachEndpointCallbackPtr())
Attaches the specified endpoint to the user to which the current endpoint is attached.
virtual void detachEndpoint(const std::string &endpointKeyHash, IDetachEndpointCallbackPtr listener=IDetachEndpointCallbackPtr())
Detaches the specified endpoint from the user to which the current endpoint is attached.