<NME> Driver.cpp
<BEF> #include "diagnostic_macros.hpp"

BEGIN_IOKIT_INCLUDE;
#include <IOKit/IOLib.h>
END_IOKIT_INCLUDE;

#include "Core.hpp"
#include "Driver.hpp"
#include "IOLogWrapper.hpp"

// ----------------------------------------------------------------------
// http://developer.apple.com/documentation/DeviceDrivers/Conceptual/WritingDeviceDriver/CPluPlusRuntime/chapter_2_section_3.html

// This convention makes it easy to invoke base class member functions.
#define super IOService
// You cannot use the "super" macro here, however, with the
//  OSDefineMetaClassAndStructors macro.
OSDefineMetaClassAndStructors(org_pqrs_driver_Karabiner, IOService);

// ----------------------------------------------------------------------
bool org_pqrs_driver_Karabiner::init(OSDictionary* dict) {
  IOLOG_INFO("init\n");

  bool res = super::init(dict);

  notifier_hookKeyboard_ = nullptr;
  notifier_unhookKeyboard_ = nullptr;
  notifier_hookPointing_ = nullptr;
  notifier_unhookPointing_ = nullptr;

  return res;
}

void org_pqrs_driver_Karabiner::free(void) {
  IOLOG_INFO("free\n");
  super::free();
}

IOService*
org_pqrs_driver_Karabiner::probe(IOService* provider, SInt32* score) {
  IOService* res = super::probe(provider, score);
  return res;
}

bool org_pqrs_driver_Karabiner::start(IOService* provider) {
  IOLOG_INFO("start\n");

  bool res = super::start(provider);
  if (!res) return res;

  org_pqrs_Karabiner::Core::start();
  if (!initialize_notification()) return false;

  // Publish ourselves so clients can find us
  registerService();

  return res;
}

void org_pqrs_driver_Karabiner::stop(IOService* provider) {
  IOLOG_INFO("stop\n");

  terminate_notification();
  org_pqrs_Karabiner::Core::stop();

  super::stop(provider);
}

