本文整理汇总了C++中IOServiceOpen函数的典型用法代码示例。如果您正苦于以下问题:C++ IOServiceOpen函数的具体用法?C++ IOServiceOpen怎么用?C++ IOServiceOpen使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了IOServiceOpen函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: IOAccelCreateAccelID
IOReturn IOAccelCreateAccelID(IOOptionBits options, IOAccelID * identifier)
{
IOReturn err;
if (!idConnect)
{
io_service_t
service = IORegistryEntryFromPath(kIOMasterPortDefault,
kIOServicePlane ":/IOResources/IODisplayWrangler");
if (service)
{
err = IOServiceOpen(service, mach_task_self(), 0, &idConnect);
IOObjectRelease(service);
}
}
if (!idConnect)
return (kIOReturnNotReady);
uint64_t inData[] = { options, *identifier };
uint64_t outData;
uint32_t outLen = 1;
err = IOConnectCallScalarMethod(idConnect, kAlloc,
inData, arrayCnt(inData),
&outData, &outLen);
*identifier = (IOAccelID) outData;
return (err);
}
示例3: connectSmartBatteryManager
io_connect_t connectSmartBatteryManager(uint32_t options, IOReturn *outret)
{
io_service_t smartbattman_entry = MACH_PORT_NULL;
io_connect_t manager_connect = MACH_PORT_NULL;
IOReturn ret;
smartbattman_entry = IOServiceGetMatchingService( MACH_PORT_NULL,
IOServiceNameMatching(kBatteryManagerName) );
if (MACH_PORT_NULL == smartbattman_entry) {
return MACH_PORT_NULL;
}
ret = IOServiceOpen( smartbattman_entry, /* service */
mach_task_self(), /* owning task */
options, /* type - kBatteryExclusiveAccessType or not*/
&manager_connect); /* connect */
if (outret) *outret = ret;
if(kIOReturnSuccess != ret) {
return MACH_PORT_NULL;
}
IOObjectRelease(smartbattman_entry);
return manager_connect;
}
示例4: PCIDriver_setupDriver
int PCIDriver_setupDriver()
{
kern_return_t kern_result;
io_iterator_t iterator;
bool driverFound = false;
io_service_t local_driver_service;
// get services
kern_result = IOServiceGetMatchingServices(kIOMasterPortDefault, IOServiceMatching(kPcmMsrDriverClassName), &iterator);
if (kern_result != KERN_SUCCESS) {
fprintf(stderr, "[error] IOServiceGetMatchingServices returned 0x%08x\n", kern_result);
return kern_result;
}
// find service
while ((local_driver_service = IOIteratorNext(iterator)) != IO_OBJECT_NULL) {
driverFound = true;
break;
}
if (driverFound == false) {
fprintf(stderr, "[error] No matching drivers found \"%s\".\n", kPcmMsrDriverClassName);
return KERN_FAILURE;
}
IOObjectRelease(iterator);
// connect to service
kern_result = IOServiceOpen(local_driver_service, mach_task_self(), 0, &PCIDriver_connect);
if (kern_result != KERN_SUCCESS) {
fprintf(stderr, "[error] IOServiceOpen returned 0x%08x\n", kern_result);
return kern_result;
}
return KERN_SUCCESS;
}
示例5: IOAccelCreateSurface
IOReturn IOAccelCreateSurface( io_service_t accelerator, UInt32 wID, eIOAccelSurfaceModeBits modebits,
IOAccelConnect *connect )
{
IOReturn kr;
io_connect_t window = MACH_PORT_NULL;
*connect = NULL;
/* Create a context */
kr = IOServiceOpen( accelerator,
mach_task_self(),
kIOAccelSurfaceClientType,
&window );
if( kr != kIOReturnSuccess)
{
return kr;
}
/* Set the window id */
uint64_t data[] = { wID, modebits };
kr = IOConnectCallScalarMethod(window, kIOAccelSurfaceSetIDMode,
data, arrayCnt(data), NULL, NULL);
if(kr != kIOReturnSuccess)
{
IOServiceClose(window);
return kr;
}
*connect = (IOAccelConnect) (uintptr_t) window;
return kIOReturnSuccess;
}
示例6: hook_get_pointer_acceleration_multiplier
UIOHOOK_API long int hook_get_pointer_acceleration_multiplier() {
#if defined USE_IOKIT || defined USE_COREFOUNDATION
bool successful = false;
double multiplier;
#endif
long int value = -1;
#ifdef USE_IOKIT
if (!successful) {
io_service_t service = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching(kIOHIDSystemClass));
if (service) {
kern_return_t kren_ret = kIOReturnError;
io_connect_t connection;
kren_ret = IOServiceOpen(service, mach_task_self(), kIOHIDParamConnectType, &connection);
if (kren_ret == kIOReturnSuccess) {
// IOByteCount size = sizeof(multiplier);
kren_ret = IOHIDGetAccelerationWithKey(connection, CFSTR(kIOHIDMouseAccelerationType), &multiplier);
if (kren_ret == kIOReturnSuccess) {
// Calculate the greatest common factor.
unsigned long denominator = 1000000, d = denominator;
unsigned long numerator = multiplier * denominator, gcf = numerator;
while (d != 0) {
unsigned long i = gcf % d;
gcf = d;
d = i;
}
value = denominator / gcf;
successful = true;
logger(LOG_LEVEL_INFO, "%s [%u]: IOHIDGetAccelerationWithKey: %li.\n",
__FUNCTION__, __LINE__, value);
}
}
}
}
#endif
#ifdef USE_COREFOUNDATION
if (!successful) {
CFTypeRef pref_val = CFPreferencesCopyValue(CFSTR("com.apple.mouse.scaling"), kCFPreferencesAnyApplication, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
if (pref_val != NULL && CFGetTypeID(pref_val) == CFNumberGetTypeID()) {
if (CFNumberGetValue((CFNumberRef) pref_val, kCFNumberSInt32Type, &multiplier)) {
value = (long) multiplier;
logger(LOG_LEVEL_INFO, "%s [%u]: CFPreferencesCopyValue: %li.\n",
__FUNCTION__, __LINE__, value);
}
}
}
#endif
return value;
}
示例7: IOServiceMatching
kern_return_t
CPUTemp::SMCOpen(void)
{
kern_return_t result;
io_iterator_t iterator;
io_object_t device;
CFMutableDictionaryRef matchingDictionary = IOServiceMatching("AppleSMC");
result = IOServiceGetMatchingServices(kIOMasterPortDefault, matchingDictionary, &iterator);
if (result != kIOReturnSuccess)
{
printf("Error: IOServiceGetMatchingServices() = %08x\n", result);
return 1;
}
device = IOIteratorNext(iterator);
IOObjectRelease(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;
}
示例8: 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;
}
示例9: connect_to_keystore
static io_connect_t connect_to_keystore(void)
{
io_registry_entry_t apple_key_bag_service;
kern_return_t result;
io_connect_t keystore = MACH_PORT_NULL;
apple_key_bag_service = IOServiceGetMatchingService(kIOMasterPortDefault,
IOServiceMatching(kAppleKeyStoreServiceName));
if (apple_key_bag_service == IO_OBJECT_NULL) {
fprintf(stderr, "Failed to get service.\n");
return keystore;
}
result = IOServiceOpen(apple_key_bag_service, mach_task_self(), 0, &keystore);
if (KERN_SUCCESS != result)
fprintf(stderr, "Failed to open keystore\n");
if (keystore != MACH_PORT_NULL) {
IOReturn kernResult = IOConnectCallMethod(keystore,
kAppleKeyStoreUserClientOpen, NULL, 0, NULL, 0, NULL, NULL,
NULL, NULL);
if (kernResult) {
fprintf(stderr, "Failed to open AppleKeyStore: %x\n", kernResult);
}
}
return keystore;
}
示例10: main
int main(int argc, char** argv) {
char* service_name = "IntelAccelerator";
int client_type = 4;
io_service_t service = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching(service_name));
if (service == MACH_PORT_NULL) {
printf("can't find service\n");
return 0;
}
IOServiceOpen(service, mach_task_self(), client_type, &conn);
if (conn == MACH_PORT_NULL) {
printf("can't connect to service\n");
return 0;
}
pthread_t t;
io_connect_t arg = conn;
pthread_create(&t, NULL, (void*) go, (void*) &arg);
usleep(100000);
start = 1;
close_it(conn);
pthread_join(t, NULL);
return 0;
}
示例11: 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;
}
示例12: main
int main(int argc, char** argv) {
char* service_name = "AppleOscarGyro";
int client_type = 0;
io_service_t service = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching(service_name));
if (service == MACH_PORT_NULL) {
printf("can't find service\n");
return 0;
}
IOServiceOpen(service, mach_task_self(), client_type, &conn);
if (conn == MACH_PORT_NULL) {
printf("can't connect to service\n");
return 0;
}
OSSpinLockLock(&lock);
pthread_t t;
io_connect_t arg = conn;
pthread_create(&t, NULL, (void*) go, (void*) &arg);
usleep(100000);
OSSpinLockUnlock(&lock);
close_it(conn);
pthread_join(t, NULL);
return 0;
}
示例13: 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 );
}
示例14: open_and_connect_user_client
io_connect_t open_and_connect_user_client(char* service_name, int type) {
kern_return_t err;
io_connect_t conn = MACH_PORT_NULL;
CFMutableDictionaryRef matching = IOServiceMatching("IOGraphicsAccelerator2");
if(!matching){
printf("unable to create service matching dictionary\n");
return conn;
}
io_iterator_t iterator;
err = IOServiceGetMatchingServices(kIOMasterPortDefault, matching, &iterator);
if (err != KERN_SUCCESS){
printf("no matches\n");
return conn;
}
io_service_t service = IOIteratorNext(iterator);
if (service == IO_OBJECT_NULL){
printf("unable to find service\n");
return conn;
}
printf("got service: %x\n", service);
err = IOServiceOpen(service, mach_task_self(), type, &conn);
if (err != KERN_SUCCESS){
printf("unable to get user client connection\n");
return MACH_PORT_NULL;
}
//getchar();
printf("got userclient connection: %x\n", conn);
return conn;
}
示例15: printMsgBuffer
void printMsgBuffer(io_service_t service)
{
kern_return_t ret;
io_connect_t connect = 0;
#if __LP64__
mach_vm_address_t address;
mach_vm_size_t size;
#else
vm_address_t address;
vm_size_t size;
#endif
ret = IOServiceOpen(service, mach_task_self(), 0, &connect);
if (ret != KERN_SUCCESS) {
printf("error: IOServiceOpen returned 0x%08x\n", ret);
goto failure;
}
ret = IOConnectMapMemory(connect, kVoodooHDAMemoryMessageBuffer, mach_task_self(), &address, &size,
kIOMapAnywhere | kIOMapDefaultCache);
if (ret != kIOReturnSuccess) {
printf("error: IOConnectMapMemory returned 0x%08x\n", ret);
goto failure;
}
printf("%s\n", (char *) address);
failure:
if (connect) {
ret = IOServiceClose(connect);
if (ret != KERN_SUCCESS)
printf("warning: IOServiceClose returned 0x%08x\n", ret);
}
}