// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
/*
* Copyright (C) 2013 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Marco Trevisan (TreviƱo)
*/
#ifndef UNITY_GLIB_DBUS_SERVER_H
#define UNITY_GLIB_DBUS_SERVER_H
#include
#include
#include
#include
#include "GLibWrapper.h"
namespace unity
{
namespace glib
{
class DBusObject : public sigc::trackable
{
public:
typedef std::shared_ptr Ptr;
DBusObject(std::string const& introspection_xml, std::string const& interface_name);
virtual ~DBusObject();
typedef std::function MethodCallback;
typedef std::function MethodCallbackFull;
typedef std::function PropertyGetterCallback;
typedef std::function PropertySetterCallback;
void SetMethodsCallsHandler(MethodCallback const&);
void SetMethodsCallsHandlerFull(MethodCallbackFull const&);
void SetPropertyGetter(PropertyGetterCallback const&);
void SetPropertySetter(PropertySetterCallback const&);
std::string InterfaceName() const;
bool Register(glib::Object const&, std::string const& path);
void UnRegister(std::string const& path = "");
void EmitSignal(std::string const& signal, GVariant* parameters = nullptr, std::string const& dest = "", std::string const& path = "");
void EmitPropertyChanged(std::string const& property, std::string const& path = "");
sigc::signal registered;
sigc::signal unregistered;
sigc::signal fully_unregistered;
private:
// not copyable class
DBusObject(DBusObject const&) = delete;
DBusObject& operator=(DBusObject const&) = delete;
struct Impl;
std::unique_ptr impl_;
};
class DBusObjectBuilder
{
public:
static std::list GetObjectsForIntrospection(std::string const& introspection_xml);
};
class DBusServer : public sigc::trackable
{
public:
typedef std::shared_ptr Ptr;
DBusServer(GBusType bus_type = G_BUS_TYPE_SESSION);
DBusServer(std::string const& name, GBusType bus_type = G_BUS_TYPE_SESSION, GBusNameOwnerFlags flags = G_BUS_NAME_OWNER_FLAGS_NONE);
virtual ~DBusServer();
void AddObjects(std::string const& introspection_xml, std::string const& path);
bool AddObject(DBusObject::Ptr const&, std::string const& path);
bool RemoveObject(DBusObject::Ptr const&);
std::list GetObjects() const;
DBusObject::Ptr GetObject(std::string const& interface) const;
void EmitSignal(std::string const& interface, std::string const& signal, GVariant* parameters = nullptr, std::string const& dest = "");
bool IsConnected() const;
std::string const& Name() const;
bool OwnsName() const;
sigc::signal connected;
sigc::signal name_acquired;
sigc::signal name_lost;
private:
// not copyable class
DBusServer(DBusServer const&) = delete;
DBusServer& operator=(DBusServer const&) = delete;
struct Impl;
std::unique_ptr impl_;
};
} // namespace glib
} // namespace unity
#endif //UNITY_GLIB_DBUS_SERVER_H