Back to index

unity  6.0.0
GLibDBusProxy.h
Go to the documentation of this file.
00001 // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
00002 /*
00003  * Copyright (C) 2011 Canonical Ltd
00004  *
00005  * This program is free software: you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License version 3 as
00007  * published by the Free Software Foundation.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016  *
00017  * Authored by: Neil Jagdish Patel <neil.patel@canonical.com>
00018  */
00019 
00020 #ifndef UNITY_DBUS_PROXY_H
00021 #define UNITY_DBUS_PROXY_H
00022 
00023 #include <boost/noncopyable.hpp>
00024 #include <gio/gio.h>
00025 #include <memory>
00026 #include <sigc++/signal.h>
00027 #include <sigc++/trackable.h>
00028 
00029 namespace unity
00030 {
00031 namespace glib
00032 {
00033 
00034 // A light wrapper around GDBusProxy which allows for some nicer signal and async
00035 // method usage from C++
00036 class DBusProxy : public sigc::trackable, boost::noncopyable
00037 {
00038 public:
00039   typedef std::shared_ptr<DBusProxy> Ptr;
00040   typedef sigc::slot<void, GVariant*> ReplyCallback;
00041 
00042   DBusProxy(std::string const& name,
00043             std::string const& object_path,
00044             std::string const& interface_name,
00045             GBusType bus_type = G_BUS_TYPE_SESSION,
00046             GDBusProxyFlags flags = G_DBUS_PROXY_FLAGS_NONE);
00047   ~DBusProxy();
00048 
00049   void Call(std::string const& method_name,
00050             GVariant* parameters = NULL,
00051             ReplyCallback callback = sigc::ptr_fun(&NoReplyCallback),
00052             GCancellable *cancellable = NULL,
00053             GDBusCallFlags flags = G_DBUS_CALL_FLAGS_NONE,
00054             int timeout_msec = -1);
00055 
00056   void Connect(std::string const& signal_name, ReplyCallback callback);
00057   bool IsConnected();
00058 
00059   sigc::signal<void> connected;
00060   sigc::signal<void> disconnected;
00061 
00062   static void NoReplyCallback(GVariant* v) {};
00063 
00064   // Public due to use in some callbacks
00065 private:
00066   class Impl;
00067   std::unique_ptr<Impl> pimpl;
00068 };
00069 
00070 }
00071 }
00072 
00073 #endif