client-cpp  0.10.0
KaaClient.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 KAACLIENT_HPP_
18 #define KAACLIENT_HPP_
19 
20 #include <memory>
21 
22 #include "kaa/IKaaClient.hpp"
23 #include "kaa/ClientStatus.hpp"
27 #include "kaa/event/gen/EventFamilyFactory.hpp"
38 #include "kaa/log/LogCollector.hpp"
43 #include "kaa/KaaClientContext.hpp"
44 
45 namespace kaa {
46 
47 class KaaClient : public IKaaClient,
48  public std::enable_shared_from_this<KaaClient> {
49 public:
51 
52  virtual void start();
53  virtual void stop();
54  virtual void pause();
55  virtual void resume();
56 
57  virtual void updateProfile();
59  virtual const KeyPair& getClientKeyPair();
60  virtual void setEndpointAccessToken(const std::string& token);
61  virtual std::string refreshEndpointAccessToken();
62  virtual std::string getEndpointAccessToken() const;
63  virtual std::string getEndpointKeyHash() const;
66  virtual EventFamilyFactory& getEventFamilyFactory();
67 
68  virtual RecordFuture addLogRecord(const KaaUserLogRecord& record);
69  virtual void setLogDeliveryListener(ILogDeliveryListenerPtr listener);
70  virtual void setLogStorage(ILogStoragePtr storage);
71  virtual void setLogUploadStrategy(ILogUploadStrategyPtr strategy);
72  virtual void setFailoverStrategy(IFailoverStrategyPtr strategy);
73  virtual void setProfileContainer(IProfileContainerPtr container);
76  virtual Topics getTopics();
77  virtual void addNotificationListener(INotificationListener& listener);
78  virtual void addNotificationListener(std::int64_t topicId, INotificationListener& listener);
79  virtual void removeNotificationListener(INotificationListener& listener);
80  virtual void removeNotificationListener(std::int64_t topicId, INotificationListener& listener);
81  virtual void subscribeToTopic(std::int64_t id, bool forceSync);
82  virtual void subscribeToTopics(const std::list<std::int64_t>& idList, bool forceSync);
83  virtual void unsubscribeFromTopic(std::int64_t id, bool forceSync);
84  virtual void unsubscribeFromTopics(const std::list<std::int64_t>& idList, bool forceSync);
85  virtual void syncTopicSubscriptions();
86  virtual void addConfigurationListener(IConfigurationReceiver &receiver);
88  virtual const KaaRootConfiguration& getConfiguration();
90  virtual void attachEndpoint(const std::string& endpointAccessToken
92  virtual void detachEndpoint(const std::string& endpointKeyHash
94  virtual void attachUser(const std::string& userExternalId, const std::string& userAccessToken
96  virtual void attachUser(const std::string& userExternalId, const std::string& userAccessToken
97  , const std::string& userVerifierToken
100  virtual bool isAttachedToUser();
101  virtual std::int32_t findEventListeners(const std::list<std::string>& eventFQNs
102  , IFetchEventListenersPtr listener);
103 
107 
108 private:
109  void init();
110 
111  void initKaaTransport();
112  void initClientKeys();
113 
114  void checkReadiness();
115 
116 private:
117 
118  enum class State {
119  CREATED,
120  STARTED,
121  PAUSED,
122  STOPPED
123  };
124 
125  void setClientState(State state);
126  void checkClientState(State expected, const std::string& message);
127  void checkClientStateNot(State unexpected, const std::string& message);
128 
129  State clientState_ = State::CREATED;
130  LoggerPtr logger_;
131  KaaClientContext context_;
133 
134 #ifdef KAA_DEFAULT_BOOTSTRAP_HTTP_CHANNEL
135  std::unique_ptr<DefaultBootstrapChannel> bootstrapChannel_;
136 #endif
137 #ifdef KAA_DEFAULT_TCP_CHANNEL
138  std::unique_ptr<DefaultOperationTcpChannel> opsTcpChannel_;
139 #endif
140 #ifdef KAA_DEFAULT_OPERATION_HTTP_CHANNEL
141  std::unique_ptr<DefaultOperationHttpChannel> opsHttpChannel_;
142 #endif
143 #ifdef KAA_DEFAULT_LONG_POLL_CHANNEL
144  std::unique_ptr<DefaultOperationLongPollChannel> opsLongPollChannel_;
145 #endif
146 
147  std::unique_ptr<IBootstrapManager> bootstrapManager_;
148  std::unique_ptr<IKaaChannelManager> channelManager_;
149  std::unique_ptr<SyncDataProcessor> syncProcessor_;
150  IFailoverStrategyPtr failoverStrategy_;
151 
152  std::unique_ptr<KeyPair> clientKeys_;
153  std::unique_ptr<ProfileManager> profileManager_;
154 #ifdef KAA_USE_NOTIFICATIONS
155  std::unique_ptr<NotificationManager> notificationManager_;
156 #endif
157 #ifdef KAA_USE_CONFIGURATION
158  std::unique_ptr<ConfigurationManager> configurationManager_;
159 #endif
160 #ifdef KAA_USE_EVENTS
161  std::unique_ptr<EventManager> eventManager_;
162  std::unique_ptr<EventFamilyFactory> eventFamilyFactory_;
163  std::unique_ptr<EndpointRegistrationManager> registrationManager_;
164 #endif
165 #ifdef KAA_USE_LOGGING
166  std::unique_ptr<LogCollector> logCollector_;
167 #endif
168 
169  IKaaClientPlatformContextPtr platformContext_;
170 };
171 
172 }
173 
174 
175 
176 #endif /* KAACLIENT_HPP_ */
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...
virtual std::string getEndpointAccessToken() const
Retrieve an access token for a current endpoint.
virtual IKaaDataDemultiplexer & getBootstrapDemultiplexer()
Retrieves Kaa bootstrap data demultiplexer.
The listener which receives updates on available topics.
virtual IKaaChannelManager & getChannelManager()
Retrieves the Channel Manager.
virtual void setLogStorage(ILogStoragePtr storage)
Sets the new log storage.
virtual void stop()
Stops Kaa's workflow.
std::shared_ptr< ILogDeliveryListener > ILogDeliveryListenerPtr
virtual RecordFuture addLogRecord(const KaaUserLogRecord &record)
Adds a new log record to the log storage.
virtual IKaaDataDemultiplexer & getOperationDemultiplexer()
Retrieves Kaa operations data demultiplexer.
std::shared_ptr< IFailoverStrategy > IFailoverStrategyPtr
std::shared_ptr< IKaaClientPlatformContext > IKaaClientPlatformContextPtr
virtual void subscribeToTopic(std::int64_t id, bool forceSync)
Subscribes to the specified optional topic to receive notifications on that topic.
virtual std::string getEndpointKeyHash() const
virtual void start()
Starts Kaa's workflow.
virtual void setProfileContainer(IProfileContainerPtr container)
Sets profile container implemented by the user.
virtual void addTopicListListener(INotificationTopicListListener &listener)
Adds the listener which receives updates on the list of available topics.
virtual IKaaDataMultiplexer & getBootstrapMultiplexer()
Retrieves Kaa bootstrap data multiplexer.
virtual void setLogDeliveryListener(ILogDeliveryListenerPtr listener)
Set a listener which receives a delivery status of each log bucket.
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 removeTopicListListener(INotificationTopicListListener &listener)
Removes listener which receives updates on the list of available topics.
virtual void removeNotificationListener(INotificationListener &listener)
Removes the listener which receives notifications on all available topics.
std::shared_ptr< KaaClientStateListener > KaaClientStateListenerPtr
std::shared_ptr< IDetachEndpointCallback > IDetachEndpointCallbackPtr
virtual void resume()
Resumes Kaa's workflow.
virtual void setConfigurationStorage(IConfigurationStoragePtr storage)
virtual std::string refreshEndpointAccessToken()
Generate new access token for a current endpoint.
std::shared_ptr< ILogger > LoggerPtr
Definition: ILogger.hpp:40
virtual void setLogUploadStrategy(ILogUploadStrategyPtr strategy)
Sets the new log upload strategy.
virtual void setEndpointAccessToken(const std::string &token)
Set new access token for a current endpoint.
std::shared_ptr< IProfileContainer > IProfileContainerPtr
std::shared_ptr< ILogStorage > ILogStoragePtr
Definition: ILogStorage.hpp:93
The listener which receives notifications on the specified topic.
std::shared_ptr< IKaaClientStateStorage > IKaaClientStateStoragePtr
virtual void addConfigurationListener(IConfigurationReceiver &receiver)
virtual void unsubscribeFromTopics(const std::list< std::int64_t > &idList, bool forceSync)
Unsubscribes from the specified list of optional topics to stop receiving notifications on those topi...
virtual void syncTopicSubscriptions()
Sends subscription request(s) to the Operations server.
virtual Topics getTopics()
Retrieves the list of available topics.
std::shared_ptr< IConfigurationStorage > IConfigurationStoragePtr
std::shared_ptr< IAttachStatusListener > IAttachStatusListenerPtr
virtual void removeConfigurationListener(IConfigurationReceiver &receiver)
virtual void setAttachStatusListener(IAttachStatusListenerPtr listener)
Sets listener to notify of the current endpoint is attached/detached by another one.
std::shared_ptr< IUserAttachCallback > IUserAttachCallbackPtr
virtual void detachEndpoint(const std::string &endpointKeyHash, IDetachEndpointCallbackPtr listener=IDetachEndpointCallbackPtr())
Detaches the specified endpoint from the user to which the current endpoint is attached.
virtual void updateProfile()
Notifies server about profile changes.
virtual std::int32_t findEventListeners(const std::list< std::string > &eventFQNs, IFetchEventListenersPtr listener)
Submits an event listeners resolution request.
virtual IKaaClientContext & getKaaClientContext()
Retrieves Kaa context data.
virtual void addNotificationListener(INotificationListener &listener)
Adds the listener which receives notifications on all available topics.
virtual IKaaDataMultiplexer & getOperationMultiplexer()
Retrieves Kaa operations data multiplexer.
std::shared_ptr< IFetchEventListeners > IFetchEventListenersPtr
std::shared_ptr< ILogUploadStrategy > ILogUploadStrategyPtr
KaaClient(IKaaClientPlatformContextPtr platformContext, KaaClientStateListenerPtr listener)
virtual const KaaRootConfiguration & getConfiguration()
virtual const KeyPair & getClientKeyPair()
Retrieves the client's public and private key.
virtual void setFailoverStrategy(IFailoverStrategyPtr strategy)
std::shared_ptr< IAttachEndpointCallback > IAttachEndpointCallbackPtr
virtual EventFamilyFactory & getEventFamilyFactory()
virtual bool isAttachedToUser()
Checks if the current endpoint is already attached to some user.
virtual void unsubscribeFromTopic(std::int64_t id, bool forceSync)
Unsubscribes from the specified optional topic to stop receiving notifications on that topic...
virtual void pause()
Pauses Kaa's workflow.
virtual void subscribeToTopics(const std::list< std::int64_t > &idList, bool forceSync)
Subscribes to the specified list of optional topics to receive notifications on those topics...