Back to index

unity  6.0.0
GLibSignal-inl.h
Go to the documentation of this file.
00001 // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
00002 /*
00003 * Copyright (C) 2011-2012 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 *              Marco Trevisan <marco.trevisan@canonical.com>
00019 */
00020 
00021 #ifndef UNITY_GLIB_SIGNAL_INL_H
00022 #define UNITY_GLIB_SIGNAL_INL_H
00023 
00024 namespace unity
00025 {
00026 namespace glib
00027 {
00028 
00029 template <typename R, typename G, typename... Ts>
00030 Signal<R, G, Ts...>::Signal(G object, std::string const& signal_name,
00031                             SignalCallback const& callback)
00032 {
00033   Connect(object, signal_name, callback);
00034 }
00035 
00036 template <typename R, typename G, typename... Ts>
00037 void Signal<R, G, Ts...>::Connect(G object, std::string const& signal_name,
00038                                   SignalCallback const& callback)
00039 {
00040   object_ = reinterpret_cast<GObject*>(object);
00041   name_ = signal_name;
00042   callback_ = callback;
00043   connection_id_ = g_signal_connect(object, signal_name.c_str(), G_CALLBACK(Callback), this);
00044 }
00045 
00046 template <typename R, typename G, typename... Ts>
00047 R Signal<R, G, Ts...>::Callback(G object, Ts... vs, Signal* self)
00048 {
00049   return self->callback_(object, vs...);
00050 }
00051 
00052 }
00053 }
00054 
00055 #endif