Home | History | Annotate | Download | only in ibus
      1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef CHROMEOS_DBUS_IBUS_IBUS_CLIENT_H_
      6 #define CHROMEOS_DBUS_IBUS_IBUS_CLIENT_H_
      7 
      8 #include <string>
      9 
     10 #include "base/basictypes.h"
     11 #include "base/callback.h"
     12 #include "chromeos/chromeos_export.h"
     13 #include "chromeos/dbus/dbus_client_implementation_type.h"
     14 #include "dbus/object_path.h"
     15 
     16 namespace dbus {
     17 class Bus;
     18 }  // namespace dbus
     19 
     20 namespace chromeos {
     21 
     22 class IBusComponent;
     23 class IBusInputContextClient;
     24 
     25 // A class to make the actual DBus calls for IBusBus service.
     26 // This class only makes calls, result/error handling should be done by
     27 // callbacks.
     28 class CHROMEOS_EXPORT IBusClient {
     29  public:
     30   enum ExitOption {
     31     RESTART_IBUS_DAEMON,
     32     SHUT_DOWN_IBUS_DAEMON
     33   };
     34   typedef base::Callback<void(const dbus::ObjectPath&)>
     35       CreateInputContextCallback;
     36   typedef base::Callback<void()> RegisterComponentCallback;
     37   typedef base::Callback<void()> ErrorCallback;
     38 
     39   virtual ~IBusClient();
     40 
     41   // Requests the ibus-daemon to create new input context. If succeeded,
     42   // |callback| will be called with an ObjectPath which is used in input context
     43   // handling. If failed, |error_callback| is called instead.
     44   virtual void CreateInputContext(
     45       const std::string& client_name,
     46       const CreateInputContextCallback& callback,
     47       const ErrorCallback& error_callback) = 0;
     48 
     49   // Requests the ibus-daemon to register new engine object. If succeeded,
     50   // |callback| will be called. If failed, |error_callback| is called instead.
     51   virtual void RegisterComponent(
     52       const IBusComponent& ibus_component,
     53       const RegisterComponentCallback& callback,
     54       const ErrorCallback& error_callback) = 0;
     55 
     56   // Requests the ibus-daemon to set global engine. If failed, |error_callback|
     57   // is called.
     58   virtual void SetGlobalEngine(const std::string& engine_name,
     59                                const ErrorCallback& error_callback) = 0;
     60 
     61   // Requests the ibus-daemon to exit daemon process. If |option| is
     62   // RESTART_IBUS_DAEMON, ibus-daemon will be relaunched. If |option| is
     63   // SHUT_DOWN_IBUS_DAEMON, ibus-daemon will not be relaunched. The
     64   // |error_callback| is called if an error occurs.
     65   virtual void Exit(ExitOption option, const ErrorCallback& error_callback) = 0;
     66 
     67   // Factory function, creates a new instance and returns ownership.
     68   // For normal usage, access the singleton via DBusThreadManager::Get().
     69   static CHROMEOS_EXPORT IBusClient* Create(DBusClientImplementationType type,
     70                                             dbus::Bus* bus);
     71 
     72  protected:
     73   // Create() should be used instead.
     74   IBusClient();
     75 
     76  private:
     77   DISALLOW_COPY_AND_ASSIGN(IBusClient);
     78 };
     79 
     80 }  // namespace chromeos
     81 
     82 #endif  // CHROMEOS_DBUS_IBUS_IBUS_CLIENT_H_
     83