aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--DomeKey/Mappings.h10
-rw-r--r--DomeKey/Mappings.m52
-rw-r--r--DomeKey/main.m9
3 files changed, 71 insertions, 0 deletions
diff --git a/DomeKey/Mappings.h b/DomeKey/Mappings.h
index ee878f1..2c46dde 100644
--- a/DomeKey/Mappings.h
+++ b/DomeKey/Mappings.h
@@ -7,7 +7,17 @@
//
#import <Foundation/Foundation.h>
+#include <notify.h>
+
+@protocol Reloadable
+
+- (void)reload;
+
+@end
@interface Mappings : NSObject
++ (void)observeReloadNotification;
++ (void)dispatchReload;
+
@end
diff --git a/DomeKey/Mappings.m b/DomeKey/Mappings.m
index bf68829..0d57fa6 100644
--- a/DomeKey/Mappings.m
+++ b/DomeKey/Mappings.m
@@ -8,6 +8,58 @@
#import "Mappings.h"
+#define NOTIFICATION_NAME_RELOAD "com.teddywing.DomeKey.reload_mappings"
+
+const CFStringRef CFNOTIFICATION_NAME_RELOAD = CFSTR(NOTIFICATION_NAME_RELOAD);
+
@implementation Mappings
+- (void)createXPCConnection
+{
+ NSXPCInterface *interface = [NSXPCInterface
+ interfaceWithProtocol:@protocol(Reloadable)];
+ NSXPCConnection *connection = [[NSXPCConnection alloc]
+ initWithServiceName:@"com.teddywing.DomeKey"];
+ [connection setRemoteObjectInterface:interface];
+ [connection resume];
+}
+
++ (void)observeReloadNotification
+{
+ CFNotificationCenterRef center = CFNotificationCenterGetDarwinNotifyCenter();
+
+ if (center) {
+ CFNotificationCenterAddObserver(
+ center,
+ NULL,
+ reload_mappings,
+ CFNOTIFICATION_NAME_RELOAD,
+ NULL,
+ CFNotificationSuspensionBehaviorDeliverImmediately
+ );
+ }
+}
+
+void reload_mappings(
+ CFNotificationCenterRef center,
+ void *observer,
+ CFStringRef name,
+ const void *object,
+ CFDictionaryRef userInfo
+) {
+ if (CFStringCompare(name, CFNOTIFICATION_NAME_RELOAD, 0) ==
+ kCFCompareEqualTo) {
+ // Reload mappings
+ NSLog(@"TODO: reload mappings");
+ }
+}
+
++ (void)dispatchReload
+{
+ if (notify_post(NOTIFICATION_NAME_RELOAD) != 0) {
+ // Notification failed
+ NSLog(@"Reload notification failed");
+ }
+}
+
@end
diff --git a/DomeKey/main.m b/DomeKey/main.m
index e61929c..5bda636 100644
--- a/DomeKey/main.m
+++ b/DomeKey/main.m
@@ -8,8 +8,15 @@
#import <Foundation/Foundation.h>
#import "AppDelegate.h"
+#import "Mappings.h"
int main(int argc, const char * argv[]) {
+ if (argc == 2 && strcmp(argv[1], "--reload-mappings") == 0) {
+ [Mappings dispatchReload];
+
+ return 0; // TODO: Return result of `notify_post`, and still log
+ }
+
@autoreleasepool {
[NSApplication sharedApplication];
AppDelegate *app = [[AppDelegate alloc] init];
@@ -18,6 +25,8 @@ int main(int argc, const char * argv[]) {
// insert code here...
NSLog(@"Hello, World!");
+ [Mappings observeReloadNotification];
+
[NSApp run];
}
return 0;