OpenAFS
OpenAFS distributed network file system
/cygdrive/c/src/openafs/openafs.git/repo/src/platform/DARWIN/growlagent/GrowlDefinesInternal.h
00001 //
00002 //  GrowlDefinesInternal.h
00003 //  Growl
00004 //
00005 //  Created by Karl Adam on Mon May 17 2004.
00006 //  Copyright (c) 2004 the Growl Project. All rights reserved.
00007 //
00008 
00009 #ifndef _GROWL_GROWLDEFINESINTERNAL_H
00010 #define _GROWL_GROWLDEFINESINTERNAL_H
00011 
00012 #include <CoreFoundation/CoreFoundation.h>
00013 #include <sys/types.h>
00014 #include <unistd.h>
00015 
00016 #ifdef __OBJC__
00017 #define XSTR(x) (@x)
00018 #else /* !__OBJC__ */
00019 #define XSTR CFSTR
00020 #endif /* __OBJC__ */
00021 
00036 #ifndef NSINTEGER_DEFINED
00037 typedef int NSInteger;
00038 typedef unsigned int NSUInteger;
00039 #define NSINTEGER_DEFINED
00040 #endif
00041 
00046 #ifndef CGFLOAT_DEFINED
00047 typedef float CGFloat;
00048 #define CGFLOAT_IS_DOUBLE 0
00049 #define CGFLOAT_DEFINED
00050 #endif
00051 
00064 #if CGFLOAT_IS_DOUBLE
00065 #define GrowlCGFloatCeiling(x) ceil(x)
00066 #define GrowlCGFloatAbsoluteValue(x) fabs(x)
00067 #define GrowlCGFloatFloor(x) floor(x)
00068 #else
00069 #define GrowlCGFloatCeiling(x) ceilf(x)
00070 #define GrowlCGFloatAbsoluteValue(x) fabsf(x)
00071 #define GrowlCGFloatFloor(x) floorf(x)
00072 #endif
00073 
00077 #define GROWL_TCP_PORT  23052
00078 
00082 #define GROWL_UDP_PORT  9887
00083 
00087 #define GROWL_PROTOCOL_VERSION  1
00088 
00092 #define GROWL_PROTOCOL_VERSION_AES128   2
00093 
00097 #define GROWL_TYPE_REGISTRATION                 0
00098 
00101 #define GROWL_TYPE_NOTIFICATION                 1
00102 
00105 #define GROWL_TYPE_REGISTRATION_SHA256  2
00106 
00109 #define GROWL_TYPE_NOTIFICATION_SHA256  3
00110 
00113 #define GROWL_TYPE_REGISTRATION_NOAUTH  4
00114 
00117 #define GROWL_TYPE_NOTIFICATION_NOAUTH  5
00118 
00119 #define ATTRIBUTE_PACKED __attribute((packed))
00120 
00125 struct GrowlNetworkPacket {
00126         unsigned char version;
00127         unsigned char type;
00128 } ATTRIBUTE_PACKED;
00129 
00141 struct GrowlNetworkRegistration {
00142         struct GrowlNetworkPacket common;
00143         /*      This name is used both internally and in the Growl
00144          *       preferences.
00145          *
00146          *       The application name should remain stable between different versions
00147          *       and incarnations of your application.
00148          *       For example, "SurfWriter" is a good app name, whereas "SurfWriter 2.0"
00149          *       and "SurfWriter Lite" are not.
00150          *
00151          *       In addition to being unsigned, the application name length is in
00152          *       network byte order.
00153          */
00154         unsigned short appNameLen;
00155         /*      These names are used both internally and in the Growl
00156          *       preferences. For this reason, they should be human-readable.
00157          */
00158         unsigned char numAllNotifications;
00159 
00160         unsigned char numDefaultNotifications;
00161         /*      The variable-sized data of a registration is:
00162          *       - The application name, in UTF-8 encoding, for appNameLen bytes.
00163          *       - The list of all notification names.
00164          *       - The list of default notifications, as 8-bit unsigned indices into the list of all notifications.
00165          *       - The MD5/SHA256 checksum of all the data preceding the checksum.
00166          *
00167          *       Each notification name is encoded as:
00168          *       - Length: two bytes, unsigned, network byte order.
00169          *       - Name: As many bytes of UTF-8-encoded text as the length says.
00170          *       And there are numAllNotifications of these.
00171          */
00172         unsigned char data[];
00173 } ATTRIBUTE_PACKED;
00174 
00188 struct GrowlNetworkNotification {
00189         struct GrowlNetworkPacket common;
00200         struct GrowlNetworkNotificationFlags {
00201 #ifdef __BIG_ENDIAN__
00202                 unsigned reserved: 12;
00203                 signed   priority: 3;
00204                 unsigned sticky:   1;
00205 #else
00206                 unsigned sticky:   1;
00207                 signed   priority: 3;
00208                 unsigned reserved: 12;
00209 #endif
00210         } ATTRIBUTE_PACKED flags; //size = 16 (12 + 3 + 1)
00211 
00212         /*      In addition to being unsigned, the notification name length
00213          *       is in network byte order.
00214          */
00215         unsigned short nameLen;
00216         /*      @discussion     In addition to being unsigned, the title length is in
00217          *       network byte order.
00218          */
00219         unsigned short titleLen;
00220         /*      In addition to being unsigned, the description length is in
00221          *       network byte order.
00222          */
00223         unsigned short descriptionLen;
00224         /*      In addition to being unsigned, the application name length
00225          *       is in network byte order.
00226          */
00227         unsigned short appNameLen;
00228         /*      The variable-sized data of a notification is:
00229          *       - Notification name, in UTF-8 encoding, for nameLen bytes.
00230          *       - Title, in UTF-8 encoding, for titleLen bytes.
00231          *       - Description, in UTF-8 encoding, for descriptionLen bytes.
00232          *       - Application name, in UTF-8 encoding, for appNameLen bytes.
00233          *       - The MD5/SHA256 checksum of all the data preceding the checksum.
00234          */
00235         unsigned char data[];
00236 } ATTRIBUTE_PACKED;
00237 
00244 #define GrowlEnabledKey                                 XSTR("GrowlEnabled")
00245 
00256 #define GROWL_SCREENSHOT_MODE                   XSTR("ScreenshotMode")
00257 
00263 #define GROWL_APP_LOCATION                              XSTR("AppLocation")
00264 
00270 #define GROWL_REMOTE_ADDRESS                    XSTR("RemoteAddress")
00271 
00276 #define GROWL_PREFPANE_BUNDLE_IDENTIFIER                XSTR("com.growl.prefpanel")
00277 
00281 #define GROWL_HELPERAPP_BUNDLE_IDENTIFIER       XSTR("com.Growl.GrowlHelperApp")
00282 
00287 #define GROWL_PREFPANE_NAME                                             XSTR("Growl.prefPane")
00288 #define PREFERENCE_PANES_SUBFOLDER_OF_LIBRARY   XSTR("PreferencePanes")
00289 #define PREFERENCE_PANE_EXTENSION                               XSTR("prefPane")
00290 
00291 //plug-in bundle filename extensions
00292 #define GROWL_PLUGIN_EXTENSION                  XSTR("growlPlugin")
00293 #define GROWL_PATHWAY_EXTENSION                 XSTR("growlPathway")
00294 #define GROWL_VIEW_EXTENSION                                    XSTR("growlView")
00295 #define GROWL_STYLE_EXTENSION                                   XSTR("growlStyle")
00296 
00297 /* --- These following macros are intended for plug-ins --- */
00298 
00304 #define SYNCHRONIZE_GROWL_PREFS() CFPreferencesAppSynchronize(CFSTR("com.Growl.GrowlHelperApp"))
00305 
00311 #define UPDATE_GROWL_PREFS() do { \
00312         SYNCHRONIZE_GROWL_PREFS(); \
00313         CFStringRef _key = CFSTR("pid"); \
00314         int pid = getpid(); \
00315         CFNumberRef _value = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &pid); \
00316         CFDictionaryRef userInfo = CFDictionaryCreate(kCFAllocatorDefault, (const void **)&_key, (const void **)&_value, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); \
00317         CFRelease(_value); \
00318         CFNotificationCenterPostNotification(CFNotificationCenterGetDistributedCenter(), \
00319                                                                                  CFSTR("GrowlPreferencesChanged"), \
00320                                                                                  CFSTR("GrowlUserDefaults"), \
00321                                                                                  userInfo, false); \
00322         CFRelease(userInfo); \
00323         } while(0)
00324 
00337 #define READ_GROWL_PREF_VALUE(key, domain, type, result) do {\
00338         CFDictionaryRef prefs = (CFDictionaryRef)CFPreferencesCopyAppValue((CFStringRef)domain, \
00339                                                                                                                                                 CFSTR("com.Growl.GrowlHelperApp")); \
00340         if (prefs) {\
00341                 if (CFDictionaryContainsKey(prefs, key)) {\
00342                         *result = (type)CFDictionaryGetValue(prefs, key); \
00343                         CFRetain(*result); \
00344                 } \
00345                 CFRelease(prefs); } \
00346         } while(0)
00347 
00357 #define WRITE_GROWL_PREF_VALUE(key, value, domain) do {\
00358         CFDictionaryRef staticPrefs = (CFDictionaryRef)CFPreferencesCopyAppValue((CFStringRef)domain, \
00359                                                                                                                                                          CFSTR("com.Growl.GrowlHelperApp")); \
00360         CFMutableDictionaryRef prefs; \
00361         if (staticPrefs == NULL) {\
00362                 prefs = CFDictionaryCreateMutable(NULL, 0, NULL, NULL); \
00363         } else {\
00364                 prefs = CFDictionaryCreateMutableCopy(NULL, 0, staticPrefs); \
00365                 CFRelease(staticPrefs); \
00366         }\
00367         CFDictionarySetValue(prefs, key, value); \
00368         CFPreferencesSetAppValue((CFStringRef)domain, prefs, CFSTR("com.Growl.GrowlHelperApp")); \
00369         CFRelease(prefs); } while(0)
00370 
00379 #define READ_GROWL_PREF_BOOL(key, domain, result) do {\
00380         CFBooleanRef boolValue = NULL; \
00381         READ_GROWL_PREF_VALUE(key, domain, CFBooleanRef, &boolValue); \
00382         if (boolValue) {\
00383                 *result = CFBooleanGetValue(boolValue); \
00384                 CFRelease(boolValue); \
00385         } } while(0)
00386 
00395 #define WRITE_GROWL_PREF_BOOL(key, value, domain) do {\
00396         WRITE_GROWL_PREF_VALUE(key, value ? kCFBooleanTrue : kCFBooleanFalse, domain); } while(0)
00397 
00406 #define READ_GROWL_PREF_INT(key, domain, result) do {\
00407         CFNumberRef intValue = NULL; \
00408         READ_GROWL_PREF_VALUE(key, domain, CFNumberRef, &intValue); \
00409         if (intValue) {\
00410                 CFNumberGetValue(intValue, kCFNumberIntType, result); \
00411                 CFRelease(intValue); \
00412         } } while(0)
00413 
00422 #define WRITE_GROWL_PREF_INT(key, value, domain) do {\
00423         CFNumberRef intValue = CFNumberCreate(NULL, kCFNumberIntType, &value); \
00424         WRITE_GROWL_PREF_VALUE(key, intValue, domain); \
00425         CFRelease(intValue); } while(0)
00426 
00435 #ifdef __LP64__
00436 #define READ_GROWL_PREF_FLOAT(key, domain, result) do {\
00437         CFNumberRef floatValue = NULL; \
00438         READ_GROWL_PREF_VALUE(key, domain, CFNumberRef, &floatValue); \
00439         if (floatValue) {\
00440                 CFNumberGetValue(floatValue, kCFNumberCGFloatType, result); \
00441                 CFRelease(floatValue); \
00442         } } while(0)
00443 #else
00444 #define READ_GROWL_PREF_FLOAT(key, domain, result) do {\
00445         CFNumberRef floatValue = NULL; \
00446         READ_GROWL_PREF_VALUE(key, domain, CFNumberRef, &floatValue); \
00447         if (floatValue) {\
00448                 CFNumberGetValue(floatValue, kCFNumberFloatType, result); \
00449                 CFRelease(floatValue); \
00450         } } while(0)
00451 #endif
00452 
00461 #ifdef __LP64__
00462 #define WRITE_GROWL_PREF_FLOAT(key, value, domain) do {\
00463         CFNumberRef floatValue = CFNumberCreate(NULL, kCFNumberCGFloatType, &value); \
00464         WRITE_GROWL_PREF_VALUE(key, floatValue, domain); \
00465         CFRelease(floatValue); } while(0)
00466 #else
00467 #define WRITE_GROWL_PREF_FLOAT(key, value, domain) do {\
00468         CFNumberRef floatValue = CFNumberCreate(NULL, kCFNumberFloatType, &value); \
00469         WRITE_GROWL_PREF_VALUE(key, floatValue, domain); \
00470         CFRelease(floatValue); } while(0)
00471 #endif
00472 
00473 
00479 #define GROWL_CLOSE_ALL_NOTIFICATIONS XSTR("GrowlCloseAllNotifications")
00480 
00481 #pragma mark Small utilities
00482 
00487 #define FLOAT_EQ(x,y) (((y - FLT_EPSILON) < x) && (x < (y + FLT_EPSILON)))
00488 
00489 #endif //ndef _GROWL_GROWLDEFINESINTERNAL_H
 All Data Structures Files Functions Variables