本文整理汇总了C++中IOMasterPort函数的典型用法代码示例。如果您正苦于以下问题:C++ IOMasterPort函数的具体用法?C++ IOMasterPort怎么用?C++ IOMasterPort使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了IOMasterPort函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sleepImmediately
static int sleepImmediately (void)
{
mach_port_t masterPort;
io_connect_t rootPort;
IOReturn err;
if (IOPMSleepEnabled()) {
if ((err = IOMasterPort(MACH_PORT_NULL, &masterPort))) {
fprintf (stderr, "%s: can't get mach master port: %ld\n", args.progname, (long) err);
return (1);
}
rootPort = IOPMFindPowerManagement(masterPort);
if (rootPort) {
err = IOPMSleepSystem(rootPort);
if (err) {
fprintf (stderr, "%s: IOPMSleepSystem failed: %ld\n", args.progname, (long) err);
return (1);
}
} else {
fprintf (stderr, "%s: IOPMFindPowerManagement failed\n", args.progname);
return (1);
}
} else {
fprintf (stderr, "%s: sleep mode is disabled\n", args.progname);
return (1);
}
return (0);
}
示例2: IOMasterPort
int AoEProperties::configure_matching(void)
{
// debugVerbose("AoEProperties::configure_matching\n");
// Obtain ports for notifications (this will be used for all service matching notifications)
kern_return_t kresult;
mach_port_t MasterPort;
kresult = IOMasterPort(MACH_PORT_NULL, &MasterPort);
if ( kresult )
{
debugError("Could not get masterport. Error=%d\n", kresult);
return false;
}
ms_NotificationPort = IONotificationPortCreate(MasterPort);
ms_IOKitNotificationRunLoopSource = IONotificationPortGetRunLoopSource(ms_NotificationPort);
CFRunLoopAddSource(CFRunLoopGetCurrent(), ms_IOKitNotificationRunLoopSource, kCFRunLoopDefaultMode);
// SetUp Notification for matching to our device
CFMutableDictionaryRef MatchingDict = IOServiceMatching(AOE_KEXT_NAME_Q);
IOServiceAddMatchingNotification(ms_NotificationPort,
kIOMatchedNotification,
MatchingDict,
AoEProperties::matched_callback,
this,
&ms_MatchIt);
// Call the callback immediately to check if our iterator already contains our device (ie. the device is already loaded)
matched_callback(this, ms_MatchIt);
return m_fMatched ? 0 : -1;
}
示例3: DASessionCreate
/**
* Use the DiskArbitration Daemon to inform us of media changes
*/
void MonitorThreadDarwin::run(void)
{
CFDictionaryRef match = kDADiskDescriptionMatchVolumeMountable;
DASessionRef daSession = DASessionCreate(kCFAllocatorDefault);
IOMasterPort(MACH_PORT_NULL, &sMasterPort);
DARegisterDiskAppearedCallback(daSession, match,
diskAppearedCallback, this);
DARegisterDiskDisappearedCallback(daSession, match,
diskDisappearedCallback, this);
DARegisterDiskDescriptionChangedCallback(daSession, match,
kDADiskDescriptionWatchVolumeName,
diskChangedCallback, this);
DASessionScheduleWithRunLoop(daSession,
CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
// Nice and simple, as long as our monitor is valid and active,
// loop and let daSession check the devices.
while (m_Monitor && m_Monitor->IsActive())
{
// Run the run loop for interval (milliseconds) - this will
// handle any disk arbitration appeared/dissappeared events
CFRunLoopRunInMode(kCFRunLoopDefaultMode,
(float) m_Interval / 1000.0f, false );
}
DAUnregisterCallback(daSession, (void(*))diskChangedCallback, this);
DAUnregisterCallback(daSession, (void(*))diskDisappearedCallback, this);
DAUnregisterCallback(daSession, (void(*))diskAppearedCallback, this);
CFRelease(daSession);
}
示例4: SMCOpen
kern_return_t SMCOpen(io_connect_t *conn, const char *serviceName)
{
kern_return_t result;
mach_port_t masterPort;
io_iterator_t iterator;
io_object_t device;
IOMasterPort(MACH_PORT_NULL, &masterPort);
CFMutableDictionaryRef matchingDictionary = IOServiceMatching(serviceName);
result = IOServiceGetMatchingServices(masterPort, matchingDictionary, &iterator);
if (result != kIOReturnSuccess)
{
//printf("Error: IOServiceGetMatchingServices() = %08x\n", result);
return 1;
}
device = IOIteratorNext(iterator);
IOObjectRelease((io_object_t)iterator);
if (device == 0)
{
//printf("Error: no SMC found\n");
return 1;
}
result = IOServiceOpen(device, mach_task_self(), 0, conn);
IOObjectRelease(device);
if (result != kIOReturnSuccess)
{
//printf("Error: IOServiceOpen() = %08x\n", result);
return 1;
}
return kIOReturnSuccess;
}
示例5: main
int main(int argc, char **argv)
{
mach_port_t masterPort;
kern_return_t status;
int arg;
// Parse args
if( argc < 2 ) {
printf("%s ClassName...\n", argv[0]);
exit(0);
}
// Obtain the I/O Kit communication handle.
status = IOMasterPort(bootstrap_port, &masterPort);
assert(status == KERN_SUCCESS);
for( arg = 1; arg < argc; arg++ ) {
printf("terminate %s...", argv[arg]);
status = IOCatalogueTerminate( masterPort, 0, argv[arg] );
printf("(%08x)\n", status);
}
exit(0);
}
示例6: inputopen
int inputopen(usbdevice* kb){
// Open master port (if not done yet)
static mach_port_t master = 0;
kern_return_t res;
if(!master&& (res = IOMasterPort(bootstrap_port, &master)) != KERN_SUCCESS){
master = 0;
printf("Unable to open master port: 0x%08x\n", res);
return 0;
}
// Open an HID service
io_iterator_t iter;
if((res = IOServiceGetMatchingServices(master, IOServiceMatching(kIOHIDSystemClass), &iter)) != KERN_SUCCESS){
printf("Unable to get input service iterator: 0x%08x\n", res);
return 0;
}
if((res = IOServiceOpen(IOIteratorNext(iter), mach_task_self(), kIOHIDParamConnectType, &kb->event)) != KERN_SUCCESS){
IOObjectRelease(iter);
printf("Unable to open IO service: 0x%08x\n", res);
kb->event = 0;
return 0;
}
IOObjectRelease(iter);
clearkeys(kb);
return 1;
}
示例7: open_iohid
// Opens HID service. Returns kIOReturnSuccess on success.
static int open_iohid(io_connect_t* connection){
io_iterator_t iter;
io_service_t service;
// Open master port (if not done yet)
static mach_port_t master = 0;
kern_return_t res;
if(!master && (res = IOMasterPort(bootstrap_port, &master)) != kIOReturnSuccess){
master = 0;
ckb_err("Unable to open master port: 0x%08x\n", res);
goto failure;
}
// Open the HID service
if((res = IOServiceGetMatchingServices(master, IOServiceMatching(kIOHIDSystemClass), &iter)) != kIOReturnSuccess)
goto failure;
service = IOIteratorNext(iter);
if(!service){
res = kIOReturnNotOpen;
goto failure_release_iter;
}
if((res = IOServiceOpen(service, mach_task_self(), kIOHIDParamConnectType, connection)) != kIOReturnSuccess){
*connection = 0;
goto failure_release_iter;
}
// Finished; release objects and return success
IOObjectRelease(service);
failure_release_iter:
IOObjectRelease(iter);
failure:
return res;
}
示例8: FindModems
static kern_return_t
FindModems(io_iterator_t *matchingServices)
{
kern_return_t kernResult;
mach_port_t masterPort;
CFMutableDictionaryRef classesToMatch;
kernResult = IOMasterPort(MACH_PORT_NULL, &masterPort);
if (KERN_SUCCESS != kernResult)
{
/* printf("IOMasterPort returned %d\n", kernResult); */
goto exit;
}
classesToMatch = IOServiceMatching(kIOSerialBSDServiceValue);
if (classesToMatch != NULL)
{
CFDictionarySetValue(classesToMatch,
CFSTR(kIOSerialBSDTypeKey),
CFSTR(kIOSerialBSDModemType));
}
kernResult = IOServiceGetMatchingServices(masterPort, classesToMatch, matchingServices);
if (KERN_SUCCESS != kernResult)
{
/* printf("IOServiceGetMatchingServices returned %d\n", kernResult); */
goto exit;
}
exit:
return kernResult;
}
示例9: createSerialIterator
static kern_return_t createSerialIterator(io_iterator_t *serialIterator)
{
kern_return_t kernResult;
mach_port_t masterPort;
CFMutableDictionaryRef classesToMatch;
if ((kernResult = IOMasterPort(0, &masterPort)) != KERN_SUCCESS)
{
printf("IOMasterPort returned %d\n", kernResult);
return kernResult;
}
if ((classesToMatch = IOServiceMatching(kIOSerialBSDServiceValue)) == NULL)
{
printf("IOServiceMatching returned NULL\n");
return kernResult;
}
CFDictionarySetValue(classesToMatch, CFSTR(kIOSerialBSDTypeKey),CFSTR(kIOSerialBSDAllTypes));
kernResult = IOServiceGetMatchingServices(masterPort, classesToMatch, serialIterator);
if (kernResult != KERN_SUCCESS)
{
printf("IOServiceGetMatchingServices returned %d\n", kernResult);
}
return kernResult;
}
示例10: fetch_raw_smbios
bool fetch_raw_smbios(unsigned char** data, unsigned int* length)
{
CFDataRef value = NULL;
io_object_t device;
io_iterator_t objectIterator;
CFMutableDictionaryRef properties = NULL;
mach_port_t master_port;
bool result = false;
if (kIOReturnSuccess == IOMasterPort(MACH_PORT_NULL, &master_port)) {
if (kIOReturnSuccess == IOServiceGetMatchingServices(master_port, IOServiceMatching("AppleSMBIOS"), &objectIterator)) {
while ((device = IOIteratorNext(objectIterator))) {
if (kIOReturnSuccess == IORegistryEntryCreateCFProperties(device, &properties, kCFAllocatorDefault, kNilOptions)) {
if (CFDictionaryGetValueIfPresent(properties, CFSTR("SMBIOS"), (const void **)&value)) {
*length = CFDataGetLength(value);
*data = new uint8[*length];
memcpy(*data, (uint8 *)CFDataGetBytePtr(value), *length);
result = true;
break;
}
CFRelease(properties);
}
IOObjectRelease(device);
}
IOObjectRelease(objectIterator);
}
mach_port_deallocate(mach_task_self(), master_port);
}
return result;
}
示例11: IN_GetIOHandle
/*
===============
IN_GetIOHandle
===============
*/
static io_connect_t IN_GetIOHandle( void ) // mac os x mouse accel hack
{
io_connect_t iohandle = MACH_PORT_NULL;
kern_return_t status;
io_service_t iohidsystem = MACH_PORT_NULL;
mach_port_t masterport;
status = IOMasterPort( MACH_PORT_NULL, &masterport );
if ( status != KERN_SUCCESS )
{
return 0;
}
iohidsystem = IORegistryEntryFromPath( masterport, kIOServicePlane ":/IOResources/IOHIDSystem" );
if ( !iohidsystem )
{
return 0;
}
status = IOServiceOpen( iohidsystem, mach_task_self(), kIOHIDParamConnectType, &iohandle );
IOObjectRelease( iohidsystem );
return iohandle;
}
示例12: FindEjectableCDMedia
kern_return_t FindEjectableCDMedia( io_iterator_t *mediaIterator )
{
kern_return_t kernResult;
mach_port_t masterPort;
CFMutableDictionaryRef classesToMatch;
kernResult = IOMasterPort( MACH_PORT_NULL, &masterPort );
if ( KERN_SUCCESS != kernResult ) {
printf( "IOMasterPort returned %d\n", kernResult );
}
classesToMatch = IOServiceMatching( kIOCDMediaClass );
if ( classesToMatch == NULL ) {
printf( "IOServiceMatching returned a NULL dictionary.\n" );
} else {
CFDictionarySetValue( classesToMatch, CFSTR( kIOMediaEjectableKey ), kCFBooleanTrue );
}
kernResult = IOServiceGetMatchingServices( masterPort, classesToMatch, mediaIterator );
if ( KERN_SUCCESS != kernResult )
{
printf( "IOServiceGetMatchingServices returned %d\n", kernResult );
}
return kernResult;
}
示例13: get_event_driver
io_connect_t get_event_driver(void){
static mach_port_t sEventDrvrRef = 0;
mach_port_t masterPort, service, iter;
kern_return_t kr;
if (!sEventDrvrRef)
{
// Get master device port
kr = IOMasterPort( bootstrap_port, &masterPort );
check( KERN_SUCCESS == kr);
kr = IOServiceGetMatchingServices( masterPort, IOServiceMatching(
kIOHIDSystemClass ), &iter );
check( KERN_SUCCESS == kr);
service = IOIteratorNext( iter );
check( service );
kr = IOServiceOpen( service, mach_task_self(),
kIOHIDParamConnectType, &sEventDrvrRef );
check( KERN_SUCCESS == kr );
IOObjectRelease( service );
IOObjectRelease( iter );
}
return sEventDrvrRef;
}
示例14: main
int main(int argc, char **argv)
{
kern_return_t result;
result = IOMasterPort(bootstrap_port, &masterPort);
if (result != KERN_SUCCESS) {
errx(1, "Error getting the IOMaster port: %s",
mach_error_string(result));
}
gPlatform = IORegistryEntryFromPath(masterPort, "IODeviceTree:/efi/platform");
if (gPlatform == 0) {
errx(1, "EFI is not supported on this system");
}
CFTypeRef data;
result = GetOFVariable("Settings", &data);
if (result != KERN_SUCCESS) {
errx(1, "Clover absent or too old : %s",
mach_error_string(result));
}
PrintConfig(data);
CFRelease(data);
IOObjectRelease(gPlatform);
return 0;
}
示例15: NXOpenEventStatus
/* Open and Close */
NXEventHandle NXOpenEventStatus(void)
{
NXEventHandle handle = MACH_PORT_NULL;
register kern_return_t kr;
io_service_t service = MACH_PORT_NULL;
mach_port_t masterPort;
do {
kr = IOMasterPort( MACH_PORT_NULL, &masterPort );
if( kr != KERN_SUCCESS)
break;
service = IORegistryEntryFromPath( masterPort,
kIOServicePlane ":/IOResources/IOHIDSystem" );
if( !service)
break;
kr = IOServiceOpen( service,
mach_task_self(),
kIOHIDParamConnectType,
&handle);
IOObjectRelease( service );
} while( false );
return( handle );
}