client-cpp  0.7.0
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 
42  , public IRegistrationProcessor
43 {
44 public:
46 
47  virtual void attachEndpoint(const std::string& endpointAccessToken
49 
50  virtual void detachEndpoint(const std::string& endpointKeyHash
52 
53  virtual void attachUser(const std::string& userExternalId
54  , const std::string& userAccessToken
56 
57  virtual void attachUser(const std::string& userExternalId
58  , const std::string& userAccessToken
59  , const std::string& userVerifierToken
61 
62  virtual bool isAttachedToUser() { return status_->getEndpointAttachStatus(); }
63 
64  virtual void setAttachStatusListener(IAttachStatusListenerPtr listener) { attachStatusListener_ = listener; }
65 
67 
68  virtual std::unordered_map<std::int32_t, std::string> getEndpointsToAttach();
69  virtual std::unordered_map<std::int32_t, std::string> getEndpointsToDetach();
70 
71  virtual void onUserAttach(const UserAttachResponse& response);
72 
73  virtual void onEndpointsAttach(const std::vector<EndpointAttachResponse>& endpoints);
74  virtual void onEndpointsDetach(const std::vector<EndpointDetachResponse>& endpoints);
75 
76  virtual void onCurrentEndpointAttach(const UserAttachNotification& response);
77  virtual void onCurrentEndpointDetach(const UserDetachNotification& response);
78 
79  void setTransport(UserTransport * transport) { userTransport_ = transport; }
80 
81 private:
82  void doSync();
83 
84 private:
85 #ifdef KAA_THREADSAFE
86  typedef std::atomic_int_fast32_t RequestId;
87 #else
88  typedef std::int32_t RequestId;
89 #endif
90 
91 private:
92  UserTransport* userTransport_;
94 
95  std::shared_ptr<UserAttachRequest> userAttachRequest_;
96  KAA_MUTEX_DECLARE(userAttachRequestGuard_);
97 
98  IUserAttachCallbackPtr userAttachResponseListener_;
99  IAttachStatusListenerPtr attachStatusListener_;
100 
101  RequestId attachRequestId_;
102  RequestId detachRequestId_;
103 
104  KAA_MUTEX_DECLARE(attachEndpointGuard_);
105  KAA_MUTEX_DECLARE(detachEndpointGuard_);
106 
107  std::unordered_map<std::int32_t, std::string/* endpoint access token */> attachEndpointRequests_;
108  std::unordered_map<std::int32_t, std::string/* endpoint key hash */> detachEndpointRequests_;
109 
110  std::unordered_map<std::int32_t, IAttachEndpointCallbackPtr> attachEndpointListeners_;
111  std::unordered_map<std::int32_t, IDetachEndpointCallbackPtr> detachEndpointListeners_;
112 };
113 
114 }
115 
116 #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...
EndpointRegistrationManager(IKaaClientStateStoragePtr status)
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()
std::shared_ptr< IKaaClientStateStorage > IKaaClientStateStoragePtr
std::shared_ptr< IAttachStatusListener > IAttachStatusListenerPtr
virtual void onUserAttach(const UserAttachResponse &response)
std::shared_ptr< IUserAttachCallback > IUserAttachCallbackPtr
std::int32_t RequestId
Definition: KaaThread.hpp:82
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.