1
/****************************************************************************
3
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4
** All rights reserved.
6
** Contact: Nokia Corporation (qt-info@nokia.com)
8
** This file is part of a Qt Solutions component.
10
** You may use this file under the terms of the BSD license as follows:
12
** "Redistribution and use in source and binary forms, with or without
13
** modification, are permitted provided that the following conditions are
15
** * Redistributions of source code must retain the above copyright
16
** notice, this list of conditions and the following disclaimer.
17
** * Redistributions in binary form must reproduce the above copyright
18
** notice, this list of conditions and the following disclaimer in
19
** the documentation and/or other materials provided with the
21
** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
22
** the names of its contributors may be used to endorse or promote
23
** products derived from this software without specific prior written
26
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
38
****************************************************************************/
41
#include "qtsinglecoreapplication.h"
42
#include "qtlocalpeer.h"
45
\class QtSingleCoreApplication qtsinglecoreapplication.h
46
\brief A variant of the QtSingleApplication class for non-GUI applications.
48
This class is a variant of QtSingleApplication suited for use in
49
console (non-GUI) applications. It is an extension of
50
QCoreApplication (instead of QApplication). It does not require
53
The API and usage is identical to QtSingleApplication, except that
54
functions relating to the "activation window" are not present, for
55
obvious reasons. Please refer to the QtSingleApplication
56
documentation for explanation of the usage.
58
A QtSingleCoreApplication instance can communicate to a
59
QtSingleApplication instance if they share the same application
60
id. Hence, this class can be used to create a light-weight
61
command-line tool that sends commands to a GUI application.
63
\sa QtSingleApplication
67
Creates a QtSingleCoreApplication object. The application identifier
68
will be QCoreApplication::applicationFilePath(). \a argc and \a
69
argv are passed on to the QCoreAppliation constructor.
72
QtSingleCoreApplication::QtSingleCoreApplication(int &argc, char **argv)
73
: QCoreApplication(argc, argv)
75
peer = new QtLocalPeer(this);
76
connect(peer, SIGNAL(messageReceived(const QString&)), SIGNAL(messageReceived(const QString&)));
81
Creates a QtSingleCoreApplication object with the application
82
identifier \a appId. \a argc and \a argv are passed on to the
83
QCoreAppliation constructor.
85
QtSingleCoreApplication::QtSingleCoreApplication(const QString &appId, int &argc, char **argv)
86
: QCoreApplication(argc, argv)
88
peer = new QtLocalPeer(this, appId);
89
connect(peer, SIGNAL(messageReceived(const QString&)), SIGNAL(messageReceived(const QString&)));
94
Returns true if another instance of this application is running;
97
This function does not find instances of this application that are
98
being run by a different user (on Windows: that are running in
104
bool QtSingleCoreApplication::isRunning()
106
return peer->isClient();
111
Tries to send the text \a message to the currently running
112
instance. The QtSingleCoreApplication object in the running instance
113
will emit the messageReceived() signal when it receives the
116
This function returns true if the message has been sent to, and
117
processed by, the current instance. If there is no instance
118
currently running, or if the running instance fails to process the
119
message within \a timeout milliseconds, this function return false.
121
\sa isRunning(), messageReceived()
124
bool QtSingleCoreApplication::sendMessage(const QString &message, int timeout)
126
return peer->sendMessage(message, timeout);
131
Returns the application identifier. Two processes with the same
132
identifier will be regarded as instances of the same application.
135
QString QtSingleCoreApplication::id() const
137
return peer->applicationId();
142
\fn void QtSingleCoreApplication::messageReceived(const QString& message)
144
This signal is emitted when the current instance receives a \a
145
message from another instance of this application.