Debian Codegraph @

tests/auto/serviceframework/serviceobject/serviceobject_target/serviceobject_target.cpp

raw symbols SCIP
1 /****************************************************************************
2 **
3 ** Copyright (C) 2018 The Qt Company Ltd and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the test suite of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21 ** included in the packaging of this file. Please review the following
22 ** information to ensure the GNU General Public License requirements will
23 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24 **
25 ** $QT_END_LICENSE$
26 **
27 ****************************************************************************/
28
29 #include <qservicemanager.h>
30 #include "serviceobject_target.h"
31
32 #include <qcoreapplication.h>
33
34 #ifdef Q_OS_LINUX
35 #include <sys/socket.h>
36 #include <sys/un.h>
37 #endif
38
39 ServiceObjectTarget::ServiceObjectTarget(QObject *parent)
40 : QObject(parent)
41 {
42 // qWarning() << "Target created";
43 }
44
45 ServiceObjectTarget::~ServiceObjectTarget()
46 {
47 // qWarning() << "Target destroyed";
48 }
49
50 void ServiceObjectTarget::slotWithArg(const QString &number)
51 {
52 for (int i = 0; i < number.toInt(); i++) {
53 emit stateChanged();
54 }
55 m_state = number.toInt();
56 }
57
58 void ServiceObjectTarget::slotWithoutArg()
59 {
60 qWarning() << "Target without arg";
61 }
62
63 bool ServiceObjectTarget::slotWithOk()
64 {
65 return true;
66 }
67
68 void ServiceObjectTarget::timerEvent(QTimerEvent *event)
69 {
70
71 }
72
73 int ServiceObjectTarget::state() const
74 {
75 return m_state;
76 }
77
78 void ServiceObjectTarget::closeClientSockets()
79 {
80 closeClientSocketsBlocking();
81 }
82
83 bool ServiceObjectTarget::closeClientSocketsBlocking()
84 {
85 #ifdef Q_OS_UNIX
86 for (int i = 0; i < 1024; i++) {
87 struct sockaddr_un un;
88 socklen_t len = sizeof(struct sockaddr_un);
89 if (-1 != ::getsockname(i, (struct sockaddr*)&un, &len)) {
90 struct sockaddr_un unp;
91 socklen_t lenp = sizeof(struct sockaddr_un);
92 if (-1 != ::getpeername(i, (struct sockaddr*)&unp, &lenp)) {
93 // found a client socket
94 qDebug() << "Socket peer" << i << un.sun_path;
95 close(i);
96 }
97 }
98 }
99 #endif
100 }
101
102 int main(int argc, char **argv)
103 {
104
105
106 QCoreApplication app(argc, argv);
107
108 //register the unique service
109 QRemoteServiceRegister* serviceRegister = new QRemoteServiceRegister();
110 QRemoteServiceRegister::Entry entry =
111 serviceRegister->createEntry<ServiceObjectTarget>(
112 "ServiceObjectTarget", "com.nokia.qt.tests.serviceobject", "1.0");
113 entry.setInstantiationType(QRemoteServiceRegister::PrivateInstance);
114 serviceRegister->setQuitOnLastInstanceClosed(false);
115 serviceRegister->publishEntries("com.nokia.qt.tests.serviceobject");
116
117 QServiceManager *mgr = new QServiceManager();
118 if (!mgr->addService(":/xml/serviceobject.xml")) {
119 qWarning() << "failed to register service" << mgr->error();
120 }
121
122 app.exec();
123 }