Back to index

lightning-sunbird  0.9+nobinonly
tmIPCModule.cpp
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is Mozilla Transaction Manager.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * Netscape Communications Corp.
00018  * Portions created by the Initial Developer are Copyright (C) 2003
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *   John Gaunt <jgaunt@netscape.com>
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #include "tmIPCModule.h"
00039 #include "tmTransaction.h"
00040 #include "tmTransactionManager.h"
00041 
00043 // IPC Daemon hookup stuff
00044 
00045 // functionpointer array giving access to this module from the IPC daemon
00046 static ipcModuleMethods gTransMethods =
00047 {
00048     IPC_MODULE_METHODS_VERSION,
00049     tmIPCModule::Init,
00050     tmIPCModule::Shutdown,
00051     tmIPCModule::HandleMsg
00052 };
00053 
00054 static ipcModuleEntry gTransModuleEntry[] =
00055 {
00056     { TRANSACTION_MODULE_ID, &gTransMethods }
00057 };
00058 
00059 IPC_IMPL_GETMODULES(TransactionModule, gTransModuleEntry)
00060 
00061 static const nsID kTransModuleID = TRANSACTION_MODULE_ID;
00062 
00064 // Define global variable
00065 
00066 tmTransactionManager *tmIPCModule::tm;
00067 
00069 // IPC Module API
00070 
00071 void
00072 tmIPCModule::Init() {
00073   if (!tm)
00074     InitInternal();
00075 }
00076 
00077 void
00078 tmIPCModule::Shutdown() {
00079   if (tm) {
00080     delete tm;
00081     tm = nsnull;
00082   }
00083 }
00084 
00085 // straight pass-through, don't check args, let the TM do it.
00086 void
00087 tmIPCModule::HandleMsg(ipcClientHandle client, const nsID &target, 
00088                        const void *data, PRUint32 dataLen) {
00089 
00090   // make sure the trans mngr is there
00091   if (!tm && (InitInternal() < 0))
00092     return;
00093 
00094   // create the transaction
00095   tmTransaction *trans = new tmTransaction();
00096 
00097   // initialize it
00098   if (trans) {
00099     if(NS_SUCCEEDED(trans->Init(IPC_GetClientID(client),  // who owns it
00100                                 TM_INVALID_ID,            // in data
00101                                 TM_INVALID,               // in data
00102                                 TM_INVALID,               // in data
00103                                 (PRUint8 *)data,          // raw message
00104                                 dataLen))) {              // length of message
00105       // pass it on to the trans mngr
00106       tm->HandleTransaction(trans);
00107     }
00108     else
00109       delete trans;
00110   }
00111 }
00112 
00114 // tmIPCModule API
00115 
00116 // straight pass-through, don't check args, let the TS & TM do it.
00117 void
00118 tmIPCModule::SendMsg(PRUint32 aDestClientIPCID, tmTransaction *aTransaction) {
00119 
00120   IPC_SendMsg(aDestClientIPCID,
00121               kTransModuleID,
00122               (void *)aTransaction->GetRawMessage(),
00123               aTransaction->GetRawMessageLength());
00124 }
00125 
00127 // Protected Methods
00128 
00129 PRInt32
00130 tmIPCModule::InitInternal() {
00131 
00132   tm = new tmTransactionManager();
00133   if (tm)
00134     return tm->Init();
00135   return -1;
00136 }
00137