tmModuleTest.cpp revision 677833bc953b6cb418c701facbdcf4aa18d6c44e
/* ***** 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
*
* 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 <jgaunt@netscape.com>
*
* 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"
//////////////////////////////////////////////////////////////////////////////
const int NameSize = 1024;
/* command line options */
char optMode = 's';
char *profileName = new char[NameSize];
//////////////////////////////////////////////////////////////////////////////
return rv;\
} \
//static PRInt32 gMsgCount = 0;
//-----------------------------------------------------------------------------
class myTransactionObserver : public ipcITransactionObserver
{
public:
myTransactionObserver() { }
};
NS_IMETHODIMP myTransactionObserver::OnTransactionAvailable(PRUint32 aQueueID, const PRUint8 *aData, PRUint32 aDataLen)
{
return NS_OK;
}
{
return NS_OK;
}
{
return NS_OK;
}
{
return NS_OK;
}
//-----------------------------------------------------------------------------
{
// default string values
{ // scope the command line option gathering (needed for some reason)
// Get command line options
{
if (PL_OPT_BAD == os) continue;
{
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 */
break;
case 'q': /* set the queue name */
break;
default:
printf("tmModuleTest: default\n");
break;
}
}
} // scope the command line option gathering (needed for some reason)
{ // scope the nsCOMPtrs
printf("tmModuleTest: Starting xpcom\n");
// xpcom startup stuff
if (registrar)
// Create the Event Queue for this thread...
// Need to make sure the ipc system has been started
printf("tmModuleTest: getting ipc service\n");
// Get the transaction service
printf("tmModuleTest: getting transaction service\n");
nsCOMPtr<ipcITransactionService> transServ(do_GetService("@mozilla.org/ipc/transaction-service;1", &rv));
// transaction specifc startup stuff, done for all cases
// initialize the transaction service with a specific profile
// attach to the queue in the transaction manager
// 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++) {
}
// listen for events
while (gKeepRunning)
printf("tmModuleTest: end standard\n");
break;
case 'b':
printf("tmModuleTest: start broadcast\n");
// post a BUNCH of messages
for (; i < 50; i++) {
}
// listen for events
while (gKeepRunning)
printf("tmModuleTest: end broadcast\n");
break;
case 'f':
printf("tmModuleTest: start flush\n");
// post a couple events
for (; i < 5; i++) {
}
// flush the queue
// post a couple events
for (i=0; i < 8; i++) {
}
// listen for events
while (gKeepRunning)
// detach
printf("tmModuleTest: end flush\n");
break;
case 'h':
printf("tmModuleTest: start hit-n-run\n");
// post a couple events
for (; i < 5; i++) {
}
// detach
printf("tmModuleTest: end hit-n-run\n");
break;
case 'l':
printf("tmModuleTest: start listener\n");
// listen for events
while (gKeepRunning)
printf("tmModuleTest: end listener\n");
break;
default :
printf("tmModuleTest: start & end default\n");
break;
}
// shutdown process
printf("tmModuleTest: processing remaining events\n");
// process any remaining events
printf("tmModuleTest: done\n");
} // this scopes the nsCOMPtrs
// helps with shutdown on some cases
// no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM
return 0;
}