{
  notifier_hookKeyboard_ = addMatchingNotification(gIOMatchedNotification,
                                                   serviceMatching("IOHIKeyboard"),
                                                   org_pqrs_KeyRemap4MacBook::Core::notifierfunc_hookKeyboard,
                                                   this, NULL, 0);
  if (notifier_hookKeyboard_ == NULL) {
    IOLOG_ERROR("initialize_notification notifier_hookKeyboard_ == NULL\n");
    IOLOG_ERROR("initialize_notification notifier_hookKeyboard_ == nullptr\n");
    return false;

  notifier_unhookKeyboard_ = addMatchingNotification(gIOTerminatedNotification,
                                                     serviceMatching("IOHIKeyboard"),
                                                     org_pqrs_KeyRemap4MacBook::Core::notifierfunc_unhookKeyboard,
                                                     this, NULL, 0);
  if (notifier_unhookKeyboard_ == NULL) {
    IOLOG_ERROR("initialize_notification notifier_unhookKeyboard_ == NULL\n");
    IOLOG_ERROR("initialize_notification notifier_unhookKeyboard_ == nullptr\n");
    return false;
  }
  // ----------------------------------------
  notifier_hookPointing_ = addMatchingNotification(gIOMatchedNotification,
                                                   serviceMatching("IOHIPointing"),
                                                   org_pqrs_KeyRemap4MacBook::Core::notifierfunc_hookPointing,
                                                   this, NULL, 0);
  if (notifier_hookPointing_ == NULL) {
    IOLOG_ERROR("initialize_notification notifier_hookPointing_ == NULL\n");
    IOLOG_ERROR("initialize_notification notifier_hookPointing_ == nullptr\n");
    return false;

  notifier_unhookPointing_ = addMatchingNotification(gIOTerminatedNotification,
                                                     serviceMatching("IOHIPointing"),
                                                     org_pqrs_KeyRemap4MacBook::Core::notifierfunc_unhookPointing,
                                                     this, NULL, 0);
  if (notifier_unhookPointing_ == NULL) {
    IOLOG_ERROR("initialize_notification notifier_unhookPointing_ == NULL\n");
    IOLOG_ERROR("initialize_notification notifier_unhookPointing_ == nullptr\n");
    return false;
  }

  return true;
}

void org_pqrs_driver_Karabiner::terminate_notification(void) {
  if (notifier_hookKeyboard_) notifier_hookKeyboard_->remove();
  if (notifier_unhookKeyboard_) notifier_unhookKeyboard_->remove();
  if (notifier_hookPointing_) notifier_hookPointing_->remove();
  if (notifier_unhookPointing_) notifier_unhookPointing_->remove();
}

<MSG> rename Core::notifierfunc_* to Core::notification_callback_*

<DFF> @@ -69,7 +69,7 @@ org_pqrs_driver_KeyRemap4MacBook::initialize_notification(void)
 {
   notifier_hookKeyboard_ = addMatchingNotification(gIOMatchedNotification,
                                                    serviceMatching("IOHIKeyboard"),
-                                                   org_pqrs_KeyRemap4MacBook::Core::notifierfunc_hookKeyboard,
+                                                   org_pqrs_KeyRemap4MacBook::Core::notification_callback_hookKeyboard,
                                                    this, NULL, 0);
   if (notifier_hookKeyboard_ == NULL) {
     IOLOG_ERROR("initialize_notification notifier_hookKeyboard_ == NULL\n");
@@ -78,7 +78,7 @@ org_pqrs_driver_KeyRemap4MacBook::initialize_notification(void)
 
   notifier_unhookKeyboard_ = addMatchingNotification(gIOTerminatedNotification,
                                                      serviceMatching("IOHIKeyboard"),
-                                                     org_pqrs_KeyRemap4MacBook::Core::notifierfunc_unhookKeyboard,
+                                                     org_pqrs_KeyRemap4MacBook::Core::notification_callback_unhookKeyboard,
                                                      this, NULL, 0);
   if (notifier_unhookKeyboard_ == NULL) {
     IOLOG_ERROR("initialize_notification notifier_unhookKeyboard_ == NULL\n");
@@ -88,7 +88,7 @@ org_pqrs_driver_KeyRemap4MacBook::initialize_notification(void)
   // ----------------------------------------
   notifier_hookPointing_ = addMatchingNotification(gIOMatchedNotification,
                                                    serviceMatching("IOHIPointing"),
-                                                   org_pqrs_KeyRemap4MacBook::Core::notifierfunc_hookPointing,
+                                                   org_pqrs_KeyRemap4MacBook::Core::notification_callback_hookPointing,
                                                    this, NULL, 0);
   if (notifier_hookPointing_ == NULL) {
     IOLOG_ERROR("initialize_notification notifier_hookPointing_ == NULL\n");
@@ -97,7 +97,7 @@ org_pqrs_driver_KeyRemap4MacBook::initialize_notification(void)
 
   notifier_unhookPointing_ = addMatchingNotification(gIOTerminatedNotification,
                                                      serviceMatching("IOHIPointing"),
-                                                     org_pqrs_KeyRemap4MacBook::Core::notifierfunc_unhookPointing,
+                                                     org_pqrs_KeyRemap4MacBook::Core::notification_callback_unhookPointing,
                                                      this, NULL, 0);
   if (notifier_unhookPointing_ == NULL) {
     IOLOG_ERROR("initialize_notification notifier_unhookPointing_ == NULL\n");

{'addition_count': 4, 'commit_subject': 'rename Core::notifierfunc_* to Core::notification_callback_*', 'deletion_count': 4, 'file_extension': '.cpp', 'lang': 'cpp', 'license': 'unlicense', 'repo_name': 'tekezo/Karabiner'}