~brandontschaefer/unity/move-pointer-barrier-to-xi-1.6.99.1

1270.2.1 by Neil Jagdish Patel
Import Signal work as merging old trunk was breaking things
1
// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2
/*
2463.1.5 by Marco Trevisan (Treviño)
GLibSignal: fix copyright dates
3
* Copyright (C) 2011-2012 Canonical Ltd
1270.2.1 by Neil Jagdish Patel
Import Signal work as merging old trunk was breaking things
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License version 3 as
7
* published by the Free Software Foundation.
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
*
17
* Authored by: Neil Jagdish patel <neil.patel@canonical.com>
2463.1.1 by Marco Trevisan (Treviño)
GLibSignal: rewrite using the variadic templates to generate multiple types
18
*              Marco Trevisan <marco.trevisan@canonical.com>
1270.2.1 by Neil Jagdish Patel
Import Signal work as merging old trunk was breaking things
19
*/
20
21
#ifndef UNITY_GLIB_SIGNAL_INL_H
22
#define UNITY_GLIB_SIGNAL_INL_H
23
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
24
namespace unity
25
{
26
namespace glib
27
{
1270.2.1 by Neil Jagdish Patel
Import Signal work as merging old trunk was breaking things
28
2463.1.1 by Marco Trevisan (Treviño)
GLibSignal: rewrite using the variadic templates to generate multiple types
29
template <typename R, typename G, typename... Ts>
30
Signal<R, G, Ts...>::Signal(G object, std::string const& signal_name,
31
                            SignalCallback const& callback)
32
{
33
  Connect(object, signal_name, callback);
34
}
35
36
template <typename R, typename G, typename... Ts>
37
void Signal<R, G, Ts...>::Connect(G object, std::string const& signal_name,
38
                                  SignalCallback const& callback)
39
{
2501.1.2 by Marco Trevisan (Treviño)
GLibSignal: replace sigc::slot with std::function
40
  if (!callback || !G_IS_OBJECT(object) || signal_name.empty())
41
    return;
42
2567.1.1 by Marco Trevisan (Treviño)
GLibSignal: disconnect from previous signal when replacing the connection
43
  Disconnect();
44
2463.1.1 by Marco Trevisan (Treviño)
GLibSignal: rewrite using the variadic templates to generate multiple types
45
  object_ = reinterpret_cast<GObject*>(object);
46
  name_ = signal_name;
47
  callback_ = callback;
2567.1.2 by Marco Trevisan (Treviño)
GLibSignal: add weak pointer to reset the object_ value when the wrapped gobject has been destroyed
48
  connection_id_ = g_signal_connect(object_, signal_name.c_str(), G_CALLBACK(Callback), this);
49
  g_object_add_weak_pointer(object_, reinterpret_cast<gpointer*>(&object_));
2463.1.1 by Marco Trevisan (Treviño)
GLibSignal: rewrite using the variadic templates to generate multiple types
50
}
51
52
template <typename R, typename G, typename... Ts>
53
R Signal<R, G, Ts...>::Callback(G object, Ts... vs, Signal* self)
54
{
55
  return self->callback_(object, vs...);
1270.2.15 by Neil Jagdish Patel
Forgot to add support for sending the emitting GObject!
56
}
1270.2.1 by Neil Jagdish Patel
Import Signal work as merging old trunk was breaking things
57
58
}
59
}
60
61
#endif