#ifndef __ServerControl_h__
#define __ServerControl_h__ 1
#include <mach/port.h>
#define USE_SYSTEMCONFIGURATION_PUBLIC_APIS
#include <SystemConfiguration/SystemConfiguration.h>
#include "PrivateTypes.h"
#include "DSSemaphore.h"
#include "SharedConsts.h"
const uInt32 kMaxHandlerThreads = 4; const uInt32 kMaxCheckpwHandlerThreads = 1; const uInt32 kMaxInternalHandlerThreads = 10;
#define kDSDefaultListenPort 625 //TODO need final port number
#define BUILD_IN_PERFORMANCE
#ifdef BUILD_IN_PERFORMANCE
#define PERFORMANCE_STATS_ALWAYS_ON 0
#define kNumErrorsToTrack 5
typedef struct {
sInt32 clientPID;
sInt32 error;
} ErrorByPID;
typedef struct {
uInt32 msgCnt;
uInt32 errCnt;
double minTime;
double maxTime;
double totTime;
ErrorByPID lastNErrors[kNumErrorsToTrack];
} PluginPerformanceAPIStat;
typedef struct {
FourCharCode pluginSignature;
const char* pluginName;
PluginPerformanceAPIStat apiStats[kDSPlugInCallsEnd]; } PluginPerformanceStats;
#endif
class CListener;
class DSTCPListener;
class CHandlerThread;
class CNodeList;
class CPlugInList;
extern CNodeList *gNodeList;
extern CPlugInList *gPlugins;
class ServerControl
{
public:
ServerControl ( void );
virtual ~ServerControl ( void );
virtual sInt32 StartUpServer ( void );
virtual sInt32 ShutDownServer ( void );
sInt32 StartAHandler ( const FourCharCode inThreadSignature );
sInt32 StopAHandler ( const FourCharCode inThreadSignature, uInt32 iThread, CHandlerThread *inThread );
void WakeAHandler ( const FourCharCode inThreadSignature );
void SleepAHandler ( const FourCharCode inThreadSignature, uInt32 waitTime );
uInt32 GetHandlerCount ( const FourCharCode inThreadSignature );
sInt32 StartTCPListener ( uInt32 inPort );
sInt32 StopTCPListener ( void );
sInt32 HandleNetworkTransition
( void );
sInt32 NIAutoSwitchCheck ( void );
sInt32 SetUpPeriodicTask ( void );
#ifdef BUILD_IN_PERFORMANCE
void ActivatePeformanceStatGathering( void ) { fPerformanceStatGatheringActive = true; }
void DeactivatePeformanceStatGathering( void ) { fPerformanceStatGatheringActive = false; LogStats(); DeletePerfStatTable(); }
void HandlePerformanceStats ( uInt32 msgType, FourCharCode pluginSig, sInt32 siResult, sInt32 clientPID, double inTime, double outTime );
void LogStats ( void );
#endif
bool IsPeformanceStatGatheringActive
( void ) { return fPerformanceStatGatheringActive; }
void NotifyDirNodeAdded ( const char* newNode );
void NotifyDirNodeDeleted ( char* oldNode );
void NodeSearchPolicyChanged ( void );
protected:
#ifdef BUILD_IN_PERFORMANCE
void DeletePerfStatTable ( void );
PluginPerformanceStats**
CreatePerfStatTable ( void );
#endif
sInt32 StartListener ( void );
sInt32 RegisterForSystemPower ( void );
sInt32 UnRegisterForSystemPower ( void );
sInt32 RegisterForNetworkChange ( void );
sInt32 UnRegisterForNetworkChange ( void );
sInt32 UnbindToNetInfo ( void );
void HandleMultipleNetworkTransitionsForNIAutoSwitch ( void );
void LaunchKerberosAutoConfigTool( void );
private:
uInt32 fTCPHandlerThreadsCnt;
uInt32 fHandlerThreadsCnt;
uInt32 fInternalHandlerThreadsCnt;
uInt32 fCheckpwHandlerThreadsCnt;
#ifdef BUILD_IN_PERFORMANCE
uInt32 fLastPluginCalled;
PluginPerformanceStats **fPerfTable;
uInt32 fPerfTableNumPlugins;
#endif
CListener *fListener;
DSTCPListener *fTCPListener;
CHandlerThread *fTCPHandlers[ kMaxHandlerThreads ];
CHandlerThread *fHandlers[ kMaxHandlerThreads ];
CHandlerThread *fInternalHandlers[ kMaxInternalHandlerThreads ];
CHandlerThread *fCheckpwHandlers[ kMaxCheckpwHandlerThreads ];
DSSemaphore *fTCPHandlerSemaphore;
DSSemaphore *fHandlerSemaphore;
DSSemaphore *fInternalHandlerSemaphore;
DSSemaphore *fCheckpwHandlerSemaphore;
SCDynamicStoreRef fSCDStore;
bool fPerformanceStatGatheringActive;
double fTimeToCheckNIAutoSwitch;
SCDynamicStoreRef fHoldStore;
CFStringRef fServiceNameString;
};
extern ServerControl *gSrvrCntl;
#endif