Home | History | Annotate | Download | only in shill
      1 //
      2 // Copyright (C) 2012 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_RPC_TASK_H_
     18 #define SHILL_RPC_TASK_H_
     19 
     20 #include <map>
     21 #include <memory>
     22 #include <string>
     23 
     24 #include <base/macros.h>
     25 
     26 namespace shill {
     27 
     28 // Declared in the header to avoid linking unused code into shims.
     29 static const char kRPCTaskServiceVariable[] = "SHILL_TASK_SERVICE";
     30 static const char kRPCTaskPathVariable[] = "SHILL_TASK_PATH";
     31 
     32 class ControlInterface;
     33 class RPCTaskAdaptorInterface;
     34 
     35 // TODO(petkov): Switch from delegate interface to registered callbacks
     36 // (crbug.com/212273).
     37 class RPCTaskDelegate {
     38  public:
     39   virtual ~RPCTaskDelegate() {}
     40 
     41   virtual void GetLogin(std::string* user, std::string* password) = 0;
     42   virtual void Notify(const std::string& reason,
     43                       const std::map<std::string, std::string>& dict) = 0;
     44 };
     45 
     46 // RPC tasks are currently used by VPN drivers for communication with external
     47 // VPN processes. The RPC task should be owned by a single owner -- its
     48 // RPCTaskDelegate -- so no need to be reference counted.
     49 class RPCTask {
     50  public:
     51   // A constructor for the RPCTask object.
     52   RPCTask(ControlInterface* control_interface, RPCTaskDelegate* delegate);
     53   virtual ~RPCTask();
     54 
     55   virtual void GetLogin(std::string* user, std::string* password) const;
     56   virtual void Notify(const std::string& reason,
     57                       const std::map<std::string, std::string>& dict);
     58 
     59   // Returns a string that is guaranteed to uniquely identify this RPCTask
     60   // instance.
     61   const std::string& UniqueName() const { return unique_name_; }
     62 
     63   // Generates environment variable strings for a child process to
     64   // communicate back to us over RPC.
     65   virtual std::map<std::string, std::string> GetEnvironment() const;
     66   std::string GetRpcIdentifier() const;
     67   std::string GetRpcConnectionIdentifier() const;
     68 
     69  private:
     70   RPCTaskDelegate* delegate_;
     71   static unsigned int serial_number_;
     72   std::string unique_name_;  // MUST be unique amongst RPC task instances
     73   std::unique_ptr<RPCTaskAdaptorInterface> adaptor_;
     74 
     75   DISALLOW_COPY_AND_ASSIGN(RPCTask);
     76 };
     77 
     78 }  // namespace shill
     79 
     80 #endif  // SHILL_RPC_TASK_H_
     81