Back to index

unity  6.0.0
UBusWrapper.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2010 Canonical Ltd
00003  *
00004  * This program is free software: you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License version 3 as
00006  * published by the Free Software Foundation.
00007  *
00008  * This program is distributed in the hope that it will be useful,
00009  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011  * GNU General Public License for more details.
00012  *
00013  * You should have received a copy of the GNU General Public License
00014  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00015  *
00016  * Authored by: Neil Jagdish Patel <neil.patel@canonical.com>
00017  */
00018 
00019 #ifndef UNITY_UBUS_WRAPPER_H
00020 #define UNITY_UBUS_WRAPPER_H
00021 
00022 #include <memory>
00023 #include <string>
00024 #include <vector>
00025 
00026 #include <sigc++/slot.h>
00027 
00028 #include "ubus-server.h"
00029 
00030 namespace unity
00031 {
00032 
00033 class UBusManager
00034 {
00035 public:
00036   typedef sigc::slot<void, GVariant*> UBusManagerCallback;
00037 
00038   struct UBusConnection
00039   {
00040   public:
00041     typedef std::shared_ptr<UBusConnection> Ptr;
00042 
00043     UBusManager* manager;
00044     std::string name;
00045     UBusManagerCallback slot;
00046     guint id;
00047   };
00048   typedef std::vector<UBusConnection::Ptr> Connections;
00049 
00050   UBusManager();
00051   ~UBusManager();
00052 
00053   void RegisterInterest(std::string const& interest_name,
00054                         UBusManagerCallback slot);
00055   void UnregisterInterest(std::string const& interest_name);
00056   void SendMessage(std::string const& message_name, GVariant* args = NULL);
00057 
00058 private:
00059   static void OnCallback(GVariant* args, gpointer user_data);
00060 
00061 private:
00062   UBusServer* server_;
00063   Connections connections_;
00064 };
00065 
00066 }
00067 
00068 #endif