#ifndef _H_IODEVICES
#define _H_IODEVICES
#include <security_utilities/mach++.h>
#include <security_utilities/machserver.h>
#include <security_utilities/cfutilities.h>
#include <IOKit/pwr_mgt/IOPMLib.h>
namespace Security {
namespace IOKit {
class MasterPort : public MachPlusPlus::AutoPort {
public:
MasterPort();
};
class Device {
public:
Device() : mService(MACH_PORT_NULL) { }
Device(io_service_t d) : mService(d) { }
~Device();
io_service_t ioObject() const { return mService; }
operator bool () const { return mService; }
bool operator ! () const { return !mService; }
std::string name() const;
std::string name(const char *plane) const;
std::string path(const char *plane = kIOServicePlane) const;
CFDictionaryRef properties() const;
CFTypeRef property(const char *name) const;
template <class T>
T property(const char *name) const
{ return static_cast<T>(property(name)); }
private:
io_service_t mService;
};
class DeviceIterator {
public:
DeviceIterator(io_iterator_t iter) : mIterator(iter), mAtEnd(false) { }
~DeviceIterator();
io_service_t operator () ();
private:
io_iterator_t mIterator; bool mAtEnd; };
class DeviceMatch : public CFRef<CFMutableDictionaryRef> {
NOCOPY(DeviceMatch)
public:
DeviceMatch(CFMutableDictionaryRef dict) : CFRef<CFMutableDictionaryRef>(dict) { } DeviceMatch(); DeviceMatch(const char *cls); DeviceMatch(const char *cls, const char *name, uint32_t value, ...);
CFRef<CFMutableDictionaryRef> &dict() { return static_cast<CFRef<CFMutableDictionaryRef> &>(*this); }
operator bool () const { return this->get() != NULL; }
bool operator ! () const { return this->get() == NULL; }
void add(const char *name, uint32_t value); };
class NotificationPort {
public:
NotificationPort();
NotificationPort(const MasterPort &master);
~NotificationPort();
mach_port_t port() const;
operator mach_port_t () const { return port(); }
CFRunLoopSourceRef source() const;
class Receiver {
public:
virtual ~Receiver();
virtual void ioChange(DeviceIterator &iterator) = 0;
virtual void ioServiceChange(void *refCon, io_service_t service, natural_t messageType, void *messageArgument) {}
};
void add(const DeviceMatch &match, Receiver &receiver, const char *type = kIOFirstMatchNotification);
void addInterestNotification(Receiver &receiver, io_service_t service,
const io_name_t interestType = kIOGeneralInterest);
private:
static void ioNotify(void *refCon, io_iterator_t iterator);
static void ioDeviceNotification(void *refCon, io_service_t service,
natural_t messageType, void *messageArgument);
protected:
IONotificationPortRef mPortRef;
};
class MachPortNotificationPort : public NotificationPort, public MachPlusPlus::MachServer::NoReplyHandler {
public:
MachPortNotificationPort();
virtual ~MachPortNotificationPort();
private:
boolean_t handle(mach_msg_header_t *in);
};
} }
#endif //_H_IODEVICES