mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 22:01:30 +00:00
Bug #117160. Create a small stand alone client for xremote client requests. r=cls,sr=brendan
This commit is contained in:
parent
32ee39d97e
commit
462bbdefd0
@ -36,6 +36,7 @@ REQUIRES = xpcom \
|
||||
|
||||
CPPSRCS = \
|
||||
XRemoteClient.cpp \
|
||||
XRemoteClientFactory.cpp \
|
||||
$(NULL)
|
||||
|
||||
EXTRA_DSO_LDOPTS = \
|
||||
@ -46,6 +47,15 @@ EXTRA_DSO_LDOPTS = \
|
||||
EXPORTS = \
|
||||
nsXRemoteClientCID.h
|
||||
|
||||
PROGRAM = mozilla-xremote-client$(BIN_SUFFIX)
|
||||
|
||||
PROGOBJS = mozilla-xremote-client.$(OBJ_SUFFIX)
|
||||
|
||||
LIBS = \
|
||||
XRemoteClient.$(OBJ_SUFFIX) \
|
||||
$(XPCOM_LIBS) $(NSPR_LIBS) \
|
||||
$(XLDFLAGS) $(XLIBS)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
ifeq ($(OS_ARCH), Linux)
|
||||
|
@ -20,16 +20,6 @@
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#define NS_XREMOTECLIENT_CID \
|
||||
{ 0xcfae5900, \
|
||||
0x1dd1, \
|
||||
0x11b2, \
|
||||
{ 0x95, 0xd0, 0xad, 0x45, 0x4c, 0x23, 0x3d, 0xc6 } \
|
||||
}
|
||||
|
||||
/* cfae5900-1dd1-11b2-95d0-ad454c233dc6 */
|
||||
|
||||
#include "nsIGenericFactory.h"
|
||||
#include "XRemoteClient.h"
|
||||
#include "prmem.h"
|
||||
#include "prprf.h"
|
||||
@ -67,6 +57,7 @@ XRemoteClient::XRemoteClient()
|
||||
mMozResponseAtom = 0;
|
||||
mMozWMStateAtom = 0;
|
||||
mMozUserAtom = 0;
|
||||
mLockData = 0;
|
||||
if (!sRemoteLm)
|
||||
sRemoteLm = PR_NewLogModule("XRemoteClient");
|
||||
PR_LOG(sRemoteLm, PR_LOG_DEBUG, ("XRemoteClient::XRemoteClient"));
|
||||
@ -165,6 +156,10 @@ XRemoteClient::Shutdown (void)
|
||||
XCloseDisplay(mDisplay);
|
||||
mDisplay = 0;
|
||||
mInitialized = PR_FALSE;
|
||||
if (mLockData) {
|
||||
free(mLockData);
|
||||
mLockData = 0;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -322,11 +317,11 @@ XRemoteClient::GetLock(Window aWindow, PRBool *aDestroyed)
|
||||
PRBool waited = PR_FALSE;
|
||||
*aDestroyed = PR_FALSE;
|
||||
|
||||
if (mLockData.Length() == 0) {
|
||||
if (!mLockData) {
|
||||
|
||||
char pidstr[256];
|
||||
char sysinfobuf[SYS_INFO_BUFFER_LENGTH];
|
||||
PR_snprintf(pidstr, 255, "pid%d@", getpid());
|
||||
char pidstr[32];
|
||||
char sysinfobuf[SYS_INFO_BUFFER_LENGTH];
|
||||
PR_snprintf(pidstr, sizeof(pidstr), "pid%d@", getpid());
|
||||
PRStatus status;
|
||||
status = PR_GetSystemInfo(PR_SI_HOSTNAME, sysinfobuf,
|
||||
SYS_INFO_BUFFER_LENGTH);
|
||||
@ -334,8 +329,16 @@ XRemoteClient::GetLock(Window aWindow, PRBool *aDestroyed)
|
||||
NS_WARNING("failed to get hostname");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
mLockData.Append(pidstr);
|
||||
mLockData.Append(sysinfobuf);
|
||||
|
||||
// allocate enough space for the string plus the terminating
|
||||
// char
|
||||
mLockData = (char *)malloc(strlen(pidstr) + strlen(sysinfobuf) + 1);
|
||||
if (!mLockData)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
strcpy(mLockData, pidstr);
|
||||
if (!strcat(mLockData, sysinfobuf))
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
do {
|
||||
@ -358,8 +361,8 @@ XRemoteClient::GetLock(Window aWindow, PRBool *aDestroyed)
|
||||
/* It's not now locked - lock it. */
|
||||
XChangeProperty (mDisplay, aWindow, mMozLockAtom, XA_STRING, 8,
|
||||
PropModeReplace,
|
||||
(unsigned char *) mLockData.get(),
|
||||
mLockData.Length());
|
||||
(unsigned char *)mLockData,
|
||||
strlen(mLockData));
|
||||
locked = True;
|
||||
}
|
||||
|
||||
@ -462,11 +465,10 @@ XRemoteClient::FreeLock(Window aWindow)
|
||||
(unsigned int) aWindow));
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
else if (strcmp((char *)data, mLockData.get())) {
|
||||
PR_LOG(sRemoteLm, PR_LOG_DEBUG,
|
||||
(MOZILLA_LOCK_PROP
|
||||
" was stolen! Expected \"%s\", saw \"%s\"!\n",
|
||||
mLockData.get(), data));
|
||||
else if (strcmp((char *)data, mLockData)) {
|
||||
PR_LOG(sRemoteLm, PR_LOG_DEBUG,
|
||||
(MOZILLA_LOCK_PROP " was stolen! Expected \"%s\", saw \"%s\"!\n",
|
||||
mLockData, data));
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
@ -596,15 +598,4 @@ XRemoteClient::DoSendCommand(Window aWindow, const char *aCommand,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(XRemoteClient)
|
||||
|
||||
static nsModuleComponentInfo components[] =
|
||||
{
|
||||
{ "XRemote Client",
|
||||
NS_XREMOTECLIENT_CID,
|
||||
NS_XREMOTECLIENT_CONTRACTID,
|
||||
XRemoteClientConstructor }
|
||||
};
|
||||
|
||||
NS_IMPL_NSGETMODULE(XRemoteClientModule, components);
|
||||
|
||||
|
@ -20,18 +20,7 @@
|
||||
|
||||
#include <X11/X.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include "nsString.h"
|
||||
#include "nsIXRemoteClient.h"
|
||||
#include "nsXRemoteClientCID.h"
|
||||
|
||||
#define NS_XREMOTECLIENT_CID \
|
||||
{ 0xcfae5900, \
|
||||
0x1dd1, \
|
||||
0x11b2, \
|
||||
{ 0x95, 0xd0, 0xad, 0x45, 0x4c, 0x23, 0x3d, 0xc6 } \
|
||||
}
|
||||
|
||||
/* cfae5900-1dd1-11b2-95d0-ad454c233dc6 */
|
||||
|
||||
class XRemoteClient : public nsIXRemoteClient
|
||||
{
|
||||
@ -65,7 +54,7 @@ private:
|
||||
Atom mMozWMStateAtom;
|
||||
Atom mMozUserAtom;
|
||||
|
||||
nsCString mLockData;
|
||||
char *mLockData;
|
||||
|
||||
PRBool mInitialized;
|
||||
|
||||
|
62
widget/src/xremoteclient/XRemoteClientFactory.cpp
Normal file
62
widget/src/xremoteclient/XRemoteClientFactory.cpp
Normal file
@ -0,0 +1,62 @@
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code Christopher Blizzard
|
||||
* <blizzard@mozilla.org>. Portions created by the Initial Developer
|
||||
* are Copyright (C) 2001 the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
|
||||
#define NS_XREMOTECLIENT_CID \
|
||||
{ 0xcfae5900, \
|
||||
0x1dd1, \
|
||||
0x11b2, \
|
||||
{ 0x95, 0xd0, 0xad, 0x45, 0x4c, 0x23, 0x3d, 0xc6 } \
|
||||
}
|
||||
|
||||
/* cfae5900-1dd1-11b2-95d0-ad454c233dc6 */
|
||||
|
||||
#include "XRemoteClient.h"
|
||||
#include "nsXRemoteClientCID.h"
|
||||
#include "nsIGenericFactory.h"
|
||||
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(XRemoteClient)
|
||||
|
||||
static nsModuleComponentInfo components[] =
|
||||
{
|
||||
{ "XRemote Client",
|
||||
NS_XREMOTECLIENT_CID,
|
||||
NS_XREMOTECLIENT_CONTRACTID,
|
||||
XRemoteClientConstructor }
|
||||
};
|
||||
|
||||
NS_IMPL_NSGETMODULE(XRemoteClientModule, components);
|
||||
|
||||
|
67
widget/src/xremoteclient/mozilla-xremote-client.cpp
Normal file
67
widget/src/xremoteclient/mozilla-xremote-client.cpp
Normal file
@ -0,0 +1,67 @@
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code Christopher Blizzard
|
||||
* <blizzard@mozilla.org>. Portions created by the Initial Developer
|
||||
* are Copyright (C) 2001 the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "XRemoteClient.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
nsresult rv;
|
||||
XRemoteClient client;
|
||||
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "Usage: mozilla-xremote-client [COMMAND]\n");
|
||||
return 4;
|
||||
}
|
||||
|
||||
rv = client.Init();
|
||||
// failed to connect to the X server
|
||||
if (NS_FAILED(rv))
|
||||
return 1;
|
||||
|
||||
// send the command - it doesn't get any easier than this
|
||||
PRBool success = PR_FALSE;
|
||||
rv = client.SendCommand(argv[1], &success);
|
||||
|
||||
// failed to send command
|
||||
if (NS_FAILED(rv))
|
||||
return 3;
|
||||
|
||||
// no running window found
|
||||
if (!success)
|
||||
return 2;
|
||||
|
||||
// else, everything is fine.
|
||||
return 0;
|
||||
}
|
@ -57,6 +57,7 @@ bin/run-mozilla.sh
|
||||
bin/regExport
|
||||
bin/regxpcom
|
||||
bin/regchrome
|
||||
bin/mozilla-xremote-client
|
||||
bin/splash.xpm
|
||||
bin/xpicleanup
|
||||
bin/res/cmessage.txt
|
||||
|
Loading…
Reference in New Issue
Block a user