Home | History | Annotate | Download | only in shill
      1 //
      2 // Copyright (C) 2014 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 #ifndef SHILL_DEVICE_CLAIMER_H_
     18 #define SHILL_DEVICE_CLAIMER_H_
     19 
     20 #include <set>
     21 #include <string>
     22 
     23 #include <base/callback.h>
     24 
     25 #include "shill/error.h"
     26 #include "shill/rpc_service_watcher_interface.h"
     27 
     28 namespace shill {
     29 
     30 class ControlInterface;
     31 class DeviceInfo;
     32 
     33 // Provide an abstraction for remote service to claim/release devices
     34 // from/to shill.
     35 class DeviceClaimer {
     36  public:
     37   DeviceClaimer(const std::string& service_name,
     38                 DeviceInfo* device_info,
     39                 bool default_claimer);
     40   virtual ~DeviceClaimer();
     41 
     42   virtual bool Claim(const std::string& device_name, Error* error);
     43   virtual bool Release(const std::string& device_name, Error* error);
     44 
     45   // Return true if there are devices claimed by this claimer, false
     46   // otherwise.
     47   virtual bool DevicesClaimed();
     48 
     49   // Return true if the specified device is released by this claimer, false
     50   // otherwise.
     51   virtual bool IsDeviceReleased(const std::string& device_name);
     52 
     53   const std::string& name() const { return service_name_; }
     54 
     55   virtual bool default_claimer() const { return default_claimer_; }
     56 
     57   const std::set<std::string>& claimed_device_names() const {
     58     return claimed_device_names_;
     59   }
     60 
     61  private:
     62   // Watcher for monitoring the remote RPC service of the claimer.
     63   std::unique_ptr<RPCServiceWatcherInterface> service_watcher_;
     64   // The name of devices that have been claimed by this claimer.
     65   std::set<std::string> claimed_device_names_;
     66   // The name of devices that have been released by this claimer.
     67   std::set<std::string> released_device_names_;
     68   // Service name of the claimer.
     69   std::string service_name_;
     70 
     71   DeviceInfo* device_info_;
     72 
     73   // Flag indicating if this is the default claimer. When set to true, this
     74   // claimer will only be deleted when shill terminates.
     75   bool default_claimer_;
     76 
     77   DISALLOW_COPY_AND_ASSIGN(DeviceClaimer);
     78 };
     79 
     80 }  // namespace shill
     81 
     82 #endif  // SHILL_DEVICE_CLAIMER_H_
     83