From 16f504a9dca3fe3b70568f67b7d41241ae485288 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 18:49:04 +0200 Subject: Adding upstream version 7.0.6-dfsg. Signed-off-by: Daniel Baumann --- .../ipc/ipcd/extensions/transmngr/.cvsignore | 1 + .../ipc/ipcd/extensions/transmngr/Makefile.in | 52 +++ .../ipc/ipcd/extensions/transmngr/build/.cvsignore | 9 + .../ipcd/extensions/transmngr/build/Makefile.in | 75 +++ .../ipc/ipcd/extensions/transmngr/build/tmCID.h | 53 +++ .../ipcd/extensions/transmngr/build/tmModule.cpp | 71 +++ .../ipcd/extensions/transmngr/common/.cvsignore | 5 + .../ipcd/extensions/transmngr/common/Makefile.in | 61 +++ .../extensions/transmngr/common/tmTransaction.cpp | 107 +++++ .../extensions/transmngr/common/tmTransaction.h | 234 ++++++++++ .../ipc/ipcd/extensions/transmngr/common/tmUtils.h | 93 ++++ .../ipcd/extensions/transmngr/common/tmVector.cpp | 179 ++++++++ .../ipcd/extensions/transmngr/common/tmVector.h | 160 +++++++ .../ipcd/extensions/transmngr/module/.cvsignore | 11 + .../ipcd/extensions/transmngr/module/Makefile.in | 100 ++++ .../extensions/transmngr/module/tmIPCModule.cpp | 137 ++++++ .../ipcd/extensions/transmngr/module/tmIPCModule.h | 109 +++++ .../ipcd/extensions/transmngr/module/tmQueue.cpp | 223 +++++++++ .../ipc/ipcd/extensions/transmngr/module/tmQueue.h | 186 ++++++++ .../transmngr/module/tmTransactionManager.cpp | 162 +++++++ .../transmngr/module/tmTransactionManager.h | 147 ++++++ .../ipcd/extensions/transmngr/public/.cvsignore | 1 + .../ipcd/extensions/transmngr/public/Makefile.in | 53 +++ .../transmngr/public/ipcITransactionObserver.idl | 100 ++++ .../transmngr/public/ipcITransactionService.idl | 239 ++++++++++ .../ipc/ipcd/extensions/transmngr/src/.cvsignore | 4 + .../ipc/ipcd/extensions/transmngr/src/Makefile.in | 64 +++ .../transmngr/src/tmTransactionService.cpp | 504 +++++++++++++++++++++ .../transmngr/src/tmTransactionService.h | 196 ++++++++ .../ipc/ipcd/extensions/transmngr/test/.cvsignore | 6 + .../ipc/ipcd/extensions/transmngr/test/Makefile.in | 68 +++ .../extensions/transmngr/test/tmModuleTest.cpp | 323 +++++++++++++ 32 files changed, 3733 insertions(+) create mode 100644 src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/.cvsignore create mode 100644 src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/Makefile.in create mode 100644 src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/build/.cvsignore create mode 100644 src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/build/Makefile.in create mode 100644 src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/build/tmCID.h create mode 100644 src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/build/tmModule.cpp create mode 100644 src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/common/.cvsignore create mode 100644 src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/common/Makefile.in create mode 100644 src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/common/tmTransaction.cpp create mode 100644 src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/common/tmTransaction.h create mode 100644 src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/common/tmUtils.h create mode 100644 src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/common/tmVector.cpp create mode 100644 src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/common/tmVector.h create mode 100644 src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/module/.cvsignore create mode 100644 src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/module/Makefile.in create mode 100644 src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/module/tmIPCModule.cpp create mode 100644 src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/module/tmIPCModule.h create mode 100644 src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/module/tmQueue.cpp create mode 100644 src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/module/tmQueue.h create mode 100644 src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/module/tmTransactionManager.cpp create mode 100644 src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/module/tmTransactionManager.h create mode 100644 src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/public/.cvsignore create mode 100644 src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/public/Makefile.in create mode 100644 src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/public/ipcITransactionObserver.idl create mode 100644 src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/public/ipcITransactionService.idl create mode 100644 src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/src/.cvsignore create mode 100644 src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/src/Makefile.in create mode 100644 src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/src/tmTransactionService.cpp create mode 100644 src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/src/tmTransactionService.h create mode 100644 src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/test/.cvsignore create mode 100644 src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/test/Makefile.in create mode 100644 src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/test/tmModuleTest.cpp (limited to 'src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr') diff --git a/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/.cvsignore b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/.cvsignore new file mode 100644 index 00000000..f3c7a7c5 --- /dev/null +++ b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/.cvsignore @@ -0,0 +1 @@ +Makefile diff --git a/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/Makefile.in b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/Makefile.in new file mode 100644 index 00000000..5f80740d --- /dev/null +++ b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/Makefile.in @@ -0,0 +1,52 @@ +# ***** 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 is Mozilla Transaction Manager. +# +# The Initial Developer of the Original Code is +# Netscape Communications Corp. +# Portions created by the Initial Developer are Copyright (C) 2003 +# the Initial Developer. All Rights Reserved. +# +# Contributor(s): +# John Gaunt +# +# 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 ***** + +DEPTH = ../../../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +DIRS = common module public src + +ifdef ENABLE_TESTS +DIRS += test +endif + +include $(topsrcdir)/config/rules.mk + diff --git a/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/build/.cvsignore b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/build/.cvsignore new file mode 100644 index 00000000..b292dd21 --- /dev/null +++ b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/build/.cvsignore @@ -0,0 +1,9 @@ +Makefile +module.rc +module.res +tmModule.obj +transmngr_client.dll +transmngr_client.pdb +transmngr_client.exp +transmngr_client.lib +transmngr_client.ilk \ No newline at end of file diff --git a/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/build/Makefile.in b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/build/Makefile.in new file mode 100644 index 00000000..87277839 --- /dev/null +++ b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/build/Makefile.in @@ -0,0 +1,75 @@ +# ***** 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 is Mozilla Transaction Manager. +# +# The Initial Developer of the Original Code is +# Netscape Communications Corp. +# Portions created by the Initial Developer are Copyright (C) 2003 +# the Initial Developer. All Rights Reserved. +# +# Contributor(s): +# John Gaunt +# +# 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 ***** + +DEPTH = ../../../../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +MODULE = transmngr +LIBRARY_NAME = transmngr_client +EXPORT_LIBRARY = 1 +IS_COMPONENT = 1 +MODULE_NAME = transmngr + +REQUIRES = ipcd \ + string \ + xpcom \ + $(NULL) + +CPPSRCS = tmModule.cpp +EXPORTS = tmCID.h + +SHARED_LIBRARY_LIBS = \ + $(DIST)/lib/$(LIB_PREFIX)transmngr_s.$(LIB_SUFFIX) \ + $(DIST)/lib/$(LIB_PREFIX)transmngrcom_s.$(LIB_SUFFIX) \ + $(NULL) + +LOCAL_INCLUDES = \ + -I$(srcdir)/../src \ + -I$(srcdir)/../common \ + $(NULL) + +EXTRA_DSO_LDOPTS = \ + $(LIBS_DIR) \ + $(EXTRA_DSO_LIBS) \ + $(MOZ_COMPONENT_LIBS) \ + $(NULL) + +include $(topsrcdir)/config/rules.mk diff --git a/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/build/tmCID.h b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/build/tmCID.h new file mode 100644 index 00000000..8ca23b84 --- /dev/null +++ b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/build/tmCID.h @@ -0,0 +1,53 @@ +/* ***** 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 is Mozilla Transaction Manager. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corp. + * Portions created by the Initial Developer are Copyright (C) 2003 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * John Gaunt + * + * 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 ***** */ + +#ifndef tmCID_h__ +#define tmCID_h__ + +#define TRANSACTION_SERVICE_CLASSNAME \ + "tmTransactionService" +#define TRANSACTION_SERVICE_CONTRACTID \ + "@mozilla.org/transaction/service;1" +#define TRANSACTION_SERVICE_CID \ +{ /* 1403adf4-94d1-4c67-a8ae-d9f86972d378 */ \ + 0x1403adf4, \ + 0x94d1, \ + 0x4c67, \ + {0xa8, 0xae, 0xd9, 0xf8, 0x69, 0x72, 0xd3, 0x78} \ +} + +#endif // !tmCID_h__ diff --git a/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/build/tmModule.cpp b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/build/tmModule.cpp new file mode 100644 index 00000000..2853ba0a --- /dev/null +++ b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/build/tmModule.cpp @@ -0,0 +1,71 @@ +/* ***** 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 is Mozilla Transaction Manager. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corp. + * Portions created by the Initial Developer are Copyright (C) 2003 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * John Gaunt + * + * 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 "nsICategoryManager.h" +#include "nsIGenericFactory.h" +#include "nsIServiceManager.h" +#include "tmCID.h" +#include "tmTransactionService.h" + +//----------------------------------------------------------------------------- +// Define the contructor function for the objects +// +// NOTE: This creates an instance of objects by using the default constructor +//----------------------------------------------------------------------------- +NS_GENERIC_FACTORY_CONSTRUCTOR(tmTransactionService) + +//----------------------------------------------------------------------------- +// Define a table of CIDs implemented by this module along with other +// information like the function to create an instance, contractid, and +// class name. +//----------------------------------------------------------------------------- +static const nsModuleComponentInfo components[] = { + { TRANSACTION_SERVICE_CLASSNAME, + TRANSACTION_SERVICE_CID, + TRANSACTION_SERVICE_CONTRACTID, + tmTransactionServiceConstructor }, + /* + tmTransactionServiceRegisterProc, + tmTransactionServiceUnregisterProc }, + */ +}; + +//----------------------------------------------------------------------------- +// Implement the NSGetModule() exported function for your module +// and the entire implementation of the module object. +//----------------------------------------------------------------------------- +NS_IMPL_NSGETMODULE(transmngr, components) diff --git a/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/common/.cvsignore b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/common/.cvsignore new file mode 100644 index 00000000..df8a43a2 --- /dev/null +++ b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/common/.cvsignore @@ -0,0 +1,5 @@ +Makefile +tmTransaction.obj +tmVector.obj +transmgrcom_s.pdb +transmgrcom_s.lib diff --git a/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/common/Makefile.in b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/common/Makefile.in new file mode 100644 index 00000000..4521c39a --- /dev/null +++ b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/common/Makefile.in @@ -0,0 +1,61 @@ +# ***** 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 is Mozilla Transaction Manager. +# +# The Initial Developer of the Original Code is +# Netscape Communications Corp. +# Portions created by the Initial Developer are Copyright (C) 2003 +# the Initial Developer. All Rights Reserved. +# +# Contributor(s): +# John Gaunt +# +# 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 ***** + +DEPTH = ../../../../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +MODULE = ipcd +LIBRARY_NAME = transmgrcom_s +FORCE_STATIC_LIB = 1 +MODULE_NAME = ipcd + +FORCE_USE_PIC = 1 + +REQUIRES = \ + xpcom \ + $(NULL) + +CPPSRCS = \ + tmTransaction.cpp \ + tmVector.cpp \ + $(NULL) + +include $(topsrcdir)/config/rules.mk diff --git a/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/common/tmTransaction.cpp b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/common/tmTransaction.cpp new file mode 100644 index 00000000..5fb7e5bf --- /dev/null +++ b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/common/tmTransaction.cpp @@ -0,0 +1,107 @@ +/* ***** 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 is Mozilla Transaction Manager. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corp. + * Portions created by the Initial Developer are Copyright (C) 2003 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * John Gaunt + * + * 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 +#include "tmTransaction.h" +#ifdef VBOX_USE_IPRT_IN_XPCOM +# include +#endif + +/////////////////////////////////////////////////////////////////////////////// +// Constructor(s) & Destructor + +tmTransaction::~tmTransaction() { + if (mHeader) +#ifdef VBOX_USE_IPRT_IN_XPCOM + RTMemFree(mHeader); +#else + free(mHeader); +#endif +} + +// call only once per lifetime of object. does not reclaim the +// raw message, only sets it. +nsresult +tmTransaction::Init(PRUint32 aOwnerID, + PRInt32 aQueueID, + PRUint32 aAction, + PRInt32 aStatus, + const PRUint8 *aMessage, + PRUint32 aLength) { + nsresult rv = NS_OK; + tmHeader *header = nsnull; + + // indicates the message is the entire raw message + if (aQueueID == TM_INVALID_ID) { +#ifdef VBOX_USE_IPRT_IN_XPCOM + header = (tmHeader*) RTMemAlloc(aLength); +#else + header = (tmHeader*) malloc(aLength); +#endif + if (header) { + mRawMessageLength = aLength; + memcpy(header, aMessage, aLength); + } + else + rv = NS_ERROR_OUT_OF_MEMORY; + } + else { // need to create the tmHeader and concat the message +#ifdef VBOX_USE_IPRT_IN_XPCOM + header = (tmHeader*) RTMemAlloc (sizeof(tmHeader) + aLength); +#else + header = (tmHeader*) malloc (sizeof(tmHeader) + aLength); +#endif + if (header) { + mRawMessageLength = sizeof(tmHeader) + aLength; + header->action = aAction; + header->queueID = aQueueID; + header->status = aStatus; + header->reserved = 0x00000000; + if (aLength > 0) // add the message if it exists + memcpy((header + 1), aMessage, aLength); + } + else + rv = NS_ERROR_OUT_OF_MEMORY; + } + + if (NS_SUCCEEDED(rv)) { + mOwnerID = aOwnerID; + mHeader = header; + } + + return rv; +} diff --git a/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/common/tmTransaction.h b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/common/tmTransaction.h new file mode 100644 index 00000000..b86f20f0 --- /dev/null +++ b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/common/tmTransaction.h @@ -0,0 +1,234 @@ +/* ***** 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 is Mozilla Transaction Manager. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corp. + * Portions created by the Initial Developer are Copyright (C) 2003 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * John Gaunt + * + * 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 ***** */ + +#ifndef _tmTransaction_H_ +#define _tmTransaction_H_ + +#include "tmUtils.h" + +////////////////////////////////////////////////////////////////////////////// +// +// Message format +// +// |------------------------------------|-- +// |QueueID | | +// |------------------------------------| | +// | Action - Post/Flush/Attach etc | |- this is the tmHeader struct +// |------------------------------------| | +// |Status | | +// |------------------------------------| | +// |Padding | | +// |------------------------------------|-- +// |Message Data (payload) | +// |------------------------------------| +// +// The Attach call is a special case in that it doesn't have a QueueID yet. A +// QueueID will be 0's. The message Data will be the Queue Name String which +// will be the profile name with a domain attached, a domain being +// [prefs|cookies|etc] +// +////////////////////////////////////////////////////////////////////////////// + +/** + * tmHeader contains various flags identifying + */ +struct tmHeader { + PRInt32 queueID; // will be the index of the queue in the TM, can be < 0 + PRUint32 action; // defined by tmUtils.h will be > 0 + PRInt32 status; // return values from methods, could be < 0 + PRUint32 reserved; // not currently used, maintaining word alignment +}; + +/** + * Using tmTransaction: + * + * After creating a tmTransaction either through new or as a member + * or local variable a process must call Init() with the proper set of + * arguements to initialize the state of the transaction. tmTransaction is + * set up to accept 3 types of initialization. + * + * 1) Raw message - All data is carried in the byte pointer aMessage, + * args 2,3,4 should be set to TM_NO_ID and aLength + * must be set to the full length of aMessage, including null + * termination if the payload is a null-term string and the size of the + * tmHeader struct preceeding the message. Currently this + * format is used at the IPC boundary, where we receive a byte pointer + * from the IPC Daemon. + * + * 2) Flags only - aQueueID, aAction and aStatus are all set. aMessage + * should be set to nsnull and aLength to 0. This format is used when + * sending reply messages (except for ATTACH_REPLY) and when the TS + * Transaction Service is sending "control" messages to the Manager - + * flush, detach, etc... + * + * 3) Flags and message - All arguements are set. The aMessage is only + * the message for the client app. aLength should be set to the length + * of aMessage and not include the length of the tmHeader struct. + * + * The only data member you can set post initialization is the QueueID. + * You should only call Init() once in the lifetime of a tmTransaction + * as it doesn't clean up the exisiting data before assigning the new + * data. Therefore it would leak most heinously if Init() were to be + * called twice. + * + * mOwnerID only has relevance on the IPC daemon side of things. The + * Transaction Service has no knowledge of this ID and makes no use + * of it. + */ +class tmTransaction +{ + +public: + + //////////////////////////////////////////////////////////////////////////// + // Constructor(s) & Destructor + + tmTransaction(): mHeader(nsnull), mRawMessageLength(0), mOwnerID(0) { } + + virtual ~tmTransaction(); + + //////////////////////////////////////////////////////////////////////////// + // Public Member Functions + + // Initializer //////////// + + /** + * Sets up the internal data of the transaction. Allows for 3 basic ways + * to call this function: No flags and just one big raw message, Just + * flags and no message, and finally flags and message. If the message + * exists it is copied into the transaction. + * + * @param aOwnerID is given to us by the IPC Daemon and is specific + * to that transport layer. It is only set when transactions + * are sent from the TM to the TS. + * + * @param aQueueID is the either the destination queue, or the queue from + * where this transaction is eminating + * + * @param aAction is the action that occured to generate this transaction + * + * @param aStatus is the success state of the action. + * + * @param aMessage can be a raw message including the 3 flags above or it + * can be just the "payload" of the transaction that the destination + * process is going deal with. + * + * @param aLength is the length of the message. If there is a null + * terminated string in the message make sure the length includes + * the null termination. + * + * @returns NS_OK if everything was successful + * @returns NS_ERROR_OUT_OF_MEMORY if allocation of space for the + * copy of the message fails. + */ + nsresult Init(PRUint32 aOwnerID, + PRInt32 aQueueID, + PRUint32 aAction, + PRInt32 aStatus, + const PRUint8 *aMessage, + PRUint32 aLength); + + // Data Accessors ///////// + + /** + * @returns a const byte pointer to the message + */ + const PRUint8* GetMessage() const { return (PRUint8*)(mHeader + 1); } + + /** + * @returns the length of the message + */ + PRUint32 GetMessageLength() const { + return (mRawMessageLength > sizeof(tmHeader)) ? + (mRawMessageLength - sizeof(tmHeader)) : 0; + } + + /** + * @returns a const pointer to the memory containing the + * flag information followed immediately by the message + * data. + */ + const PRUint8* GetRawMessage() const { return (PRUint8*) mHeader; } + + /** + * @returns the length of the flags and message combined + */ + PRUint32 GetRawMessageLength() const { return mRawMessageLength; } + + /** + * @returns the id of the destination or sending queue, depending on the + * direction of the transaction. + */ + PRInt32 GetQueueID() const { return mHeader->queueID; } + + /** + * @returns the action represented by this transaction + */ + PRUint32 GetAction() const { return mHeader->action; } + + /** + * @returns the success state, if applicable of the action leading + * up to this message + */ + PRInt32 GetStatus() const { return mHeader->status; } + + /** + * @returns the client ID (in IPC daemon terms) of the client who initiated + * the exchange that generated this transaction. + */ + PRUint32 GetOwnerID() const { return mOwnerID; } + + // Data Mutator /////////// + + /** + * Sets the ID of the destination or source queue. Init should have been + * called before the call to this function. + */ + void SetQueueID(PRInt32 aID) { mHeader->queueID = aID; } + +protected: + + //////////////////////////////////////////////////////////////////////////// + // Protected Member Variables + + tmHeader* mHeader; // points to beginning of entire message + PRUint32 mRawMessageLength; // length of entire message, incl tmHeader + PRUint32 mOwnerID; // client who sent this trans. - a IPC ClientID + +}; + +#endif diff --git a/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/common/tmUtils.h b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/common/tmUtils.h new file mode 100644 index 00000000..f85184d3 --- /dev/null +++ b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/common/tmUtils.h @@ -0,0 +1,93 @@ +/* ***** 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 is Mozilla Transaction Manager. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corp. + * Portions created by the Initial Developer are Copyright (C) 2003 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * John Gaunt + * + * 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 ***** */ + +#ifndef _tmUtils_H_ +#define _tmUtils_H_ + +#include "nscore.h" +#include "nsError.h" +#include "nsID.h" +#include "prlog.h" +#include + +// UUID used to identify the Transaction Module in both daemon and client +// not part of the XPCOM hooks, but rather a means of identifying +// modules withing the IPC daemon. +#define TRANSACTION_MODULE_ID \ +{ /* c3dfbcd5-f51d-420b-abf4-3bae445b96a9 */ \ + 0xc3dfbcd5, \ + 0xf51d, \ + 0x420b, \ + {0xab, 0xf4, 0x3b, 0xae, 0x44, 0x5b, 0x96, 0xa9} \ +} + +//static const nsID kTransModuleID = TRANSACTION_MODULE_ID; + +/////////////////////////////////////////////////////////////////////////////// +// match NS_ERROR_FOO error code formats +// +// only create new errors for those errors that are specific to TM + +#define NS_ERROR_MODULE_TM 27 /* XXX goes in nserror.h -- integrating with ns error codes */ + +#define TM_ERROR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_TM, 1) +#define TM_ERROR_WRONG_QUEUE NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_TM, 2) +#define TM_ERROR_NOT_POSTED NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_TM, 3) +#define TM_ERROR_QUEUE_EXISTS NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_TM, 4) +#define TM_SUCCESS_DELETE_QUEUE NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_TM, 6) + + +// XXX clean up: +#define TM_INVALID_ID 0xFFFFFFFF +#define TM_INVALID 0xFFFFFFFF +#define TM_NO_ID 0xFFFFFFFE + +// Transaction Actions +enum { + TM_ATTACH = 0, + TM_ATTACH_REPLY, + TM_POST, + TM_POST_REPLY, + TM_NOTIFY, + TM_FLUSH, + TM_FLUSH_REPLY, + TM_DETACH, + TM_DETACH_REPLY +}; + +#endif + diff --git a/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/common/tmVector.cpp b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/common/tmVector.cpp new file mode 100644 index 00000000..99213f27 --- /dev/null +++ b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/common/tmVector.cpp @@ -0,0 +1,179 @@ +/* ***** 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 is Mozilla Transaction Manager. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corp. + * Portions created by the Initial Developer are Copyright (C) 2003 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * John Gaunt + * + * 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 +#include "tmVector.h" +#ifdef VBOX_USE_IPRT_IN_XPCOM +# include +#endif + +//////////////////////////////////////////////////////////////////////////// +// Constructor(s) & Destructor + +// can not be responsible for reclaiming memory pointed to by the void*s in +// the collection - how would we reclaim, don't know how they were allocated +tmVector::~tmVector() { + if (mElements) +#ifdef VBOX_USE_IPRT_IN_XPCOM + RTMemFree((void*)mElements); +#else + free((void*)mElements); +#endif +} + +/////////////////////////////////////////////////////////////////////////////// +// Public Member Functions + +nsresult +tmVector::Init() { + +#ifdef VBOX_USE_IPRT_IN_XPCOM + mElements = (void**) RTMemAllocZ (mCapacity * sizeof(void*)); +#else + mElements = (void**) calloc (mCapacity, sizeof(void*)); +#endif + if (!mElements) + return NS_ERROR_OUT_OF_MEMORY; + return NS_OK; +} + +/////////////////////////////////////////////////////////////////////////////// +// mutators + +PRInt32 +tmVector::Append(void *aElement){ + PR_ASSERT(aElement); + + // make sure there is room + if (mNext == mCapacity) + if (NS_FAILED(Grow())) + return -1; + + // put the element in the array + mElements[mNext] = aElement; + mCount++; + + // encapsulates the index into a success value + return mNext++; // post increment. +} + +void +tmVector::Remove(void *aElement) { + PR_ASSERT(aElement); + + for (PRUint32 index = 0; index < mNext; index++) { + if (mElements[index] == aElement) { + mElements[index] = nsnull; + mCount--; + if (index == mNext-1) { // if we removed the last element + mNext--; + // don't test for success of the shrink + Shrink(); + } + } + } +} + +void +tmVector::RemoveAt(PRUint32 aIndex) { + PR_ASSERT(aIndex < mNext); + + // remove the element if it isn't already nsnull + if (mElements[aIndex] != nsnull) { + mElements[aIndex] = nsnull; + mCount--; + if (aIndex == mNext-1) { // if we removed the last element + mNext--; + // don't test for success of the shrink + Shrink(); + } + } +} + +//void* +//tmVector::operator[](int index) { +// if (index < mNext && index >= 0) +// return mElements[index]; +// return nsnull; +//} + +// Does not delete any of the data, merely removes references to them +void +tmVector::Clear(){ + memset(mElements, 0, mCapacity); + mCount = 0; + mNext = 0; +} + +////////////////////////////////////////////////////////////////////////////// +// Protected Member Functions + +// increases the capacity by the growth increment +nsresult +tmVector::Grow() { + + PRUint32 newcap = mCapacity + GROWTH_INC; +#ifdef VBOX_USE_IPRT_IN_XPCOM + mElements = (void**) RTMemRealloc(mElements, (newcap * sizeof(void*))); +#else + mElements = (void**) realloc(mElements, (newcap * sizeof(void*))); +#endif + if (mElements) { + mCapacity = newcap; + return NS_OK; + } + return NS_ERROR_FAILURE; +} + +// reduces the capacity by the growth increment. leaves room +// for one more add before needing to Grow(). +nsresult +tmVector::Shrink() { + + PRUint32 newcap = mCapacity - GROWTH_INC; + if (mNext < newcap) { +#ifdef VBOX_USE_IPRT_IN_XPCOM + mElements = (void**) RTMemRealloc(mElements, newcap * sizeof(void*)); +#else + mElements = (void**) realloc(mElements, newcap * sizeof(void*)); +#endif + if (!mElements) + return NS_ERROR_OUT_OF_MEMORY; + mCapacity = newcap; + } + return NS_OK; +} diff --git a/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/common/tmVector.h b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/common/tmVector.h new file mode 100644 index 00000000..4ddb68ef --- /dev/null +++ b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/common/tmVector.h @@ -0,0 +1,160 @@ +/* ***** 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 is Mozilla Transaction Manager. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corp. + * Portions created by the Initial Developer are Copyright (C) 2003 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * John Gaunt + * + * 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 ***** */ + +#ifndef _tmVector_H_ +#define _tmVector_H_ + +#include "tmUtils.h" + +#define GROWTH_INC 5 + +/** + * A simple, clear, self-growing, collection of objects. typed independant + * basically a growing array. Useful in situations where you need an + * indexed collection but do not know the size in advance and need the + * ability for increase and decrease in size. Not optimized for anything + * in particular, or any size in particular. + * + * Is able to guarantee the index of an item will + * not change due to removals of a lower indexed item. The growing, + * and shrinking all happens to the end of the collection + * + * Does not backfill, adds to the end. At some point this should be + * changed to make best use of space. + */ +class tmVector +{ +public: + + //////////////////////////////////////////////////////////////////////////// + // Constructor(s) & Destructor + + /** + * Set some sane default values to set up the internal storage. Init() + * must be called after construction of the object to allcate the + * backing store. + */ + tmVector() : mNext(0), mCount(0), mCapacity(10), mElements(nsnull) {;} + + /** + * Reclaim the memory allocated in the Init() method. + */ + virtual ~tmVector(); + + //////////////////////////////////////////////////////////////////////////// + // Public Member Functions + + /** + * Allocates the storage back-end + * + * @returns NS_OK if allocation succeeded + * @returns NS_ERROR_OUT_OF_MEMORY if the allocation failed + */ + nsresult Init(); + + // mutators + + /** + * @returns the index of the element added, if successful + * @returns -1 if an error occured during allocation of space + */ + PRInt32 Append(void *aElement); + + /** + * This does not collapse the collection, it leaves holes. Note, it also + * doesn't delete the element, it merely removes it from the collection + */ + void Remove(void *aElement); + + /** + * This does not collapse the collection, it leaves holes. Note, it also + * doesn't delete the element, it merely removes it from the collection + */ + void RemoveAt(PRUint32 aIndex); + + /** + * Does not call delete on the elements since we have no idea how to + * reclaim the memory. Sets all array slots to 0. + */ + void Clear(); + + /** + * @returns the element at the index indicated, including nsnull if the + * slot is empty. + */ + void* operator[](PRUint32 index) { + PR_ASSERT(index < mNext); + return mElements[index]; + } + + /** + * @returns the number of elements stored + */ + PRUint32 Count() { return mCount; } + + /** + * Meant to be used as the conditional in a loop. |index < size| should + * reach all elements of the collection and not run out of bounds. If + * slots 0,1,4,5,6 contain elements Size() will return 7, Count() will + * return 5. + * + * @returns the number of slots in the array taken, irrespective of + * holes in the collection. + */ + PRUint32 Size() { return mNext; } + +protected: + + nsresult Grow(); // mCapacity += GROWTH_INC - realloc()s + nsresult Shrink(); // mCapacity -= GROWTH_INC - dumb, free, malloc + + //////////////////////////////////////////////////////////////////////////// + // Protected Member Variables + + // bookkeeping variables + PRUint32 mNext; // next element insertion slot (0 based) + PRUint32 mCount; // how many elements in the Vector (1 based) + PRUint32 mCapacity; // current capacity of the Vector (1 based) + + // the actual array of objects being stored + void **mElements; + +private: + +}; + +#endif diff --git a/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/module/.cvsignore b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/module/.cvsignore new file mode 100644 index 00000000..ccfb2bc3 --- /dev/null +++ b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/module/.cvsignore @@ -0,0 +1,11 @@ +Makefile +module.rc +module.res +tmIPCModule.obj +tmQueue.obj +tmTransactionManager.obj +transmgr.dll +transmgr.exp +transmgr.ilk +transmgr.lib +transmgr.pdb diff --git a/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/module/Makefile.in b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/module/Makefile.in new file mode 100644 index 00000000..b8baa225 --- /dev/null +++ b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/module/Makefile.in @@ -0,0 +1,100 @@ +# ***** 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 is Mozilla Transaction Manager. +# +# The Initial Developer of the Original Code is +# Netscape Communications Corp. +# Portions created by the Initial Developer are Copyright (C) 2003 +# the Initial Developer. All Rights Reserved. +# +# Contributor(s): +# John Gaunt +# +# 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 ***** + +DEPTH = ../../../../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +MODULE = ipcd +LIBRARY_NAME = transmgr +MODULE_NAME = ipcd + +FORCE_SHARED_LIB = 1 +NO_DIST_INSTALL = 1 +NO_INSTALL = 1 + +ifeq ($(OS_ARCH),Darwin) +NO_COMPONENT_LINK_MAP = 1 +MOZ_COMPONENTS_VERSION_SCRIPT_LDFLAGS = +endif + +REQUIRES = nspr \ + xpcom \ + $(NULL) + +CPPSRCS = \ + tmIPCModule.cpp \ + tmQueue.cpp \ + tmTransactionManager.cpp \ + $(NULL) + +EXPORTS = \ + tmIPCModule.h \ + $(NULL) + +LOCAL_INCLUDES = \ + -I$(srcdir)/../common \ + $(NULL) + +include $(topsrcdir)/config/config.mk + +LIBS = \ + $(EXTRA_DSO_LIBS) \ + $(NSPR_LIBS) \ + $(NULL) + +EXTRA_DSO_LDOPTS = \ + $(LIBS_DIR) \ + $(NSPR_LIBS) \ + $(DIST)/lib/$(LIB_PREFIX)transmgrcom_s.$(LIB_SUFFIX) \ + $(EXTRA_DSO_LIBS) \ + $(NULL) + +include $(topsrcdir)/config/rules.mk + +_IPC_FILES = \ + $(DLL_PREFIX)$(LIBRARY_NAME)$(DLL_SUFFIX) \ + $(NULL) + +libs:: $(_IPC_FILES) + $(INSTALL) $^ $(DIST)/bin/ipc/modules + +install:: $(_IPC_FILES) + $(SYSINSTALL) $(IFLAGS1) $^ $(DESTDIR)$(mozappdir)/ipc/modules diff --git a/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/module/tmIPCModule.cpp b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/module/tmIPCModule.cpp new file mode 100644 index 00000000..3982c93c --- /dev/null +++ b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/module/tmIPCModule.cpp @@ -0,0 +1,137 @@ +/* ***** 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 is Mozilla Transaction Manager. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corp. + * Portions created by the Initial Developer are Copyright (C) 2003 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * John Gaunt + * + * 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 "tmIPCModule.h" +#include "tmTransaction.h" +#include "tmTransactionManager.h" + +/////////////////////////////////////////////////////////////////////////////// +// IPC Daemon hookup stuff + +// functionpointer array giving access to this module from the IPC daemon +static ipcModuleMethods gTransMethods = +{ + IPC_MODULE_METHODS_VERSION, + tmIPCModule::Init, + tmIPCModule::Shutdown, + tmIPCModule::HandleMsg +}; + +static ipcModuleEntry gTransModuleEntry[] = +{ + { TRANSACTION_MODULE_ID, &gTransMethods } +}; + +IPC_IMPL_GETMODULES(TransactionModule, gTransModuleEntry) + +static const nsID kTransModuleID = TRANSACTION_MODULE_ID; + +/////////////////////////////////////////////////////////////////////////////// +// Define global variable + +tmTransactionManager *tmIPCModule::tm; + +/////////////////////////////////////////////////////////////////////////////// +// IPC Module API + +void +tmIPCModule::Init() { + if (!tm) + InitInternal(); +} + +void +tmIPCModule::Shutdown() { + if (tm) { + delete tm; + tm = nsnull; + } +} + +// straight pass-through, don't check args, let the TM do it. +void +tmIPCModule::HandleMsg(ipcClientHandle client, const nsID &target, + const void *data, PRUint32 dataLen) { + + // make sure the trans mngr is there + if (!tm && (InitInternal() < 0)) + return; + + // create the transaction + tmTransaction *trans = new tmTransaction(); + + // initialize it + if (trans) { + if(NS_SUCCEEDED(trans->Init(IPC_GetClientID(client), // who owns it + TM_INVALID_ID, // in data + TM_INVALID, // in data + TM_INVALID, // in data + (PRUint8 *)data, // raw message + dataLen))) { // length of message + // pass it on to the trans mngr + tm->HandleTransaction(trans); + } + else + delete trans; + } +} + +/////////////////////////////////////////////////////////////////////////////// +// tmIPCModule API + +// straight pass-through, don't check args, let the TS & TM do it. +void +tmIPCModule::SendMsg(PRUint32 aDestClientIPCID, tmTransaction *aTransaction) { + + IPC_SendMsg(aDestClientIPCID, + kTransModuleID, + (void *)aTransaction->GetRawMessage(), + aTransaction->GetRawMessageLength()); +} + +/////////////////////////////////////////////////////////////////////////////// +// Protected Methods + +PRInt32 +tmIPCModule::InitInternal() { + + tm = new tmTransactionManager(); + if (tm) + return tm->Init(); + return -1; +} + diff --git a/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/module/tmIPCModule.h b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/module/tmIPCModule.h new file mode 100644 index 00000000..d4623b1e --- /dev/null +++ b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/module/tmIPCModule.h @@ -0,0 +1,109 @@ +/* ***** 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 is Mozilla Transaction Manager. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corp. + * Portions created by the Initial Developer are Copyright (C) 2003 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * John Gaunt + * + * 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 ***** */ + +#ifndef _tmIPCModule_H_ +#define _tmIPCModule_H_ + +#include "ipcModuleUtil.h" +#include "tmUtils.h" + +// forward declarations +class tmTransaction; +class tmTransactionManager; + +/** + * Basically an interface between the tmTransactionManager and the IPC + * daemon. Does little else than format the data from one party into + * a format understandable to the other. + * + * The reason for this class is to try and abstract the transportation + * layer the transaction service uses. By using this class the Transaction + * Manager itself only needs to know that clients are identified by + * PRUint32 IDs. + */ +class tmIPCModule +{ +public: + + //////////////////////////////////////////////////////////////////////////// + // ipcModule API - called from IPC daemon + + /** + * Clean up the TM + */ + static void Shutdown(); + + /** + * Check the TM, create it if neccessary. + */ + static void Init(); + + /** + * Receives a message from the IPC daemon, creates a transaction and sends + * it to the TM to deal with. + */ + static void HandleMsg(ipcClientHandle client, + const nsID &target, + const void *data, + PRUint32 dataLen); + + //////////////////////////////////////////////////////////////////////////// + // tmIPCModule API - called from tmTransactionManager + + /** + * Sends the message to the IPC daemon to be deliverd to the client arg. + */ + static void SendMsg(PRUint32 aDestClientIPCID, tmTransaction *aTransaction); + +protected: + + /** + * tm should be null coming into this method. This does NOT delete tm + * first. + * + * @returns NS_OK if everything succeeds + * @returns -1 if initialization fails + */ + static PRInt32 InitInternal(); + + static tmTransactionManager *tm; + +}; + +#endif + + diff --git a/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/module/tmQueue.cpp b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/module/tmQueue.cpp new file mode 100644 index 00000000..5164446f --- /dev/null +++ b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/module/tmQueue.cpp @@ -0,0 +1,223 @@ +/* ***** 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 is Mozilla Transaction Manager. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corp. + * Portions created by the Initial Developer are Copyright (C) 2003 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * John Gaunt + * + * 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 "plstr.h" +#include "tmQueue.h" +#include "tmTransaction.h" +#include "tmTransactionManager.h" +#include "tmUtils.h" + +/////////////////////////////////////////////////////////////////////////////// +// Constructors & Destructor + +tmQueue::~tmQueue() { + + // empty the vectors + PRUint32 index = 0; + PRUint32 size = mTransactions.Size(); + for ( ; index < size ; index++) { + if (mTransactions[index]) + delete (tmTransaction *)mTransactions[index]; + } + + // don't need to delete the mListeners because + // we just insert PRUint32s, no allocation + + mTM = nsnull; + mID = 0; + if (mName) + PL_strfree(mName); +} + +/////////////////////////////////////////////////////////////////////////////// +// Public Methods + +PRInt32 +tmQueue::Init(const char* aName, PRUint32 aID, tmTransactionManager *aTM) { + PR_ASSERT(mTM == nsnull); + + if (NS_SUCCEEDED(mTransactions.Init()) && + NS_SUCCEEDED(mListeners.Init()) && + ((mName = PL_strdup(aName)) != nsnull) ) { + mTM = aTM; + mID = aID; + return NS_OK; + } + return -1; +} + +PRInt32 +tmQueue::AttachClient(PRUint32 aClientID) { + + PRInt32 status = NS_OK; // success of adding client + + if (!IsAttached(aClientID)) { + // add the client to the listener list -- null safe call + status = mListeners.Append((void*) aClientID); + } + else + status = -2; + + // create & init a reply transaction + tmTransaction trans; + if (NS_SUCCEEDED(trans.Init(aClientID, // owner's ipc ID + mID, // client gets our ID + TM_ATTACH_REPLY, // action + status, // success of the add + (PRUint8*)mName, // client matches name to ID + PL_strlen(mName)+1))) { + // send the reply + mTM->SendTransaction(aClientID, &trans); + } + + // if we successfully added the client - send all current transactions + if (status >= 0) { // append returns the index of the added element + + PRUint32 size = mTransactions.Size(); + for (PRUint32 index = 0; index < size; index++) { + if (mTransactions[index]) + mTM->SendTransaction(aClientID, (tmTransaction*) mTransactions[index]); + } + } + return status; +} + +PRInt32 +tmQueue::DetachClient(PRUint32 aClientID) { + + PRUint32 size = mListeners.Size(); + PRUint32 id = 0; + PRInt32 status = -1; + + for (PRUint32 index = 0; index < size; index++) { + id = (PRUint32)NS_PTR_TO_INT32(mListeners[index]); + if(id == aClientID) { + mListeners.RemoveAt(index); + status = NS_OK; + break; + } + } + + tmTransaction trans; + if (NS_SUCCEEDED(trans.Init(aClientID, + mID, + TM_DETACH_REPLY, + status, + nsnull, + 0))) { + // send the reply + mTM->SendTransaction(aClientID, &trans); + } + + // if we've removed all the listeners, remove the queue. + if (mListeners.Size() == 0) + return TM_SUCCESS_DELETE_QUEUE; + return status; +} + +void +tmQueue::FlushQueue(PRUint32 aClientID) { + + if(!IsAttached(aClientID)) + return; + + PRUint32 size = mTransactions.Size(); + for (PRUint32 index = 0; index < size; index++) + if (mTransactions[index]) + delete (tmTransaction*)mTransactions[index]; + + mTransactions.Clear(); + + tmTransaction trans; + if (NS_SUCCEEDED(trans.Init(aClientID, + mID, + TM_FLUSH_REPLY, + NS_OK, + nsnull, + 0))) { + mTM->SendTransaction(aClientID, &trans); + } +} + +PRInt32 +tmQueue::PostTransaction(tmTransaction *aTrans) { + + PRInt32 status = -1; + PRUint32 ownerID = aTrans->GetOwnerID(); + + // if we are attached, have the right queue and have successfully + // appended the transaction to the queue, send the transaction + // to all the listeners. + + if (IsAttached(ownerID) && aTrans->GetQueueID() == mID) + status = mTransactions.Append(aTrans); + + if (status >= 0) { + // send the transaction to all members of mListeners except the owner + PRUint32 size = mListeners.Size(); + PRUint32 id = 0; + for (PRUint32 index = 0; index < size; index++) { + id = (PRUint32)NS_PTR_TO_INT32(mListeners[index]); + if (ownerID != id) + mTM->SendTransaction(id, aTrans); + } + } + + tmTransaction trans; + if (NS_SUCCEEDED(trans.Init(ownerID, + mID, + TM_POST_REPLY, + status, + nsnull, + 0))) { + // send the reply + mTM->SendTransaction(ownerID, &trans); + } + return status; +} + +PRBool +tmQueue::IsAttached(PRUint32 aClientID) { + // XXX could be an issue if the aClientID is 0 and there + // is a "hole" in the mListeners vector. - may NEED to store PRUint32*s + PRUint32 size = mListeners.Size(); + for (PRUint32 index = 0; index < size; index++) { + if (aClientID == (PRUint32)NS_PTR_TO_INT32(mListeners[index])) + return PR_TRUE; + } + return PR_FALSE; +} diff --git a/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/module/tmQueue.h b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/module/tmQueue.h new file mode 100644 index 00000000..1c680084 --- /dev/null +++ b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/module/tmQueue.h @@ -0,0 +1,186 @@ +/* ***** 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 is Mozilla Transaction Manager. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corp. + * Portions created by the Initial Developer are Copyright (C) 2003 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * John Gaunt + * + * 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 ***** */ + +#ifndef _tmQueue_H_ +#define _tmQueue_H_ + +#include "tmUtils.h" +#include "tmVector.h" + +class tmClient; +class tmTransaction; +class tmTransactionManager; + +/** + * This class isn't so much a queue as it is storage for transactions. It + * is set up to recieve and store transactions in a growing collection + * (using tmVectors). Different messages can be recieved from the + * Transaction Manager(TM) the queue belongs to which can add and remove + * listeners, empty the queue (flush), and add messages to the queue. + * + * See the documentation in tmTransactionService.h for details on the + * messages you can send to and recieve from the queues in the TM + */ +class tmQueue +{ + +public: + + //////////////////////////////////////////////////////////////////////////// + // Constructor & Destructor + + /** + * Set the internal state to default values. Init() must be called + * after construction to allocate the storage and set the name and ID. + */ + tmQueue(): mID(0), mName(nsnull), mTM(nsnull) { } + + /** + * Reclaim the memory allocated in Init(). Destroys the transactions in + * the transaction storage and the ids in the listener storage + */ + virtual ~tmQueue(); + + //////////////////////////////////////////////////////////////////////////// + // Public Member Functions + + /** + * Initialize internal storage vectors and set the name of the queue + * and the pointer to the TM container. + * + * @returns NS_OK if everything succeeds + * @returns -1 if initialization fails + */ + PRInt32 Init(const char* aName, PRUint32 aID, tmTransactionManager *aTM); + + // Queue Operations + + /** + * Adds the clientID to the list of queue listeners. A reply is created + * and sent to the client. The reply contains both the name of the + * queue and the id, so the client can match the id to the name and + * then use the id in all further communications to the queue. All + * current transactions in the queue are then sent to the client. + * + * If the client was already attached the reply is sent, but not the + * outstanding transactions, the assumption being made that all + * transactions have already been sent to the client. + * + * The reply is sent for all cases, with the return value in the status + * field. + * + * @returns >= 0 if the client was attached successfully + * @returns -1 if the client was not attached + * @returns -2 if the client was already attached + */ + PRInt32 AttachClient(PRUint32 aClientID); + + /** + * Removes the client from the list of queue listeners. A reply is created + * and sent to the client to indicate the success of the removal. + * + * The reply is sent for all cases, with the status field set to either + * -1 or NS_OK. + * + * @returns NS_OK on success + * @returns -1 if client is not attached to this queue + * @returns TM_SUCCESS_DELETE_QUEUE if there are no more listeners, + * instructing the Transaction Mangaer to delete the queue. + */ + PRInt32 DetachClient(PRUint32 aClientID); + + /** + * Removes all the transactions being held in the queue. + * A reply is created and sent to the client to indicate the + * completion of the operation. + */ + void FlushQueue(PRUint32 aClientID); + + /** + * Places the transaction passed in on the queue. Takes ownership of the + * transaction, deletes it in the destructor. A reply is created and + * sent to the client to indicate the success of the posting of the + * transaction. + * + * The reply is sent for all cases, with the status field containing the + * return value. + * + * @returns >= 0 if the message was posted properly. + * @returns -1 if the client posting is not attached to this queue, + * if the transaction has been posted to the wrong queue or + * if an error occured when trying to add the post to the + * internal storage. + */ + PRInt32 PostTransaction(tmTransaction *aTrans); + + // Accessors + + /** + * @returns the ID of the queue + */ + PRUint32 GetID() const { return mID; } + + /** + * @returns the name of the queue + */ + const char* GetName() const { return mName; } + +protected: + + /** + * Helper method to determine if the client has already attached. + * + * @returns PR_TRUE if the client is attached to the queue. + * @returns PR_FALSE if the client is not attached to the queue. + */ + PRBool IsAttached(PRUint32 aClientID); + + //////////////////////////////////////////////////////////////////////////// + // Protected Member Variables + + // storage + tmVector mTransactions; // transactions that have been posted + tmVector mListeners; // programs listening to this queue + + // bookkeeping + PRUint32 mID; // a number linked to the name in the mTM + char *mName; // format: [namespace][domainname(ie prefs)] + tmTransactionManager *mTM; // the container that holds the queue + +}; + +#endif diff --git a/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/module/tmTransactionManager.cpp b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/module/tmTransactionManager.cpp new file mode 100644 index 00000000..9d6cc98e --- /dev/null +++ b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/module/tmTransactionManager.cpp @@ -0,0 +1,162 @@ +/* ***** 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 is Mozilla Transaction Manager. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corp. + * Portions created by the Initial Developer are Copyright (C) 2003 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * John Gaunt + * + * 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 "plstr.h" +#include +#include "tmQueue.h" +#include "tmTransactionManager.h" +#include "tmTransaction.h" +#include "tmUtils.h" + +/////////////////////////////////////////////////////////////////////////////// +// Constructors & Destructor & Initializer + +tmTransactionManager::~tmTransactionManager() { + + PRUint32 size = mQueues.Size(); + tmQueue *queue = nsnull; + for (PRUint32 index = 0; index < size; index++) { + queue = (tmQueue *)mQueues[index]; + if (queue) { + delete queue; + } + } +} + +PRInt32 +tmTransactionManager::Init() { + return mQueues.Init(); +} + +/////////////////////////////////////////////////////////////////////////////// +// public transaction module methods + +void +tmTransactionManager::HandleTransaction(tmTransaction *aTrans) { + + PRUint32 action = aTrans->GetAction(); + PRUint32 ownerID = aTrans->GetOwnerID(); + tmQueue *queue = nsnull; + + // get the right queue -- attaches do it differently + if (action == TM_ATTACH) { + const char *name = (char*) aTrans->GetMessage(); // is qName for Attaches + queue = GetQueue(name); + if (!queue) { + PRInt32 index = AddQueue(name); + if (index >= 0) + queue = GetQueue(index); // GetQueue may return nsnull + } + } + else // all other trans should have a valid queue ID already + queue = GetQueue(aTrans->GetQueueID()); + + if (queue) { + // All possible actions should have a case, default is not valid + // delete trans when done with them, let the queue own the trans + // that are posted to them. + PRInt32 result = 0; + switch (action) { + case TM_ATTACH: + queue->AttachClient(ownerID); + break; + case TM_POST: + result = queue->PostTransaction(aTrans); + if (result >= 0) // post failed, aTrans cached in a tmQueue + return; + break; + case TM_FLUSH: + queue->FlushQueue(ownerID); + break; + case TM_DETACH: + if (queue->DetachClient(ownerID) == TM_SUCCESS_DELETE_QUEUE) { + // the last client has been removed, remove the queue + RemoveQueue(aTrans->GetQueueID()); // this _could_ be out of bounds + } + break; + default: + PR_NOT_REACHED("bad action in the transaction"); + } + } + delete aTrans; +} + +/////////////////////////////////////////////////////////////////////////////// +// Protected member functions + +// +// Queue Handling +// + +tmQueue* +tmTransactionManager::GetQueue(const char *aQueueName) { + + PRUint32 size = mQueues.Size(); + tmQueue *queue = nsnull; + for (PRUint32 index = 0; index < size; index++) { + queue = (tmQueue*) mQueues[index]; + if (queue && strcmp(queue->GetName(), aQueueName) == 0) + return queue; + } + return nsnull; +} + +// if successful the nsresult contains the index of the added queue +PRInt32 +tmTransactionManager::AddQueue(const char *aQueueName) { + + tmQueue* queue = new tmQueue(); + if (!queue) + return -1; + PRInt32 index = mQueues.Append(queue); + if (index < 0) + delete queue; + else + queue->Init(aQueueName, index, this); + return index; +} + +void +tmTransactionManager::RemoveQueue(PRUint32 aQueueID) { + PR_ASSERT(aQueueID <= mQueues.Size()); + + tmQueue *queue = (tmQueue*)mQueues[aQueueID]; + if (queue) { + mQueues.RemoveAt(aQueueID); + delete queue; + } +} diff --git a/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/module/tmTransactionManager.h b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/module/tmTransactionManager.h new file mode 100644 index 00000000..a03ba528 --- /dev/null +++ b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/module/tmTransactionManager.h @@ -0,0 +1,147 @@ +/* ***** 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 is Mozilla Transaction Manager. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corp. + * Portions created by the Initial Developer are Copyright (C) 2003 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * John Gaunt + * + * 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 ***** */ + +#ifndef _tmTransactionManager_H_ +#define _tmTransactionManager_H_ + +#include "plhash.h" +#include "tmUtils.h" +#include "tmVector.h" +#include "tmIPCModule.h" + +// forward declarations +class tmQueue; +class tmClient; +class tmTransaction; + +/** + * This class manages the flow of messages from the IPC daemon (coming to + * it through the tmIPCModule) that ultimately come from a Transaction + * Service (TS) in a mozilla based client somewhere. The message is + * delivered to the proper queue, where it is dealt with. + * + * New queues get created here as clients request them. + */ +class tmTransactionManager +{ + +public: + + //////////////////////////////////////////////////////////////////////////// + // Constructor(s) & Destructor & Initializer + + /** + * reclaim the memory allcoated during initialization + */ + virtual ~tmTransactionManager(); + + /** + * Set up the storage of the queues - initialize the vector + * + * @returns NS_OK if successful + * @returns -1 if initialization fails + */ + PRInt32 Init(); + + //////////////////////////////////////////////////////////////////////////// + // Public Member Functions + + /** + * Called from the tmIPCModule. Decide where to send the message and + * dispatch it. + */ + void HandleTransaction(tmTransaction *aTrans); + + /** + * Called by the queues when they need to get a message back out to a + * client. + */ + void SendTransaction(PRUint32 aDestClientIPCID, tmTransaction *aTrans) { + PR_ASSERT(aTrans); + tmIPCModule::SendMsg(aDestClientIPCID, aTrans); + } + +protected: + + //////////////////////////////////////////////////////////////////////////// + // Protected Member Functions + + // Queue management + + /** + * @returns the queue indexed by the ID passed in, which could be nsnull + */ + tmQueue* GetQueue(PRUint32 aQueueID) { + return (tmQueue*) mQueues[aQueueID]; + } + + /** + * @returns the queue with the name passed in + * @returns nsnull if there is no queue with that name + */ + tmQueue* GetQueue(const char *aQueueName); + + /** + * If all is successful a new queue with the name provided will be created, + * and added to the collection of queues. It will be initialized and ready + * to have transactions added. + * + * This doesn't check for the existance of a queue with this name. IF + * there is already a queue with this name then you will + * get that when using GetQueue(qName) and never get the new queue + * created here. A call to GetQueue(qID) will be able to get at the new + * queue, however you had better cache the ID. + * + * @returns -1 if the queue can't be created, or is not added + * @returns >= 0 if the queue was added successfully + */ + PRInt32 AddQueue(const char *aQueueType); + + /** + */ + void RemoveQueue(PRUint32 aQueueID); + + //////////////////////////////////////////////////////////////////////////// + // Protected Member Variables + + tmVector mQueues; + +private: + +}; + +#endif diff --git a/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/public/.cvsignore b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/public/.cvsignore new file mode 100644 index 00000000..f3c7a7c5 --- /dev/null +++ b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/public/.cvsignore @@ -0,0 +1 @@ +Makefile diff --git a/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/public/Makefile.in b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/public/Makefile.in new file mode 100644 index 00000000..65b126e9 --- /dev/null +++ b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/public/Makefile.in @@ -0,0 +1,53 @@ +# ***** 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 is Mozilla Transaction Manager. +# +# The Initial Developer of the Original Code is +# Netscape Communications Corp. +# Portions created by the Initial Developer are Copyright (C) 2003 +# the Initial Developer. All Rights Reserved. +# +# Contributor(s): +# John Gaunt +# +# 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 ***** + +DEPTH = ../../../../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +MODULE = ipcd +XPIDL_MODULE = ipcd_transmngr + +XPIDLSRCS = \ + ipcITransactionService.idl \ + ipcITransactionObserver.idl \ + $(NULL) + +include $(topsrcdir)/config/rules.mk diff --git a/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/public/ipcITransactionObserver.idl b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/public/ipcITransactionObserver.idl new file mode 100644 index 00000000..c7df965d --- /dev/null +++ b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/public/ipcITransactionObserver.idl @@ -0,0 +1,100 @@ +/* ***** 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 is Mozilla Transaction Manager. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corp. + * Portions created by the Initial Developer are Copyright (C) 2003 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * John Gaunt + * + * 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 "nsISupports.idl" + +[scriptable, uuid(656c0a6a-5cb3-45ec-8cb6-e7678897f937)] +interface ipcITransactionObserver : nsISupports +{ + /** + * This gets called when a Transaction has been sent from the + * TransactionManager. If the data passed in needs to be stored + * for longer than the life of the method the observer needs + * to make a copy. + * + * @param aQueueID + * The queue from which the transaction originated + * + * @param aData + * The data to be sent. + * + * @param aDataLen + * The length of the data argument + */ + void onTransactionAvailable(in unsigned long aQueueID, + [array, const, size_is(aDataLen)] + in octet aData, + in unsigned long aDataLen); + + /** + * Called after an application sends an Attach message to the + * Transaction Manager. + * + * @param aQueueID + * The client has been attached to the queue with this ID + * + * @param aStatus + * The status of the operation, as defined in tmUtils.h + */ + void onAttachReply(in unsigned long aQueueID, in unsigned long aStatus); + + /** + * Called after an application sends a Detach message. Indicates + * to the client that no more messages will be coming from the + * the TM to this client. Also, no messages posted from this + * client to the indicated queue will be accepted. + * + * @param aQueueID + * The client has been detached from the queue with this ID + * + * @param aStatus + * The status of the operation, as defined in tmUtils.h + */ + void onDetachReply(in unsigned long aQueueID, in unsigned long aStatus); + + /** + * The reply from the TM indicating all messages have been removed + * from the queue indicated. + * + * @param aQueueID + * The queue that has been flushed. + * + * @param aStatus + * The status of the operation, as defined in tmUtils.h + */ + void onFlushReply(in unsigned long aQueueID, in unsigned long aStatus); +}; diff --git a/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/public/ipcITransactionService.idl b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/public/ipcITransactionService.idl new file mode 100644 index 00000000..0bcbc453 --- /dev/null +++ b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/public/ipcITransactionService.idl @@ -0,0 +1,239 @@ +/* ***** 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 is Mozilla Transaction Manager. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corp. + * Portions created by the Initial Developer are Copyright (C) 2003 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * John Gaunt + * + * 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 ***** */ + +// from tmTransactionManager.h +// +// XXX documentation needs work +////////////////////////////////////////////////////////////////////////////// +// Overview of TransactionManager IPC Module +// +// Classes: +// tmIPCModule - From the tmTransactionManager's point of view, this +// is a proxy for the IPC daemon itself. The reverse is true +// from the daemon's point of view. This is an interface for the +// Transaction system to work with the IPC daemon as its transport +// layer. +// tmTransactionManager (TM) - Manages the different queues. Maintains +// the queues neccessary for different clients. Receives messages +// from the tmIPCModule and passes message to the IPC daemon through +// the tmIPCModule. +// tmQueue - this class manages the transactions for the different areas +// of the profiles being shared. Broken down by functional area there +// will be a queue for prefs, cookies etc, but not for profileA and +// profileB, and not for pref_delete, pref_create, pref_change etc... +// tmTransaction - the actual transaction being shared with the different +// tmClients. It contains the type of transaction, which will equate with +// a type of queue in existance, the owner of the transaction (an IPC daemon ID) +// and the actual text message to be shared. +// +////////////////////////////////////////////////////////////////////////////// + +/// XXX some docs that need to be put somewhere: +// +// from tmqueue.cpp +// Docs - note that the status of the TM_ATTACH_REPLY is only for checking +// for TM_ERROR_FAILURE. Other numbers have no importance +// success of the status means the NS_ERROR_GET_CODE(status) will +// yield the index of the listener. +// +// move to documentation page - from tmqueue.h +// +// a queue is specific to profile +// +// UUID going out from the module is a handler in the client +// (will go to the XPCOM service impling that UUID) +// -- does it make sense to have different UUIDs for cookies/prefs/etc +// + +#include "nsISupports.idl" + +interface ipcITransactionObserver; + +[scriptable, uuid(15561efb-8c58-4a47-813a-fa91cf730895)] +interface ipcITransactionService : nsISupports +{ + /** + * Connects the application to the transaction manager, defines the + * namespace and initializes internal storage + * + * @param aNamespace + * A string defining the scope of the transaction domains. It is + * used internally to seperate process listening to the same domain + * (ie. preferences) but for two different namespaces (ie. profile1 vs + * profile2). + * + * @returns NS_OK if all memory allocated properly and the IPC service was + * reached and attached to successfully. + * + * @returns an NS_ERROR_ code specific to the failure otherwise + */ + void init(in ACString aNamespace); + + /** + * Links the observer passed in with the domain specified. This will allow + * the observer to post transactions dealing with this domain as well as + * receive transactions posted by other applications observing this + * domain. + * + * Return codes for this method confer information about the success of + * this call, not of the actual attaching of the observer to the domain. + * (except the TM_ERROR code - which means the observer can not attach) + * If the attach is successful the observer will have its OnAttachReply + * method called before this method returns. + * + * Note: This call is synchronous and will not return until the call to + * OnAttachReply is made. + * + * @param aDomainName + * the name of the domain, in the current namespace, to listen for + * transactions from. i.e. cookies + * + * @param aObserver + * this will be used to notify the application when transactions + * and messages come in. + * + * @param aLockingCall + * Have the Transaction Sevice acquire a lock based on the domain + * before attaching. This should be used when persistant storage + * is being used to prevent data corruption. + * + * @returns NS_OK if the attach message was sent to the Transaction Manager. + * + * @returns an NS_ERROR_ code specific to the failure otherwise + * + * @returns TM_ERROR_QUEUE_EXISTS if the queue already exists which means + * someone has already attached to it. + */ + void attach(in ACString aDomainName, + in ipcITransactionObserver aObserver, + in PRBool aLockingCall); + + /** + * Sends a detach message to the Transaction Manager to unlink the observer + * associated with the domain passed in. + * + * As in attach, return codes do not indicate success of detachment. The + * observer will have it's OnDetach method called if it is successfully + * detached. + * + * Note: This call is an asynchronous call. + * + * @param aDomainName + * the domain, in the current namespace, from which the client + * should be removed. + * + * @returns NS_OK if the detach message is sent to the Transaction Manager + * + * @returns NS_ERROR_FAILURE is something goes wrong + * + * @returns NS_ERRROR_UNEXPECTD if the domain does not have an observer + * attached + */ + void detach(in ACString aDomainName); + + /** + * Sends a flush message to the Transaction Manager to remove all + * transactions for the domain. After this call there will be no + * transactions in the Transaction Manager for the namespace/domain + * pairing. It is up to the application to coordinate the flushing + * of the Transaction Manager with the writing of data to files, + * if needed. + * + * Note: This call is synchronous and will not return until the call to + * OnFlushReply is made. + * + * @param aDomainName + * The domain, in the current namespace, to flush. + * + * @param aLockingCall + * Have the Transaction Sevice acquire a lock based on the domain + * before flushing. This should be used when persistant storage + * is being used to prevent data corruption. + * + * @returns NS_OK if the flush message is sent to the Transaction Manager + * + * @returns NS_ERROR_FAILURE is something goes wrong + * + * @returns NS_ERRROR_UNEXPECTD if the domain does not have an observer + * attached + */ + void flush(in ACString aDomainName, in PRBool aLockingCall); + + /** + * Send the data to the Transaction Manager to be broadcast to any + * applications that have registered as observers of this particular + * namespace/domain pairing. + * + * If this domain is not being observed (attach has not been called for + * this domain) the message is queued until the attach is made and then + * the message is sent to the Transaction Manager with the proper domain + * information. + * + * XXXjg - this may not be neccessary with the synch attach call. + * + * Note: This call is an asynchronous call. + * + * @param aDomainName + * the domain, in the current namespace, to which the data will be + * sent. + * + * @param aData + * The actual data to be sent. + * + * @param aDataLen + * The length of the data argument + */ + void postTransaction(in ACString aDomainName, + [array, const, size_is(aDataLen)] + in octet aData, + in unsigned long aDataLen); +}; + +%{C++ +// singleton implementing ipcITransactionService +#define IPC_TRANSACTIONSERVICE_CLASSNAME \ + "tmTransactionService" +#define IPC_TRANSACTIONSERVICE_CONTRACTID \ + "@mozilla.org/ipc/transaction-service;1" +#define IPC_TRANSACTIONSERVICE_CID \ +{ /* 1403adf4-94d1-4c67-a8ae-d9f86972d378 */ \ + 0x1403adf4, \ + 0x94d1, \ + 0x4c67, \ + {0xa8, 0xae, 0xd9, 0xf8, 0x69, 0x72, 0xd3, 0x78} \ +} +%} diff --git a/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/src/.cvsignore b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/src/.cvsignore new file mode 100644 index 00000000..7726b497 --- /dev/null +++ b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/src/.cvsignore @@ -0,0 +1,4 @@ +Makefile +tmTransactionService.obj +transmgr_s.lib +transmgr_s.pdb \ No newline at end of file diff --git a/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/src/Makefile.in b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/src/Makefile.in new file mode 100644 index 00000000..6510e489 --- /dev/null +++ b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/src/Makefile.in @@ -0,0 +1,64 @@ +# ***** 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 is Mozilla Transaction Manager. +# +# The Initial Developer of the Original Code is +# Netscape Communications Corp. +# Portions created by the Initial Developer are Copyright (C) 2003 +# the Initial Developer. All Rights Reserved. +# +# Contributor(s): +# John Gaunt +# +# 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 ***** + +DEPTH = ../../../../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +MODULE = ipcd +LIBRARY_NAME = transmgr_s +FORCE_STATIC_LIB = 1 +MODULE_NAME = ipcd + +REQUIRES = string \ + xpcom \ + $(NULL) + +CPPSRCS = \ + tmTransactionService.cpp \ + $(NULL) + +include $(topsrcdir)/config/config.mk + +LOCAL_INCLUDES = \ + -I$(srcdir)/../common \ + $(NULL) + +include $(topsrcdir)/config/rules.mk diff --git a/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/src/tmTransactionService.cpp b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/src/tmTransactionService.cpp new file mode 100644 index 00000000..e53d6aa7 --- /dev/null +++ b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/src/tmTransactionService.cpp @@ -0,0 +1,504 @@ +/* ***** 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 is Mozilla Transaction Manager. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corp. + * Portions created by the Initial Developer are Copyright (C) 2003 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * John Gaunt + * + * 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 "nsCOMPtr.h" +#include "nsIServiceManager.h" +#include "nsReadableUtils.h" +#include "plstr.h" +#include "ipcITransactionObserver.h" +#include "tmTransaction.h" +#include "tmTransactionService.h" +#include "tmUtils.h" + +static const nsID kTransModuleID = TRANSACTION_MODULE_ID; + +struct tm_waiting_msg { + tmTransaction trans; // a transaction waiting to be sent to a queue + char* domainName; // the short queue name + + ~tm_waiting_msg(); +}; + +tm_waiting_msg::~tm_waiting_msg() { + if (domainName) + PL_strfree(domainName); +} + +struct tm_queue_mapping { + PRInt32 queueID; // the ID in the TM + char* domainName; // used by the consumers of this service + char* joinedQueueName; // used by the service -- namespace + domain name + + ~tm_queue_mapping(); +}; + +tm_queue_mapping::~tm_queue_mapping() { + if (domainName) + PL_strfree(domainName); + if (joinedQueueName) + PL_strfree(joinedQueueName); +} + +////////////////////////////////////////////////////////////////////////////// +// Constructor and Destructor + +tmTransactionService::~tmTransactionService() { + + // just destroy this, it contains 2 pointers it doesn't own. + if (mObservers) + PL_HashTableDestroy(mObservers); + + PRUint32 index = 0; + PRUint32 size = mWaitingMessages.Size(); + tm_waiting_msg *msg = nsnull; + for ( ; index < size; index ++) { + msg = (tm_waiting_msg*) mWaitingMessages[index]; + delete msg; + } + + size = mQueueMaps.Size(); + tm_queue_mapping *qmap = nsnull; + for (index = 0; index < size; index++) { + qmap = (tm_queue_mapping*) mQueueMaps[index]; + if (qmap) + delete qmap; + } +} + +////////////////////////////////////////////////////////////////////////////// +// ISupports + +NS_IMPL_ISUPPORTS2(tmTransactionService, + ipcITransactionService, + ipcIMessageObserver) + +////////////////////////////////////////////////////////////////////////////// +// ipcITransactionService + +NS_IMETHODIMP +tmTransactionService::Init(const nsACString & aNamespace) { + + nsresult rv; + + rv = IPC_DefineTarget(kTransModuleID, this, PR_TRUE); + if (NS_FAILED(rv)) + return rv; + + // get the lock service + lockService = do_GetService("@mozilla.org/ipc/lock-service;1"); + if (!lockService) + return NS_ERROR_FAILURE; + + // create some internal storage + mObservers = PL_NewHashTable(20, + PL_HashString, + PL_CompareStrings, + PL_CompareValues, 0, 0); + if (!mObservers) + return NS_ERROR_FAILURE; + + // init some internal storage + mQueueMaps.Init(); + mWaitingMessages.Init(); + + // store the namespace + mNamespace.Assign(aNamespace); + return NS_OK; +} + +NS_IMETHODIMP +tmTransactionService::Attach(const nsACString & aDomainName, + ipcITransactionObserver *aObserver, + PRBool aLockingCall) { + + // if the queue already exists, then someone else is attached to it. must + // return an error here. Only one module attached to a queue per app. + if (GetQueueID(aDomainName) != TM_NO_ID) + return TM_ERROR_QUEUE_EXISTS; + + // create the full queue name: namespace + queue + nsCString jQName; + jQName.Assign(mNamespace); + jQName.Append(aDomainName); + + // this char* has two homes, make sure it gets PL_free()ed properly + char* joinedQueueName = ToNewCString(jQName); + if (!joinedQueueName) + return NS_ERROR_OUT_OF_MEMORY; + + // link the observer to the joinedqueuename. home #1 for joinedQueueName + // these currently don't get removed until the destructor on this is called. + PL_HashTableAdd(mObservers, joinedQueueName, aObserver); + + // store the domainName and JoinedQueueName, create a place to store the ID + tm_queue_mapping *qm = new tm_queue_mapping(); + if (!qm) + return NS_ERROR_OUT_OF_MEMORY; + qm->queueID = TM_NO_ID; // initially no ID for the queue + qm->joinedQueueName = joinedQueueName; // home #2, owner of joinedQueueName + qm->domainName = ToNewCString(aDomainName); + if (!qm->domainName) { + PL_HashTableRemove(mObservers, joinedQueueName); + delete qm; + return NS_ERROR_OUT_OF_MEMORY; + } + mQueueMaps.Append(qm); + + nsresult rv = NS_ERROR_FAILURE; + tmTransaction trans; + + // acquire a lock if neccessary + if (aLockingCall) + lockService->AcquireLock(joinedQueueName, PR_TRUE); + // XXX need to handle lock failures + + if (NS_SUCCEEDED(trans.Init(0, // no IPC client + TM_NO_ID, // qID gets returned to us + TM_ATTACH, // action + NS_OK, // default status + (PRUint8 *)joinedQueueName, // qName gets copied + PL_strlen(joinedQueueName)+1))) { // message length + // send the attach msg + SendMessage(&trans, PR_TRUE); // synchronous + rv = NS_OK; + } + + // drop the lock if neccessary + if (aLockingCall) + lockService->ReleaseLock(joinedQueueName); + + return rv; +} + +// actual removal of the observer takes place when we get the detach reply +NS_IMETHODIMP +tmTransactionService::Detach(const nsACString & aDomainName) { + + // asynchronous detach + return SendDetachOrFlush(GetQueueID(aDomainName), TM_DETACH, PR_FALSE); + +} + +NS_IMETHODIMP +tmTransactionService::Flush(const nsACString & aDomainName, + PRBool aLockingCall) { + // acquire a lock if neccessary + if (aLockingCall) + lockService->AcquireLock(GetJoinedQueueName(aDomainName), PR_TRUE); + + // synchronous flush + nsresult rv = SendDetachOrFlush(GetQueueID(aDomainName), TM_FLUSH, PR_TRUE); + + // drop the lock if neccessary + if (aLockingCall) + lockService->ReleaseLock(GetJoinedQueueName(aDomainName)); + + return rv; + +} + +NS_IMETHODIMP +tmTransactionService::PostTransaction(const nsACString & aDomainName, + const PRUint8 *aData, + PRUint32 aDataLen) { + + tmTransaction trans; + if (NS_SUCCEEDED(trans.Init(0, // no IPC client + GetQueueID(aDomainName), // qID returned to us + TM_POST, // action + NS_OK, // default status + aData, // message data + aDataLen))) { // message length + if (trans.GetQueueID() == TM_NO_ID) { + // stack it and pack it + tm_waiting_msg *msg = new tm_waiting_msg(); + if (!msg) + return NS_ERROR_OUT_OF_MEMORY; + msg->trans = trans; + msg->domainName = ToNewCString(aDomainName); + if (!msg->domainName) { + delete msg; + return NS_ERROR_OUT_OF_MEMORY; + } + mWaitingMessages.Append(msg); + } + else { + // send it + SendMessage(&trans, PR_FALSE); + } + return NS_OK; + } + return NS_ERROR_FAILURE; +} + +////////////////////////////////////////////////////////////////////////////// +// ipcIMessageObserver + +NS_IMETHODIMP +tmTransactionService::OnMessageAvailable(const PRUint32 aSenderID, + const nsID & aTarget, + const PRUint8 *aData, + PRUint32 aDataLength) { + + nsresult rv = NS_ERROR_OUT_OF_MEMORY; // prime the return value + + tmTransaction *trans = new tmTransaction(); + if (trans) { + rv = trans->Init(0, // no IPC client ID + TM_INVALID_ID, // in aData + TM_INVALID_ID, // in aData + TM_INVALID_ID, // in aData + aData, // message data + aDataLength); // message length + + if (NS_SUCCEEDED(rv)) { + switch(trans->GetAction()) { + case TM_ATTACH_REPLY: + OnAttachReply(trans); + break; + case TM_POST_REPLY: + // OnPostReply() would be called here + // isn't neccessary at the current time 2/19/03 + break; + case TM_DETACH_REPLY: + OnDetachReply(trans); + break; + case TM_FLUSH_REPLY: + OnFlushReply(trans); + break; + case TM_POST: + OnPost(trans); + break; + default: // error, should not happen + NS_NOTREACHED("Recieved a TM reply outside of mapped messages"); + break; + } + } + delete trans; + } + return rv; +} + +////////////////////////////////////////////////////////////////////////////// +// Protected Member Functions + +void +tmTransactionService::SendMessage(tmTransaction *aTrans, PRBool aSync) { + + NS_ASSERTION(aTrans, "tmTransactionService::SendMessage called with null transaction"); + + IPC_SendMessage(0, kTransModuleID, + aTrans->GetRawMessage(), + aTrans->GetRawMessageLength()); + if (aSync) + IPC_WaitMessage(0, kTransModuleID, nsnull, nsnull, PR_INTERVAL_NO_TIMEOUT); +} + +void +tmTransactionService::OnAttachReply(tmTransaction *aTrans) { + + // if we attached, store the queue's ID + if (aTrans->GetStatus() >= 0) { + + PRUint32 size = mQueueMaps.Size(); + tm_queue_mapping *qmap = nsnull; + for (PRUint32 index = 0; index < size; index++) { + qmap = (tm_queue_mapping*) mQueueMaps[index]; + if (qmap && + PL_strcmp(qmap->joinedQueueName, (char*) aTrans->GetMessage()) == 0) { + + // set the ID in the mapping + qmap->queueID = aTrans->GetQueueID(); + // send any stored messges to the queue + DispatchStoredMessages(qmap); + } + } + } + + // notify the observer we have attached (or didn't) + ipcITransactionObserver *observer = + (ipcITransactionObserver *)PL_HashTableLookup(mObservers, + (char*)aTrans->GetMessage()); + if (observer) + observer->OnAttachReply(aTrans->GetQueueID(), aTrans->GetStatus()); +} + +void +tmTransactionService::OnDetachReply(tmTransaction *aTrans) { + + tm_queue_mapping *qmap = GetQueueMap(aTrans->GetQueueID()); + + // get the observer before we release the hashtable entry + ipcITransactionObserver *observer = + (ipcITransactionObserver *)PL_HashTableLookup(mObservers, + qmap->joinedQueueName); + + // if it was removed, clean up + if (aTrans->GetStatus() >= 0) { + + // remove the link between observer and queue + PL_HashTableRemove(mObservers, qmap->joinedQueueName); + + // remove the mapping of queue names and id + mQueueMaps.Remove(qmap); + delete qmap; + } + + + // notify the observer -- could be didn't detach + if (observer) + observer->OnDetachReply(aTrans->GetQueueID(), aTrans->GetStatus()); +} + +void +tmTransactionService::OnFlushReply(tmTransaction *aTrans) { + + ipcITransactionObserver *observer = + (ipcITransactionObserver *)PL_HashTableLookup(mObservers, + GetJoinedQueueName(aTrans->GetQueueID())); + if (observer) + observer->OnFlushReply(aTrans->GetQueueID(), aTrans->GetStatus()); +} + +void +tmTransactionService::OnPost(tmTransaction *aTrans) { + + ipcITransactionObserver *observer = + (ipcITransactionObserver*) PL_HashTableLookup(mObservers, + GetJoinedQueueName(aTrans->GetQueueID())); + if (observer) + observer->OnTransactionAvailable(aTrans->GetQueueID(), + aTrans->GetMessage(), + aTrans->GetMessageLength()); +} + +void +tmTransactionService::DispatchStoredMessages(tm_queue_mapping *aQMapping) { + + PRUint32 size = mWaitingMessages.Size(); + tm_waiting_msg *msg = nsnull; + for (PRUint32 index = 0; index < size; index ++) { + msg = (tm_waiting_msg*) mWaitingMessages[index]; + // if the message is waiting on the queue passed in + if (msg && strcmp(aQMapping->domainName, msg->domainName) == 0) { + + // found a match, send it and remove + msg->trans.SetQueueID(aQMapping->queueID); + SendMessage(&(msg->trans), PR_FALSE); + + // clean up + mWaitingMessages.Remove(msg); + delete msg; + } + } +} + +// searches against the short queue name +PRInt32 +tmTransactionService::GetQueueID(const nsACString & aDomainName) { + + PRUint32 size = mQueueMaps.Size(); + tm_queue_mapping *qmap = nsnull; + for (PRUint32 index = 0; index < size; index++) { + qmap = (tm_queue_mapping*) mQueueMaps[index]; + if (qmap && aDomainName.Equals(qmap->domainName)) + return qmap->queueID; + } + return TM_NO_ID; +} + +char* +tmTransactionService::GetJoinedQueueName(PRUint32 aQueueID) { + + PRUint32 size = mQueueMaps.Size(); + tm_queue_mapping *qmap = nsnull; + for (PRUint32 index = 0; index < size; index++) { + qmap = (tm_queue_mapping*) mQueueMaps[index]; + if (qmap && qmap->queueID == aQueueID) + return qmap->joinedQueueName; + } + return nsnull; +} + +char* +tmTransactionService::GetJoinedQueueName(const nsACString & aDomainName) { + + PRUint32 size = mQueueMaps.Size(); + tm_queue_mapping *qmap = nsnull; + for (PRUint32 index = 0; index < size; index++) { + qmap = (tm_queue_mapping*) mQueueMaps[index]; + if (qmap && aDomainName.Equals(qmap->domainName)) + return qmap->joinedQueueName; + } + return nsnull; +} + +tm_queue_mapping* +tmTransactionService::GetQueueMap(PRUint32 aQueueID) { + + PRUint32 size = mQueueMaps.Size(); + tm_queue_mapping *qmap = nsnull; + for (PRUint32 index = 0; index < size; index++) { + qmap = (tm_queue_mapping*) mQueueMaps[index]; + if (qmap && qmap->queueID == aQueueID) + return qmap; + } + return nsnull; +} + +nsresult +tmTransactionService::SendDetachOrFlush(PRUint32 aQueueID, + PRUint32 aAction, + PRBool aSync) { + + // if the queue isn't attached to, just return + if (aQueueID == TM_NO_ID) + return NS_ERROR_UNEXPECTED; + + tmTransaction trans; + if (NS_SUCCEEDED(trans.Init(0, // no IPC client + aQueueID, // qID to detach from + aAction, // action + NS_OK, // default status + nsnull, // no message + 0))) { // no message + // send it + SendMessage(&trans, aSync); + return NS_OK; + } + return NS_ERROR_FAILURE; +} diff --git a/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/src/tmTransactionService.h b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/src/tmTransactionService.h new file mode 100644 index 00000000..cd9310fe --- /dev/null +++ b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/src/tmTransactionService.h @@ -0,0 +1,196 @@ +/* ***** 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 is Mozilla Transaction Manager. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corp. + * Portions created by the Initial Developer are Copyright (C) 2003 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * John Gaunt + * + * 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 ***** */ + +#ifndef _tmTransactionService_H_ +#define _tmTransactionService_H_ + +#include "ipcdclient.h" +#include "ipcILockService.h" +#include "ipcIMessageObserver.h" +#include "ipcITransactionService.h" +#include "nsString.h" +#include "nsVoidArray.h" +#include "plhash.h" +#include "tmTransaction.h" +#include "tmVector.h" + +struct tm_queue_mapping; + +/** + * The tmTransactionService shares packets of information + * (transactions) with other Gecko based applications interested in the same + * namespace and domain. An application registers with the Transaction Service + * for a particular namespace and domain and then can post transactions to the + * service and receive transactions from the service. + * + * For applications using the Transaction Service to share changes in state that + * get reflected in files on disk there are certain pattersn to follow to ensure + * data loss does not occur. + * + * Startup: XXX docs needed + * + * Shutdown/writing to disk: XXX docs needed + * + * + */ +class tmTransactionService : public ipcITransactionService, + public ipcIMessageObserver +{ + +public: + + //////////////////////////////////////////////////////////////////////////// + // Constructor & Destructor + tmTransactionService() : mObservers(0) {}; + + /** + * Reclaim all the memory allocated: PL_hashtable, tmVectors + */ + virtual ~tmTransactionService(); + + //////////////////////////////////////////////////////////////////////////// + // Interface Declarations + + // for API docs, see the respective *.idl files + NS_DECL_ISUPPORTS + NS_DECL_IPCITRANSACTIONSERVICE + NS_DECL_IPCIMESSAGEOBSERVER + +protected: + + //////////////////////////////////////////////////////////////////////////// + // Protected Member Functions + + /** + * Pulls the raw message out of the transaction and sends it to the IPC + * service to be delivered to the TM. + * + * @param aTrans + * The transaction to send to the TM + * + * @param aSync + * If TRUE, calling thread will be blocked until a reply is + * received. + */ + void SendMessage(tmTransaction *aTrans, PRBool aSync); + + // handlers for reply messages from TransactionManager + + /** + * Pulls the queueID out of the ATTACH_REPLY message and stores it in the + * proper tm_queue_mapping object. Calls DispatchStoredMessages() to make + * sure we send any messages that have been waiting on the ATTACH_REPLY. + * Also calls the OnAttachReply() method for the observer of the queue. + */ + void OnAttachReply(tmTransaction *aTrans); + + /** + * Removes the tm_queue_mapping object and calls the OnDetachReply() method + * on the observer of the queue detached. + */ + void OnDetachReply(tmTransaction *aTrans); + + /** + * Calls the OnFlushReply method of the observer of the queue. + */ + void OnFlushReply(tmTransaction *aTrans); + + /** + * Calls the OnPost method of the observer of the queue. + */ + void OnPost(tmTransaction *aTrans); + + // other helper functions + + /** + * Cycle through the collection of transactions waiting to go out and + * send any that are waiting on an ATTACH_REPLY from the queue + * specified by the tm_queue_mapping passed in. + */ + void DispatchStoredMessages(tm_queue_mapping *aQMapping); + + // helper methods for accessing the void arrays + + /** + * @returns the ID corresponding to the domain name passed in + * @returns TM_NO_ID if the name is not found. + */ + PRInt32 GetQueueID(const nsACString & aDomainName); + + /** + * @returns the joined queue name - namespace + domain + * (prefs, cookies etc) corresponding to the ID passed in. + * @returns nsnull if the ID is not found. + */ + char* GetJoinedQueueName(PRUint32 aQueueID); + + /** + * @returns the joined queue name - namespace + domain + * (prefs, cookies etc) corresponding to the ID passed in. + * @returns nsnull if the ID is not found. + */ + char* GetJoinedQueueName(const nsACString & aDomainName); + + /** + * @returns the tm_queue_mapping object that contains the ID passed in. + * @returns nsnull if the ID is not found. + */ + tm_queue_mapping* GetQueueMap(PRUint32 aQueueID); + + /** + * Helper method for Detach and Flush requests. + */ + nsresult SendDetachOrFlush(PRUint32 aQueueID, + PRUint32 aAction, + PRBool aSync); + + //////////////////////////////////////////////////////////////////////////// + // Protected Member Variables + + nsCString mNamespace; // limit domains to the namespace + PLHashTable *mObservers; // maps qName -> ipcITransactionObserver + + tmVector mQueueMaps; // queue - name - domain mappings + tmVector mWaitingMessages; // messages sent before ATTACH_REPLY + + nsCOMPtr lockService; // cache the lock service + +private: + +}; + +#endif diff --git a/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/test/.cvsignore b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/test/.cvsignore new file mode 100644 index 00000000..e3c610be --- /dev/null +++ b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/test/.cvsignore @@ -0,0 +1,6 @@ +Makefile +tmModuleTest.exe +tmModuleTest.ilk +tmModuleTest.pdb +tmModuleTest.obj +tmModuleTest diff --git a/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/test/Makefile.in b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/test/Makefile.in new file mode 100644 index 00000000..385751a3 --- /dev/null +++ b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/test/Makefile.in @@ -0,0 +1,68 @@ +# ***** 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 is Mozilla Transaction Manager. +# +# The Initial Developer of the Original Code is +# Netscape Communications Corp. +# Portions created by the Initial Developer are Copyright (C) 2003 +# the Initial Developer. All Rights Reserved. +# +# Contributor(s): +# John Gaunt +# +# 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 ***** + +DEPTH = ../../../../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +MODULE = tm_test + +REQUIRES = ipcd \ + nspr \ + string \ + xpcom \ + $(NULL) + +CPPSRCS = \ + tmModuleTest.cpp \ + $(NULL) + +SIMPLE_PROGRAMS = $(CPPSRCS:.cpp=$(BIN_SUFFIX)) + +include $(topsrcdir)/config/config.mk + +LIBS = \ + $(EXTRA_DSO_LIBS) \ + $(XPCOM_LIBS) \ + $(NSPR_LIBS) \ + $(NULL) + +include $(topsrcdir)/config/rules.mk + diff --git a/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/test/tmModuleTest.cpp b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/test/tmModuleTest.cpp new file mode 100644 index 00000000..5d1dccd4 --- /dev/null +++ b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/test/tmModuleTest.cpp @@ -0,0 +1,323 @@ +/* ***** 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 is Mozilla Transaction Manager. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corp. + * Portions created by the Initial Developer are Copyright (C) 2003 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * John Gaunt + * + * 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 ***** */ + +// transaction manager includes +#include "ipcITransactionService.h" +#include "ipcITransactionObserver.h" + +// ipc daemon includes +#include "ipcIService.h" + +// core & xpcom ns includes +#include "nsDebug.h" +#include "nsIEventQueueService.h" +#include "nsIServiceManager.h" +#include "nsIComponentRegistrar.h" +#include "nsString.h" + +// nspr includes +#include "prmem.h" +#include "plgetopt.h" +#include "nspr.h" +#include "prlog.h" + +////////////////////////////////////////////////////////////////////////////// +// Testing/Debug/Logging BEGIN + +const int NameSize = 1024; + +/* command line options */ +PRIntn optDebug = 0; +char optMode = 's'; +char *profileName = new char[NameSize]; +char *queueName = new char[NameSize]; + +char *data = new char[NameSize]; +PRUint32 dataLen = 10; // includes the null terminator for "test data" + +// Testing/Debug/Logging END +////////////////////////////////////////////////////////////////////////////// + +#define RETURN_IF_FAILED(rv, step) \ + PR_BEGIN_MACRO \ + if (NS_FAILED(rv)) { \ + printf("*** %s failed: rv=%x\n", step, rv); \ + return rv;\ + } \ + PR_END_MACRO + +static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID); +static nsIEventQueue* gEventQ = nsnull; +static PRBool gKeepRunning = PR_TRUE; +//static PRInt32 gMsgCount = 0; +static ipcIService *gIpcServ = nsnull; +static ipcITransactionService *gTransServ = nsnull; + +//----------------------------------------------------------------------------- + +class myTransactionObserver : public ipcITransactionObserver +{ +public: + NS_DECL_ISUPPORTS + NS_DECL_IPCITRANSACTIONOBSERVER + + myTransactionObserver() { } +}; + +NS_IMPL_ISUPPORTS1(myTransactionObserver, ipcITransactionObserver) + +NS_IMETHODIMP myTransactionObserver::OnTransactionAvailable(PRUint32 aQueueID, const PRUint8 *aData, PRUint32 aDataLen) +{ + printf("tmModuleTest: myTransactionObserver::OnTransactionAvailable [%s]\n", aData); + return NS_OK; +} + +NS_IMETHODIMP myTransactionObserver::OnAttachReply(PRUint32 aQueueID, PRUint32 aStatus) +{ + printf("tmModuleTest: myTransactionObserver::OnAttachReply [%d]\n", aStatus); + return NS_OK; +} + +NS_IMETHODIMP myTransactionObserver::OnDetachReply(PRUint32 aQueueID, PRUint32 aStatus) +{ + printf("tmModuleTest: myTransactionObserver::OnDetachReply [%d]\n", aStatus); + return NS_OK; +} + +NS_IMETHODIMP myTransactionObserver::OnFlushReply(PRUint32 aQueueID, PRUint32 aStatus) +{ + printf("tmModuleTest: myTransactionObserver::OnFlushReply [%d]\n", aStatus); + return NS_OK; +} + + +//----------------------------------------------------------------------------- + +int main(PRInt32 argc, char *argv[]) +{ + nsresult rv; + + // default string values + strcpy(profileName, "defaultProfile"); + strcpy(queueName, "defaultQueue"); + strcpy(data, "test data"); + + { // scope the command line option gathering (needed for some reason) + + // Get command line options + PLOptStatus os; + PLOptState *opt = PL_CreateOptState(argc, argv, "bdfhlp:q:"); + + while (PL_OPT_EOL != (os = PL_GetNextOpt(opt))) + { + if (PL_OPT_BAD == os) continue; + switch (opt->option) + { + case 'b': /* broadcast a bunch of messages */ + printf("tmModuleTest: broadcaster\n"); + optMode = 'b'; + break; + case 'd': /* debug mode */ + printf("tmModuleTest: debugging baby\n"); + optDebug = 1; + break; + case 'f': /* broadcast and flush */ + printf("tmModuleTest: flusher\n"); + optMode = 'f'; + break; + case 'h': /* broadcast and detach */ + printf("tmModuleTest: hit-n-run\n"); + optMode = 'h'; + break; + case 'l': /* don't broadcast, just listen */ + printf("tmModuleTest: listener\n"); + optMode = 'l'; + break; + case 'p': /* set the profile name */ + strcpy(profileName, opt->value); + printf("tmModuleTest: profilename:%s\n",profileName); + break; + case 'q': /* set the queue name */ + strcpy(queueName, opt->value); + printf("tmModuleTest: queuename:%s\n",queueName); + break; + default: + printf("tmModuleTest: default\n"); + break; + } + } + PL_DestroyOptState(opt); + } // scope the command line option gathering (needed for some reason) + + { // scope the nsCOMPtrs + + printf("tmModuleTest: Starting xpcom\n"); + + // xpcom startup stuff + nsCOMPtr servMan; + NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); + nsCOMPtr registrar = do_QueryInterface(servMan); + NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); + if (registrar) + registrar->AutoRegister(nsnull); + + // Create the Event Queue for this thread... + nsCOMPtr eqs = do_GetService(kEventQueueServiceCID, &rv); + RETURN_IF_FAILED(rv, "do_GetService(EventQueueService)"); + + rv = eqs->CreateMonitoredThreadEventQueue(); + RETURN_IF_FAILED(rv, "CreateMonitoredThreadEventQueue"); + + rv = eqs->GetThreadEventQueue(NS_CURRENT_THREAD, &gEventQ); + RETURN_IF_FAILED(rv, "GetThreadEventQueue"); + + // Need to make sure the ipc system has been started + printf("tmModuleTest: getting ipc service\n"); + nsCOMPtr ipcServ(do_GetService("@mozilla.org/ipc/service;1", &rv)); + RETURN_IF_FAILED(rv, "do_GetService(ipcServ)"); + NS_ADDREF(gIpcServ = ipcServ); + + // Get the transaction service + printf("tmModuleTest: getting transaction service\n"); + nsCOMPtr transServ(do_GetService("@mozilla.org/ipc/transaction-service;1", &rv)); + RETURN_IF_FAILED(rv, "do_GetService(transServ)"); + NS_ADDREF(gTransServ = transServ); + + // transaction specifc startup stuff, done for all cases + + nsCOMPtr observ = new myTransactionObserver(); + + // initialize the transaction service with a specific profile + gTransServ->Init(nsDependentCString(profileName)); + printf("tmModuleTest: using profileName [%s]\n", profileName); + + // attach to the queue in the transaction manager + gTransServ->Attach(nsDependentCString(queueName), observ, PR_TRUE); + printf("tmModuleTest: observing queue [%s]\n", queueName); + + + // run specific patterns based on the mode + int i = 0; // wasn't working inside the cases + switch (optMode) + { + case 's': + printf("tmModuleTest: start standard\n"); + // post a couple events + for (; i < 5 ; i++) { + gTransServ->PostTransaction(nsDependentCString(queueName), (PRUint8 *)data, dataLen); + } + // listen for events + while (gKeepRunning) + gEventQ->ProcessPendingEvents(); + printf("tmModuleTest: end standard\n"); + break; + case 'b': + printf("tmModuleTest: start broadcast\n"); + // post a BUNCH of messages + for (; i < 50; i++) { + gTransServ->PostTransaction(nsDependentCString(queueName), (PRUint8 *)data, dataLen); + } + // listen for events + while (gKeepRunning) + gEventQ->ProcessPendingEvents(); + printf("tmModuleTest: end broadcast\n"); + break; + case 'f': + printf("tmModuleTest: start flush\n"); + // post a couple events + for (; i < 5; i++) { + gTransServ->PostTransaction(nsDependentCString(queueName), (PRUint8 *)data, dataLen); + } + // flush the queue + gTransServ->Flush(nsDependentCString(queueName), PR_TRUE); + // post a couple events + for (i=0; i < 8; i++) { + gTransServ->PostTransaction(nsDependentCString(queueName), (PRUint8 *)data, dataLen); + } + // listen for events + while (gKeepRunning) + gEventQ->ProcessPendingEvents(); + // detach + gTransServ->Detach(nsDependentCString(queueName)); + printf("tmModuleTest: end flush\n"); + break; + case 'h': + printf("tmModuleTest: start hit-n-run\n"); + // post a couple events + for (; i < 5; i++) { + gTransServ->PostTransaction(nsDependentCString(queueName), (PRUint8 *)data, dataLen); + } + // detach + gTransServ->Detach(nsDependentCString(queueName)); + printf("tmModuleTest: end hit-n-run\n"); + break; + case 'l': + printf("tmModuleTest: start listener\n"); + // listen for events + while (gKeepRunning) + gEventQ->ProcessPendingEvents(); + printf("tmModuleTest: end listener\n"); + break; + default : + printf("tmModuleTest: start & end default\n"); + break; + } + + // shutdown process + + NS_RELEASE(gTransServ); + NS_RELEASE(gIpcServ); + + printf("tmModuleTest: processing remaining events\n"); + + // process any remaining events + PLEvent *ev; + while (NS_SUCCEEDED(gEventQ->GetEvent(&ev)) && ev) + gEventQ->HandleEvent(ev); + + printf("tmModuleTest: done\n"); + } // this scopes the nsCOMPtrs + + // helps with shutdown on some cases + PR_Sleep(PR_SecondsToInterval(4)); + + // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM + rv = NS_ShutdownXPCOM(nsnull); + NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed"); + + return 0; +} -- cgit v1.2.3