#include "CPlugInList.h"
#include "CServerPlugin.h"
#include "CLauncher.h"
#include "DSUtils.h"
#include "PrivateTypes.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
CPlugInList::CPlugInList ( void )
{
fPICount = 0;
::memset( fTable, 0, sizeof( fTable ) );
}
CPlugInList::~CPlugInList ( void )
{
}
sInt32 CPlugInList::AddPlugIn ( const char *inName,
const char *inVersion,
const char *inConfigAvail,
const char *inConfigFile,
FourCharCode inKey,
CServerPlugin *inPluginPtr )
{
sInt32 siResult = kMaxPlugInsLoaded;
uInt32 uiCntr = 0;
fMutex.Wait();
try
{
if ( inName == nil )
{
return( kInvalidPlugInName );
}
while ( uiCntr < kMaxPlugIns )
{
if ( fTable[ uiCntr ].fName == nil )
{
fTable[ uiCntr ].fName = inName;
fTable[ uiCntr ].fVersion = inVersion;
fTable[ uiCntr ].fConfigAvail = inConfigAvail;
fTable[ uiCntr ].fConfigFile = inConfigFile;
fTable[ uiCntr ].fPluginPtr = inPluginPtr;
fTable[ uiCntr ].fKey = inKey;
fTable[ uiCntr ].fState = kInactive | kUninitalized;
fPICount++;
siResult = kPlugInListNoErr;
break;
}
uiCntr++;
}
}
catch( sInt32 err )
{
siResult = err;
}
fMutex.Signal();
return( siResult );
}
sInt32 CPlugInList::DeletePlugIn ( const char *inName )
{
sInt32 siResult = kPlugInNotFound;
uInt32 uiCntr = 0;
fMutex.Wait();
try
{
if ( inName == nil )
{
return( kInvalidPlugInName );
}
while ( uiCntr < kMaxPlugIns )
{
if ( fTable[ uiCntr ].fName != nil )
{
if ( ::strcmp( fTable[ uiCntr ].fName, inName ) == 0 )
{
fTable[ uiCntr ].fName = nil;
fTable[ uiCntr ].fVersion = nil;
fTable[ uiCntr ].fConfigAvail = nil;
fTable[ uiCntr ].fConfigFile = nil;
fTable[ uiCntr ].fPluginPtr = nil;
fTable[ uiCntr ].fKey = 0;
fTable[ uiCntr ].fState = kUnknownState;
fPICount--;
siResult = kPlugInListNoErr;
break;
}
}
uiCntr++;
}
}
catch( sInt32 err )
{
siResult = err;
}
fMutex.Signal();
return( siResult );
}
void CPlugInList::InitPlugIns ( void )
{
uInt32 uiCntr = 0;
fMutex.Wait();
try
{
while ( uiCntr < kMaxPlugIns )
{
if ( (fTable[ uiCntr ].fName != nil) && (fTable[ uiCntr ].fPluginPtr != nil) )
{
CLauncher *cpLaunch = new CLauncher( (CServerPlugin *)fTable[ uiCntr ].fPluginPtr );
if ( cpLaunch != nil )
{
cpLaunch->StartThread();
}
}
uiCntr++;
}
}
catch( sInt32 err )
{
}
fMutex.Signal();
}
sInt32 CPlugInList::IsPresent ( const char *inName )
{
sInt32 siResult = kPlugInNotFound;
uInt32 uiCntr = 0;
fMutex.Wait();
try
{
if ( inName == nil )
{
return( kInvalidPlugInName );
}
while ( uiCntr < kMaxPlugIns )
{
if ( fTable[ uiCntr ].fName != nil )
{
if ( ::strcmp( fTable[ uiCntr ].fName, inName ) == 0 )
{
siResult = kPlugInFound;
break;
}
}
uiCntr++;
}
}
catch( sInt32 err )
{
siResult = err;
}
fMutex.Signal();
return( siResult );
}
sInt32 CPlugInList::SetState ( const char *inName, const uInt32 inState )
{
sInt32 siResult = kPlugInNotFound;
uInt32 uiCntr = 0;
fMutex.Wait();
try
{
if ( inName == nil )
{
return( kInvalidPlugInName );
}
while ( uiCntr < kMaxPlugIns )
{
if ( fTable[ uiCntr ].fName != nil )
{
if ( ::strcmp( fTable[ uiCntr ].fName, inName ) == 0 )
{
fTable[ uiCntr ].fState = inState;
siResult = kPlugInListNoErr;
break;
}
}
uiCntr++;
}
}
catch( sInt32 err )
{
siResult = err;
}
fMutex.Signal();
return( siResult );
}
sInt32 CPlugInList::GetState ( const char *inName, uInt32 *outState )
{
sInt32 siResult = kPlugInNotFound;
uInt32 uiCntr = 0;
fMutex.Wait();
try
{
if ( inName == nil )
{
return( kInvalidPlugInName );
}
while ( uiCntr < kMaxPlugIns )
{
if ( fTable[ uiCntr ].fName != nil )
{
if ( ::strcmp( fTable[ uiCntr ].fName, inName ) == 0 )
{
*outState = fTable[ uiCntr ].fState;
siResult = kPlugInListNoErr;
break;
}
}
uiCntr++;
}
}
catch( sInt32 err )
{
siResult = err;
}
fMutex.Signal();
return( siResult );
}
uInt32 CPlugInList::GetPlugInCount ( void )
{
return( fPICount );
}
uInt32 CPlugInList::GetActiveCount ( void )
{
uInt32 siResult = 0;
uInt32 uiCntr = 0;
fMutex.Wait();
try
{
while ( uiCntr < kMaxPlugIns )
{
if ( fTable[ uiCntr ].fName == nil )
{
if ( fTable[ uiCntr ].fState & kActive )
{
siResult++;
}
}
uiCntr++;
}
}
catch( sInt32 err )
{
siResult = 0;
}
fMutex.Signal();
return( siResult );
}
CServerPlugin* CPlugInList::GetPlugInPtr ( const char *inName )
{
CServerPlugin *pResult = nil;
uInt32 uiCntr = 0;
fMutex.Wait();
try
{
if ( inName == nil )
{
return( nil );
}
while ( uiCntr < kMaxPlugIns )
{
if ( (fTable[ uiCntr ].fName != nil) && (fTable[ uiCntr ].fPluginPtr != nil) )
{
if ( ::strcmp( fTable[ uiCntr ].fName, inName ) == 0 )
{
pResult = fTable[ uiCntr ].fPluginPtr;
break;
}
}
uiCntr++;
}
}
catch( sInt32 err )
{
pResult = nil;
}
fMutex.Signal();
return( pResult );
}
CServerPlugin* CPlugInList::GetPlugInPtr ( const uInt32 inKey )
{
CServerPlugin *pResult = nil;
uInt32 uiCntr = 0;
fMutex.Wait();
try
{
while ( uiCntr < kMaxPlugIns )
{
if ( (fTable[ uiCntr ].fName != nil) && (fTable[ uiCntr ].fPluginPtr != nil) )
{
if ( fTable[ uiCntr ].fKey == inKey )
{
pResult = fTable[ uiCntr ].fPluginPtr;
break;
}
}
uiCntr++;
}
}
catch( sInt32 err )
{
pResult = nil;
}
fMutex.Signal();
return( pResult );
}
CServerPlugin* CPlugInList::Next ( uInt32 *inIndex )
{
CServerPlugin *pResult = nil;
uInt32 uiCntr = *inIndex;
fMutex.Wait();
try
{
while ( uiCntr < kMaxPlugIns )
{
if ( (fTable[ uiCntr ].fName != nil) && (fTable[ uiCntr ].fPluginPtr != nil) )
{
pResult = fTable[ uiCntr ].fPluginPtr;
uiCntr++;
break;
}
uiCntr++;
}
}
catch( sInt32 err )
{
pResult = nil;
}
*inIndex = uiCntr;
fMutex.Signal();
return( pResult );
}
CPlugInList::sTableData* CPlugInList::GetPlugInInfo ( uInt32 inIndex )
{
sTableData *pResult = nil;
fMutex.Wait();
try
{
if ( inIndex < kMaxPlugIns )
{
pResult = &fTable[ inIndex ];
}
}
catch( sInt32 err )
{
pResult = nil;
}
fMutex.Signal();
return( pResult );
}