1 //
2 // Copyright (C) 2013 The Android Open Source Project
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 #include "shill/cellular/out_of_credits_detector.h"
18
19 #include <string>
20
21 #include "shill/cellular/active_passive_out_of_credits_detector.h"
22 #include "shill/cellular/cellular_service.h"
23 #include "shill/cellular/no_out_of_credits_detector.h"
24 #include "shill/cellular/subscription_state_out_of_credits_detector.h"
25 #include "shill/logging.h"
26
27 namespace shill {
28
29 using std::string;
30
31 namespace Logging {
32 static auto kModuleLogScope = ScopeLogger::kCellular;
ObjectID(CellularService * c)33 static string ObjectID(CellularService* c) { return c->GetRpcIdentifier(); }
34 }
35
OutOfCreditsDetector(EventDispatcher * dispatcher,Manager * manager,Metrics * metrics,CellularService * service)36 OutOfCreditsDetector::OutOfCreditsDetector(EventDispatcher* dispatcher,
37 Manager* manager,
38 Metrics* metrics,
39 CellularService* service)
40 : dispatcher_(dispatcher),
41 manager_(manager),
42 metrics_(metrics),
43 service_(service),
44 out_of_credits_(false) {
45 }
46
~OutOfCreditsDetector()47 OutOfCreditsDetector::~OutOfCreditsDetector() {
48 }
49
50 // static
51 OutOfCreditsDetector*
CreateDetector(OOCType detector_type,EventDispatcher * dispatcher,Manager * manager,Metrics * metrics,CellularService * service)52 OutOfCreditsDetector::CreateDetector(OOCType detector_type,
53 EventDispatcher* dispatcher,
54 Manager* manager,
55 Metrics* metrics,
56 CellularService* service) {
57 switch (detector_type) {
58 case OOCTypeActivePassive:
59 LOG(INFO) << __func__
60 << ": Using active-passive out-of-credits detection";
61 return
62 new ActivePassiveOutOfCreditsDetector(dispatcher,
63 manager,
64 metrics,
65 service);
66 case OOCTypeSubscriptionState:
67 LOG(INFO) << __func__
68 << ": Using subscription status out-of-credits detection";
69 return
70 new SubscriptionStateOutOfCreditsDetector(dispatcher,
71 manager,
72 metrics,
73 service);
74 default:
75 LOG(INFO) << __func__ << ": No out-of-credits detection";
76 return
77 new NoOutOfCreditsDetector(dispatcher,
78 manager,
79 metrics,
80 service);
81 }
82 }
83
ReportOutOfCredits(bool state)84 void OutOfCreditsDetector::ReportOutOfCredits(bool state) {
85 SLOG(service_, 2) << __func__ << ": " << state;
86 if (state == out_of_credits_) {
87 return;
88 }
89 out_of_credits_ = state;
90 service_->SignalOutOfCreditsChanged(state);
91 }
92
93 } // namespace shill
94