client-cpp  0.10.0
BootstrapManager.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 BOOTSTRAPMANAGER_HPP_
18 #define BOOTSTRAPMANAGER_HPP_
19 
20 #include <vector>
21 
22 #include "kaa/KaaThread.hpp"
26 #include "kaa/utils/KaaTimer.hpp"
28 
29 namespace kaa {
30 
31 class IKaaClient;
32 
33 class BootstrapManager : public IBootstrapManager, public boost::noncopyable {
34 public:
36  : bootstrapTransport_(nullptr)
37  , channelManager_(nullptr)
38  , context_(context)
39  , retryTimer_("BootstrapManager retryTimer")
40  , client_(client)
41  {
42 
43  }
44 
45  virtual void setFailoverStrategy(IFailoverStrategyPtr strategy);
46  virtual void receiveOperationsServerList();
47  virtual void onOperationsServerFailed(const TransportProtocolId& protocolId, KaaFailoverReason reason);
48  virtual void useNextOperationsServerByAccessPointId(std::int32_t id);
49  virtual void setTransport(IBootstrapTransport* transport);
50  virtual void setChannelManager(IKaaChannelManager* manager);
51  virtual void onServerListUpdated(const std::vector<ProtocolMetaData>& operationsServers);
52 
53 private:
54  typedef std::vector<ITransportConnectionInfoPtr> OperationsServers;
55 
56  OperationsServers getOPSByAccessPointId(std::int32_t id);
57  void notifyChannelManangerAboutServer(const OperationsServers& servers);
58 
59  void onCurrentBootstrapServerFailed(KaaFailoverReason reason);
60 
61 private:
62  std::map<TransportProtocolId, OperationsServers > operationServers_;
63  std::map<TransportProtocolId, OperationsServers::iterator > lastOperationsServers_;
64 
65  BootstrapTransport *bootstrapTransport_;
66  IKaaChannelManager *channelManager_;
67 
68  IKaaClientContext& context_;
69 
70  IFailoverStrategyPtr failoverStrategy_;
71 
72  std::unique_ptr<std::int32_t> serverToApply;
73 
74  KaaTimer<void ()> retryTimer_;
75 
76  // Temporary solution to stop app
77  IKaaClient *client_;
78 
79  KAA_R_MUTEX_MUTABLE_DECLARE(guard_);
80 };
81 
82 }
83 
84 
85 
86 #endif /* BOOTSTRAPMANAGER_HPP_ */
virtual void setTransport(IBootstrapTransport *transport)
KaaFailoverReason
std::shared_ptr< IFailoverStrategy > IFailoverStrategyPtr
virtual void onOperationsServerFailed(const TransportProtocolId &protocolId, KaaFailoverReason reason)
virtual void setFailoverStrategy(IFailoverStrategyPtr strategy)
virtual void setChannelManager(IKaaChannelManager *manager)
BootstrapManager(IKaaClientContext &context, IKaaClient *client)
virtual void useNextOperationsServerByAccessPointId(std::int32_t id)
virtual void onServerListUpdated(const std::vector< ProtocolMetaData > &operationsServers)
virtual void receiveOperationsServerList()