LeechCraft  0.6.70-6645-gcd10d7e
Modular cross-platform feature rich live environment.
basehookinterconnector.cpp
Go to the documentation of this file.
1 /**********************************************************************
2  * LeechCraft - modular cross-platform feature rich internet client.
3  * Copyright (C) 2006-2014 Georg Rudoy
4  *
5  * Boost Software License - Version 1.0 - August 17th, 2003
6  *
7  * Permission is hereby granted, free of charge, to any person or organization
8  * obtaining a copy of the software and accompanying documentation covered by
9  * this license (the "Software") to use, reproduce, display, distribute,
10  * execute, and transmit the Software, and to prepare derivative works of the
11  * Software, and to permit third-parties to whom the Software is furnished to
12  * do so, all subject to the following:
13  *
14  * The copyright notices in the Software and this entire statement, including
15  * the above license grant, this restriction and the following disclaimer,
16  * must be included in all copies of the Software, in whole or in part, and
17  * all derivative works of the Software, unless such copies or derivative
18  * works are solely in the form of machine-executable object code generated by
19  * a source language processor.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
24  * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
25  * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
26  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27  * DEALINGS IN THE SOFTWARE.
28  **********************************************************************/
29 
30 #include "basehookinterconnector.h"
31 #include <QMetaMethod>
32 #include <QtDebug>
33 
34 namespace LeechCraft
35 {
36 namespace Util
37 {
39  : QObject (parent)
40  {
41  }
42 
44  {
45  }
46 
47  namespace
48  {
49 #define LC_N(a) (QMetaObject::normalizedSignature(a))
50 #define LC_TOSLOT(a) ('1' + QByteArray(a))
51 #define LC_TOSIGNAL(a) ('2' + QByteArray(a))
52  void ConnectHookSignals (QObject *sender, QObject *receiver, bool destSlot)
53  {
54  const QMetaObject *mo = sender->metaObject ();
55  for (int i = 0, size = mo->methodCount (); i < size; ++i)
56  {
57  QMetaMethod method = mo->method (i);
58  if (method.methodType () != QMetaMethod::Signal)
59  continue;
60  if (method.parameterTypes ().size () == 0)
61  continue;
62  if (method.parameterTypes ().at (0) != "LeechCraft::IHookProxy_ptr")
63  continue;
64 
65 #if QT_VERSION >= 0x050000
66  const auto& signature = method.methodSignature ();
67 #else
68  const auto& signature = method.signature ();
69 #endif
70 
71  if (receiver->metaObject ()->indexOfMethod (LC_N (signature)) == -1)
72  {
73  if (!destSlot)
74  {
75  qWarning () << Q_FUNC_INFO
76  << "not found meta method for"
77  << signature
78  << "in receiver object"
79  << receiver;
80  }
81  continue;
82  }
83 
84  if (!QObject::connect (sender,
85  LC_TOSIGNAL (signature),
86  receiver,
87  destSlot ? LC_TOSLOT (signature) : LC_TOSIGNAL (signature),
88  Qt::UniqueConnection))
89  {
90  qWarning () << Q_FUNC_INFO
91  << "connect for"
92  << sender
93  << "->"
94  << receiver
95  << ":"
96  << signature
97  << "failed";
98  }
99  }
100  }
101 #undef LC_N
102  };
103 
104  void BaseHookInterconnector::AddPlugin (QObject *plugin)
105  {
106  Plugins_.push_back (plugin);
107 
108  ConnectHookSignals (this, plugin, true);
109  }
110 
112  {
113  ConnectHookSignals (object, this, false);
114  }
115 }
116 }
BaseHookInterconnector(QObject *parent=0)
Creates the interconnector with the given parent.
virtual ~BaseHookInterconnector()
Virtual destructor.
void RegisterHookable(QObject *hookable)
Adds a hookable object from the root plugin.
#define LC_N(a)
#define LC_TOSLOT(a)
#define LC_TOSIGNAL(a)
virtual void AddPlugin(QObject *plugin)
Adds a subplugin to this interconnector.