// APSCLI.CPP
//
// Copyright (c) 1997-1999 Symbian Ltd.  All rights reserved.
//

//
//	Client access to the AppArc server
//

#include <e32base.h>
#include <e32svr.h>
#include <apasvst.h>
#include <apsserv.h>
#include <e32uid.h>
#include <f32file.h>

#include "apsstd.h"

const TInt KApaServThreadStackSize=KDefaultStackSize;

EXPORT_C TInt StartupApaServer(MApaAppStarter& aAppStarter)
// Create a new thread of the correct priority, then construct
// the server in that thread
	{
	TFindServer findServer(KAppListServerName);
	TFullName name;
	if (findServer.Next(name)==KErrNone)
		return KErrAlreadyExists;

	RSemaphore globStartSignal;
	TInt err=globStartSignal.CreateGlobal(NameApaServStartSemaphore(),EOwnerProcess);
	if (err!=KErrNone)
		{
		err=globStartSignal.OpenGlobal(NameApaServStartSemaphore(),EOwnerProcess);
		if (err!=KErrNone)
			return err;
		}
	RThread appArcServerThread;
	SCommandLine comLine;
	comLine.iAppStarter=&aAppStarter;
	err=appArcServerThread.Create(NameApaServServerThread(),ApaServThreadStart,KApaServThreadStackSize,KMinHeapSize,KApaServMaxHeapSize,&comLine,EOwnerThread);
	appArcServerThread.Resume();
	appArcServerThread.Close();
	globStartSignal.Wait();
	return err;
	}
