hotplug_macosx.cpp [plain text]
#include "wintypes.h"
#include "hotplug.h"
#include "pthread.h"
#include "PCSCDriverBundles.h"
#include "pcscdserver.h"
#include "pcscdmonitor.h"
#include <security_utilities/debugging.h>
const uint32_t kPCSCLITE_HP_BASE_PORT = 0x200000;
PCSCDMonitor *gPCSCDMonitor = NULL;
static Security::MachPlusPlus::Port gMainServerPort;
#ifndef HOTPLUGTEST
#include "readerfactory.h"
#else
LONG RFAddReader(LPSTR, DWORD, LPSTR)
{
return 0;
}
LONG RFRemoveReader(LPSTR, DWORD)
{
return 0;
}
#endif
int32_t WrapRFAddReader(const char *name, uint32_t address, const char *pathLibrary, const char *deviceName)
{
secdebug("device", "RFAddReader: name: %s, address: %04X, pathLibrary: %s, pathDevice: %s", name, address, pathLibrary, deviceName);
return RFAddReader(const_cast<char *>(name), kPCSCLITE_HP_BASE_PORT+address, const_cast<char *>(pathLibrary), const_cast<char *>(deviceName));
}
int32_t WrapRFRemoveReader(const char *name, uint32_t address)
{
secdebug("device", "RFRemoveReader: name: %s, address: %04X", name, address);
return RFRemoveReader(const_cast<char *>(name), kPCSCLITE_HP_BASE_PORT+address);
}
int32_t WrapRFAwakeAllReaders()
{
secdebug("device", "RFAwakeAllReaders");
RFAwakeAllReaders();
return 0;
}
int32_t WrapRFSuspendAllReaders()
{
secdebug("device", "RFSuspendAllReaders");
RFSuspendAllReaders();
return 0;
}
static void *HPDeviceNotificationThread(void *foo)
{
try
{
PCSCD::DriverBundles bdls;
PCSCD::Server myserv("hotplug");
PCSCDMonitor xmon(myserv,bdls);
gPCSCDMonitor = &xmon;
gMainServerPort = myserv.primaryServicePort();
xmon.setCallbacks(WrapRFAddReader, WrapRFRemoveReader, WrapRFSuspendAllReaders, WrapRFAwakeAllReaders);
bdls.update();
myserv.run();
}
catch (Security::MachPlusPlus::Error e)
{
char *perr = (char *)mach_error_string(e.error);
if (perr)
secdebug("device", "Caught error in xx: %s, error: %04lX", perr, e.osStatus());
else
secdebug("device", "Caught error in xx: %04X", e.error);
}
catch (...)
{
}
exit(0);
return NULL; }
void systemAwakeAndReadyCheck()
{
gPCSCDMonitor->systemAwakeAndReadyCheck();
}
int32_t HPSearchHotPluggables()
{
return 0;
}
static pthread_t sHotplugWatcherThread;
int32_t HPRegisterForHotplugEvents()
{
return HPRegisterForHotplugEventsT(&sHotplugWatcherThread);
}
int32_t HPRegisterForHotplugEventsT(pthread_t *wthread)
{
int rx = pthread_create(wthread, NULL, HPDeviceNotificationThread, NULL);
return rx;
}
LONG HPStopHotPluggables(void)
{
int rx = pthread_detach(sHotplugWatcherThread);
return rx;
}
void HPReCheckSerialReaders(void)
{
}
LONG HPCancelHotPluggables(void)
{
int rx = pthread_cancel(sHotplugWatcherThread);
return rx;
}
LONG HPJoinHotPluggables(void)
{
char *value_ptr;
int rx = pthread_join(sHotplugWatcherThread, (void **)&value_ptr);
return rx;
}