1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * |
|
5 * This program is free software: you can redistribute it and/or modify |
|
6 * it under the terms of the GNU Lesser General Public License as published by |
|
7 * the Free Software Foundation, version 2.1 of the License. |
|
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 Lesser General Public License for more details. |
|
13 * |
|
14 * You should have received a copy of the GNU Lesser General Public License |
|
15 * along with this program. If not, |
|
16 * see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/". |
|
17 * |
|
18 * Description: |
|
19 * |
|
20 */ |
|
21 |
|
22 #ifndef XQSERVICEADAPTOR_H |
|
23 #define XQSERVICEADAPTOR_H |
|
24 |
|
25 #include <xqserviceglobal.h> |
|
26 |
|
27 #include <QObject> |
|
28 #include <QString> |
|
29 #include <QByteArray> |
|
30 #include <QVariant> |
|
31 #include <QStringList> |
|
32 |
|
33 #include <xqrequestinfo.h> |
|
34 |
|
35 class XQServiceAdaptorPrivate; |
|
36 class XQServiceRequestCompletedAsync; |
|
37 class XQSharableFile; |
|
38 |
|
39 class XQSERVICE_EXPORT XQServiceAdaptor : public QObject |
|
40 { |
|
41 Q_OBJECT |
|
42 friend class XQServiceAdaptorPrivate; |
|
43 friend class XQServiceAdaptorChannel; |
|
44 friend class XQServiceProvider; |
|
45 |
|
46 public: |
|
47 explicit XQServiceAdaptor(const QString& channel, QObject *parent = 0); |
|
48 virtual ~XQServiceAdaptor(); |
|
49 |
|
50 QString channel() const; |
|
51 |
|
52 static bool connect(QObject *sender, const QByteArray& signal, |
|
53 QObject *receiver, const QByteArray& member); |
|
54 |
|
55 bool send(const QByteArray& member, const QVariant &arg1, QVariant &retData); |
|
56 bool send(const QByteArray& member, const QVariant &arg1, |
|
57 const QVariant &arg2, QVariant &retData); |
|
58 bool send(const QByteArray& member, const QVariant &arg1, |
|
59 const QVariant &arg2, const QVariant &arg3, QVariant &retData); |
|
60 bool send(const QByteArray& member, const QList<QVariant>& args, QVariant &retData); |
|
61 |
|
62 bool isConnected(const QByteArray& signal); |
|
63 |
|
64 //todo: proposed to change in channel in 2 separate api sendSync sendAsync |
|
65 static bool send(const QString& channel, |
|
66 const QString& msg, |
|
67 const QList<QVariant>& args, |
|
68 QVariant& retValue, |
|
69 bool sync = true, |
|
70 XQServiceRequestCompletedAsync* rc = NULL); |
|
71 |
|
72 static bool send(const QString& channel, |
|
73 const QString& msg, |
|
74 const QList<QVariant>& args, |
|
75 QVariant& retValue, |
|
76 bool sync, |
|
77 XQServiceRequestCompletedAsync* rc, |
|
78 const void *userData); |
|
79 |
|
80 static bool cancelPendingSend(const QString& channel); |
|
81 |
|
82 static int latestError(); |
|
83 |
|
84 int setCurrentRequestAsync(); |
|
85 |
|
86 bool completeRequest(int index, const QVariant& retValue); |
|
87 |
|
88 XQRequestInfo requestInfo() const; |
|
89 |
|
90 Q_SIGNALS: |
|
91 void returnValueDelivered() ; |
|
92 void clientDisconnected() ; |
|
93 |
|
94 protected: |
|
95 enum PublishType |
|
96 { |
|
97 Signals, |
|
98 Slots, |
|
99 SignalsAndSlots |
|
100 }; |
|
101 |
|
102 bool publish(const QByteArray& member); |
|
103 void publishAll(XQServiceAdaptor::PublishType type); |
|
104 virtual QString memberToMessage(const QByteArray& member); |
|
105 |
|
106 private slots: |
|
107 void receiverDestroyed(); |
|
108 |
|
109 private: |
|
110 QVariant received(const QString& msg, const QByteArray& data,const XQSharableFile &sf); |
|
111 |
|
112 bool connectLocalToRemote(QObject *sender, const QByteArray& signal, |
|
113 const QByteArray& member); |
|
114 bool connectRemoteToLocal(const QByteArray& signal, QObject *receiver, |
|
115 const QByteArray& member); |
|
116 bool sendMessage(const QString& msg, const QList<QVariant>& args, QVariant &retData); |
|
117 |
|
118 void publishAll(QObject* object, int metCount, XQServiceAdaptor::PublishType type); |
|
119 |
|
120 private: |
|
121 XQServiceAdaptorPrivate *d; |
|
122 }; |
|
123 |
|
124 // Useful alias to make it clearer when connecting to messages on a channel. |
|
125 #define MESSAGE(x) "3"#x |
|
126 #define QMESSAGE_CODE 3 |
|
127 |
|
128 #endif |
|