client-cpp  0.10.0
EndpointRegistrationManager.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2014-2016 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"
33 
34 namespace kaa {
35 
36 struct UserAttachRequest;
37 struct EndpointAttachResponse;
38 struct EndpointDetachResponse;
39 struct UserAttachNotification;
40 struct UserDetachNotification;
41 
42 class IExecutorContext;
43 
45  , public IRegistrationProcessor
46 {
47 public:
49 
50  virtual void attachEndpoint(const std::string& endpointAccessToken
52 
53  virtual void detachEndpoint(const std::string& endpointKeyHash
55 
56  virtual void attachUser(const std::string& userExternalId
57  , const std::string& userAccessToken
59 
60  virtual void attachUser(const std::string& userExternalId
61  , const std::string& userAccessToken
62  , const std::string& userVerifierToken
64 
65  virtual bool isAttachedToUser() { return context_.getStatus().getEndpointAttachStatus(); }
66 
67  virtual void setAttachStatusListener(IAttachStatusListenerPtr listener) { attachStatusListener_ = listener; }
68 
70 
71  virtual std::unordered_map<std::int32_t, std::string> getEndpointsToAttach();
72  virtual std::unordered_map<std::int32_t, std::string> getEndpointsToDetach();
73 
74  virtual void onUserAttach(const UserAttachResponse& response);
75 
76  virtual void onEndpointsAttach(const std::vector<EndpointAttachResponse>& endpoints);
77  virtual void onEndpointsDetach(const std::vector<EndpointDetachResponse>& endpoints);
78 
79  virtual void onCurrentEndpointAttach(const UserAttachNotification& response);
80  virtual void onCurrentEndpointDetach(const UserDetachNotification& response);
81 
82  void setTransport(UserTransport * transport) { userTransport_ = transport; }
83 
84 private:
85  void doSync();
86 
87 private:
88 #ifdef KAA_THREADSAFE
89  typedef std::atomic_int_fast32_t RequestId;
90 #else
91  typedef std::int32_t RequestId;
92 #endif
93 
94 private:
95  IKaaClientContext &context_;
96  UserTransport* userTransport_;
97 
98  std::shared_ptr<UserAttachRequest> userAttachRequest_;
99  KAA_MUTEX_DECLARE(userAttachRequestGuard_);
100 
101  IUserAttachCallbackPtr userAttachResponseListener_;
102  IAttachStatusListenerPtr attachStatusListener_;
103 
104  RequestId attachRequestId_;
105  RequestId detachRequestId_;
106 
107  KAA_MUTEX_DECLARE(attachEndpointGuard_);
108  KAA_MUTEX_DECLARE(detachEndpointGuard_);
109 
110  std::unordered_map<std::int32_t, std::string/* endpoint access token */> attachEndpointRequests_;
111  std::unordered_map<std::int32_t, std::string/* endpoint key hash */> detachEndpointRequests_;
112 
113  std::unordered_map<std::int32_t, IAttachEndpointCallbackPtr> attachEndpointListeners_;
114  std::unordered_map<std::int32_t, IDetachEndpointCallbackPtr> detachEndpointListeners_;
115 };
116 
117 }
118 
119 #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 bool getEndpointAttachStatus() const =0
virtual void onCurrentEndpointAttach(const UserAttachNotification &response)
EndpointRegistrationManager(IKaaClientContext &context)
virtual std::unordered_map< std::int32_t, std::string > getEndpointsToDetach()
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
virtual IKaaClientStateStorage & getStatus()=0
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.