client-cpp  0.9.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  { }
43 
44  virtual void setFailoverStrategy(IFailoverStrategyPtr strategy);
45  virtual void receiveOperationsServerList();
46  virtual void useNextOperationsServer(const TransportProtocolId& protocolId, KaaFailoverReason reason);
47  virtual void useNextOperationsServerByAccessPointId(std::int32_t id);
48  virtual void setTransport(IBootstrapTransport* transport);
49  virtual void setChannelManager(IKaaChannelManager* manager);
50  virtual void onServerListUpdated(const std::vector<ProtocolMetaData>& operationsServers);
51 
52 private:
53  typedef std::vector<ITransportConnectionInfoPtr> OperationsServers;
54 
55  OperationsServers getOPSByAccessPointId(std::int32_t id);
56  void notifyChannelManangerAboutServer(const OperationsServers& servers);
57 
58 private:
59  std::map<TransportProtocolId, OperationsServers > operationServers_;
60  std::map<TransportProtocolId, OperationsServers::iterator > lastOperationsServers_;
61 
62  BootstrapTransport *bootstrapTransport_;
63  IKaaChannelManager *channelManager_;
64 
65  IKaaClientContext &context_;
66 
67  IFailoverStrategyPtr failoverStrategy_;
68 
69  std::unique_ptr<std::int32_t> serverToApply;
70 
71  KaaTimer<void ()> retryTimer_;
72 
73  // Temporary solution to stop app
74  IKaaClient *client_;
75 
76  KAA_R_MUTEX_MUTABLE_DECLARE(guard_);
77 };
78 
79 }
80 
81 
82 
83 #endif /* BOOTSTRAPMANAGER_HPP_ */
virtual void setTransport(IBootstrapTransport *transport)
std::shared_ptr< IFailoverStrategy > IFailoverStrategyPtr
virtual void useNextOperationsServer(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()