client-cpp  0.10.0
ClientStatus.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 CLIENTSTATUS_HPP_
18 #define CLIENTSTATUS_HPP_
19 
20 #include <string>
21 #include <map>
22 #include <cstdint>
23 #include <memory>
24 #include <boost/bimap.hpp>
25 
26 #include "kaa/KaaThread.hpp"
27 #include "kaa/gen/EndpointGen.hpp"
31 
32 namespace kaa {
33 
34 /* Fwd declarations */
35 enum class ClientParameterT;
36 class IPersistentParameter;
37 
38 typedef boost::bimaps::bimap<
39  boost::bimaps::set_of<ClientParameterT> /* Client parameter type */
40  , boost::bimaps::set_of<std::string> /* String token for mapping in status file */
41  , boost::bimaps::left_based
42 > bimap;
43 
45 public:
48 
49  std::int32_t getEventSequenceNumber() const;
50  void setEventSequenceNumber(std::int32_t sequenceNumber);
51 
52  bool isRegistered() const;
53  void setRegistered(bool isRegistered);
54 
55  Topics getTopicList() const;
56  void setTopicList(const Topics& topicList);
57 
58  HashDigest getProfileHash() const;
59  void setProfileHash(HashDigest hash);
60 
62  void setAttachedEndpoints(const AttachedEndpoints& endpoints);
63 
64  std::string getEndpointAccessToken();
65  void setEndpointAccessToken(const std::string& token);
66  std::string refreshEndpointAccessToken();
67 
68  bool getEndpointAttachStatus() const;
69  void setEndpointAttachStatus(bool isAttached);
70 
71  std::string getEndpointKeyHash() const;
72  void setEndpointKeyHash(const std::string& keyHash);
73 
74  void setTopicListHash(const std::int32_t topicListHash);
75  std::int32_t getTopicListHash();
76 
77  void setTopicStates(const TopicStates& subscriptions);
79 
80  virtual bool isSDKPropertiesUpdated() const { return isSDKPropertiesForUpdated_; }
81 
82  virtual bool isProfileResyncNeeded() const;
83  virtual void setProfileResyncNeeded(bool isNeeded);
84 
85  void read();
86  void save();
87 
88 private:
89  void checkSDKPropertiesForUpdates();
90  /* Helpers */
91  template< ClientParameterT Type, class ParameterData >
92  void setParameterData(const ParameterData& data);
93 
94  template< ClientParameterT Type, class ParameterData >
95  void setParameterDataWithEqualCheck(const ParameterData& data);
96 
97  template< ClientParameterT Type, class ParameterData >
98  ParameterData getParameterData(const ParameterData& defaultValue) const;
99 
100 private:
101  const std::string filename_;
102  std::map<ClientParameterT, std::shared_ptr<IPersistentParameter> > parameters_;
103 
104  bool isSDKPropertiesForUpdated_;
105  bool hasUpdate_;
106  TopicStates topicStates_;
107 
108  IKaaClientContext &context_;
109 
110 
111  static const bimap parameterToToken_;
112  static const std::int32_t eventSeqNumberDefault_;
113  static const bool isRegisteredDefault_;
114  static const HashDigest endpointHashDefault_;
115  static const Topics topicListDefault_;
116  static const std::int32_t topicListHashDefault_;
117  static const AttachedEndpoints attachedEndpoints_;
118  static const bool endpointDefaultAttachStatus_;
119  static const std::string endpointKeyHashDefault_;
120  static const bool isProfileResyncNeededDefault_;
121 };
122 
123 }
124 
125 
126 #endif /* CLIENTSTATUS_HPP_ */
std::int32_t getTopicListHash()
std::string getEndpointAccessToken()
void setAttachedEndpoints(const AttachedEndpoints &endpoints)
void setProfileHash(HashDigest hash)
std::string getEndpointKeyHash() const
void setEndpointAccessToken(const std::string &token)
std::int32_t getEventSequenceNumber() const
ClientStatus(IKaaClientContext &context)
virtual bool isProfileResyncNeeded() const
boost::bimaps::bimap< boost::bimaps::set_of< ClientParameterT >, boost::bimaps::set_of< std::string >, boost::bimaps::left_based > bimap
std::map< std::string, std::string > AttachedEndpoints
virtual void setProfileResyncNeeded(bool isNeeded)
void setTopicListHash(const std::int32_t topicListHash)
std::vector< std::uint8_t > HashDigest
TopicStates & getTopicStates()
void setEndpointAttachStatus(bool isAttached)
void setTopicList(const Topics &topicList)
Topics getTopicList() const
bool isRegistered() const
void setEndpointKeyHash(const std::string &keyHash)
void setEventSequenceNumber(std::int32_t sequenceNumber)
AttachedEndpoints getAttachedEndpoints() const
void setRegistered(bool isRegistered)
HashDigest getProfileHash() const
void setTopicStates(const TopicStates &subscriptions)
std::string refreshEndpointAccessToken()
bool getEndpointAttachStatus() const
virtual bool isSDKPropertiesUpdated() const
std::map< std::int64_t, std::int32_t > TopicStates