Ningyuan Wang | 58f2706 | 2015-11-20 13:20:24 -0800 | [diff] [blame] | 1 | // |
| 2 | // Copyright (C) 2015 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 "dhcp_client/manager.h" |
Ningyuan Wang | b683602 | 2015-12-02 14:39:01 -0800 | [diff] [blame] | 18 | #include "dhcp_client/service.h" |
| 19 | |
| 20 | #include "dhcp_client/message_loop_event_dispatcher.h" |
Ningyuan Wang | 58f2706 | 2015-11-20 13:20:24 -0800 | [diff] [blame] | 21 | |
| 22 | namespace dhcp_client { |
| 23 | |
Ningyuan Wang | b683602 | 2015-12-02 14:39:01 -0800 | [diff] [blame] | 24 | Manager::Manager() |
| 25 | : service_identifier_(0), |
| 26 | event_dispatcher_(new MessageLoopEventDispatcher()) { |
| 27 | } |
Ningyuan Wang | 58f2706 | 2015-11-20 13:20:24 -0800 | [diff] [blame] | 28 | |
| 29 | Manager::~Manager() {} |
| 30 | |
Ningyuan Wang | b683602 | 2015-12-02 14:39:01 -0800 | [diff] [blame] | 31 | scoped_refptr<Service> Manager::StartService( |
| 32 | const brillo::VariantDictionary& configs) { |
| 33 | scoped_refptr<Service> service = new Service(this, |
| 34 | service_identifier_++, |
| 35 | event_dispatcher_.get(), |
| 36 | configs); |
| 37 | services_.push_back(service); |
| 38 | return service; |
Ningyuan Wang | 58f2706 | 2015-11-20 13:20:24 -0800 | [diff] [blame] | 39 | } |
| 40 | |
Ningyuan Wang | b683602 | 2015-12-02 14:39:01 -0800 | [diff] [blame] | 41 | bool Manager::StopService(const scoped_refptr<Service>& service) { |
| 42 | for (auto it = services_.begin(); it != services_.end(); ++it) { |
| 43 | if (*it == service) { |
| 44 | services_.erase(it); |
| 45 | return true; |
| 46 | } |
| 47 | } |
| 48 | return false; |
Ningyuan Wang | 58f2706 | 2015-11-20 13:20:24 -0800 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | } // namespace dhcp_client |
| 52 | |