pike.git / src / modules / FSEvents / fsevents.cmod

version» Context lines:

pike.git/src/modules/FSEvents/fsevents.cmod:1: + /* -*- c -*- + || This file is part of Pike. For copyright information see COPYRIGHT. + || Pike is distributed under GPL, LGPL and MPL. See the file COPYING + || for more information. + */ +    /*! @module System    */      /*! @module FSEvents    */    - #include "global.h" - #include "interpret.h" +    #include "module.h" -  + #include "interpret.h"   #include "program.h" - #include "stralloc.h" - #include "svalue.h" +    #include "threads.h" - #include "object.h" +    #include "pike_types.h"   #include "builtin_functions.h"      #include "fsevents_config.h"      #define ADD_ICONST(name) do { \    add_integer_constant(#name, name, 0); \   } while(0);      #ifdef HAVE_FRAMEWORK_CORESERVICES   #import <CoreServices/CoreServices.h>   #endif /* HAVE_FRAMEWORK_CORESERVICES */      DECLARATIONS   #ifdef HAVE_FRAMEWORK_CORESERVICES    - void low_stop(); + void low_stop(void);   struct pike_string * string_from_cfstring(CFStringRef cfString);      struct event_callback_ctx   {    ConstFSEventStreamRef streamRef;    void *clientCallBackInfo;    size_t numEvents;    void *eventPaths;    const FSEventStreamEventFlags * eventFlags;    const FSEventStreamEventId * eventIds;
pike.git/src/modules/FSEvents/fsevents.cmod:136:    *! Flags that modify the behavior of the stream being created. See Apple's FSEvents documentation    *! for details of the various flags available.    */   PIKEFUN void create(array paths, float latency, int|void sinceWhen, int|void flags)   {    int idx = 0, cnt = 0;       THIS->isRunning = 0;    THIS->_latency = latency;    -  if(sinceWhen && sinceWhen->type == T_INT) +  if(sinceWhen && TYPEOF(*sinceWhen) == T_INT)    {    THIS->_sinceWhen = sinceWhen->u.integer;    }    else    {    THIS->_sinceWhen = kFSEventStreamEventIdSinceNow;    }    -  if(flags && flags->type == T_INT) +  if(flags && TYPEOF(*flags) == T_INT)    {    THIS->_flags = flags->u.integer;    }    else    {    THIS->_flags = kFSEventStreamCreateFlagNone;    }       THIS->_paths = CFArrayCreateMutable(NULL, 0, NULL);    CFRetain(THIS->_paths);       if(paths && paths->size)    {    for(idx = 0; idx < paths->size; idx++)    {    struct svalue sv;    CFStringRef str; -  if(ITEM(paths)[idx].type != T_STRING) continue; +  if(TYPEOF(ITEM(paths)[idx]) != T_STRING) continue;    sv = ITEM(paths)[idx];    push_svalue(&sv);    f_string_to_utf8(1);    str = CFStringCreateWithBytes(NULL, (const UInt8 *)(Pike_sp[-1].u.string->str), (CFIndex)Pike_sp[-1].u.string->len, kCFStringEncodingUTF8, false);    pop_stack();    CFArrayInsertValueAtIndex( (CFMutableArrayRef)THIS->_paths, cnt, str);    cnt++;    }    } -  -  pop_n_elems(args); -  -  return; +    }      /*! @decl void add_path(string path)    *! Add a path to the monitor list.    *!    *! @param path    *!    *! @note    *! this can only be called when the monitor is stopped.    */
pike.git/src/modules/FSEvents/fsevents.cmod:203:       if(path && path->len)    {    int size;    CFStringRef str;    f_string_to_utf8(1);    str = CFStringCreateWithBytes(NULL, (const UInt8 *)(Pike_sp[-1].u.string->str), (CFIndex)Pike_sp[-1].u.string->len, kCFStringEncodingUTF8, false);    size = CFArrayGetCount(THIS->_paths);    CFArrayInsertValueAtIndex( (CFMutableArrayRef)THIS->_paths, size, str);    } -  pop_stack(); +    }      /*! @decl void set_callback(function callback)    *! Sets the function that will be called when a file notification event is received.    *!    *! The method signature for the callback is:    *!    *! void event_callback(string path, int flags, int event_id)    */   PIKEFUN void set_callback(function callback)   {    assign_svalue(&THIS->callback_func, callback); -  pop_stack(); +    }      /*    * TODO we should allow the runloop to be specified.    */      /*! @decl void start()    *!    *! Requests that new events be delivered to this EventStream.    *!
pike.git/src/modules/FSEvents/fsevents.cmod:288:   }      /*! @decl void stop()    *! Stops watching for new events.    */   PIKEFUN void stop()   {    low_stop();   }    - void low_stop() + void low_stop(void)   {    if(THIS->isRunning)    {    FSEventStreamStop(THIS->stream);    FSEventStreamUnscheduleFromRunLoop(THIS->stream, THIS->runLoop, kCFRunLoopDefaultMode);    FSEventStreamInvalidate(THIS->stream);    FSEventStreamRelease(THIS->stream);    CFRelease(THIS->runLoop);    THIS->isRunning = 0;    }
pike.git/src/modules/FSEvents/fsevents.cmod:348:      static void do_event_callback(struct event_callback_ctx * ctx)   {    size_t cnt = 0;       for(cnt = 0; cnt < ctx->numEvents; cnt++)    {    CFStringRef eventPath;    struct pike_string * str;    const char * u8s; -  struct EventStream_struct * eventStreamObj; +  struct FSEvents_EventStream_struct * eventStreamObj;       eventPath = CFArrayGetValueAtIndex(ctx->eventPaths, (CFIndex)cnt);    str = string_from_cfstring(eventPath);    push_string(str);    f_utf8_to_string(1);    push_int(ctx->eventFlags[cnt]);    push_int(ctx->eventIds[cnt]); -  eventStreamObj = (struct EventStream_struct *)(ctx->clientCallBackInfo); +  eventStreamObj = (struct FSEvents_EventStream_struct *)(ctx->clientCallBackInfo);    apply_svalue(&eventStreamObj->callback_func, 3);    }   }      struct pike_string * string_from_cfstring(CFStringRef cfString)   {    const char *useUTF8StringPtr = NULL;    UInt8 *freeUTF8StringPtr = NULL;    struct pike_string * str = NULL;    long utf8Length;
pike.git/src/modules/FSEvents/fsevents.cmod:393:    * utf8Length contains the length of the UTF8 string.    */    str = make_shared_binary_string(useUTF8StringPtr, utf8Length);    }       if(freeUTF8StringPtr != NULL) { free(freeUTF8StringPtr); freeUTF8StringPtr = NULL; }       return str;   }    - #endif /* HAVE_FRAMEWORK_CORESERVICES */ -  +     INIT    {    }       EXIT    {   #ifdef HAVE_FRAMEWORK_CORESERVICES    low_stop();    if(THIS->_paths) CFRelease(THIS->_paths);   #endif /* HAVE_FRAMEWORK_CORESERVICES */    }      }    -  + /*! @endclass +  */ +  + #endif /* HAVE_FRAMEWORK_CORESERVICES */ +    PIKE_MODULE_INIT   {    INIT;   /*! @decl constant kFSEventStreamEventFlagNone    */      /*! @decl constant kFSEventStreamEventFlagMustScanSubDirs    */      /*! @decl constant kFSEventStreamEventFlagUserDropped
pike.git/src/modules/FSEvents/fsevents.cmod:455:    */      /*! @decl constant kFSEventStreamEventFlagInodeMetaMod    *! Available in MacOS X 10.7 and newer.    */      /*! @decl constant kFSEventStreamEventFlagRenamed    *! Available in MacOS X 10.7 and newer.    */    - /*! @decl constant kFSEventStreamEventFlagModified + /*! @decl constant kFSEventStreamEventFlagItemModified    *! Available in MacOS X 10.7 and newer.    */      /*! @decl constant kFSEventStreamEventFlagFinderInfoMod    *! Available in MacOS X 10.7 and newer.    */      /*! @decl constant kFSEventStreamEventFlagChangeOwner    *! Available in MacOS X 10.7 and newer.    */
pike.git/src/modules/FSEvents/fsevents.cmod:507:   /*! @decl constant kFSEventStreamCreateFlagNone    */      /*! @decl constant kFSEventStreamEventIdSinceNow    */      #if HAVE_DECL_KFSEVENTSTREAMEVENTFLAGNONE    ADD_ICONST(kFSEventStreamEventFlagNone);   #endif    - #if HAVE_DECL_KFSEVENTSTREAMEVENTMUSTSCANSUBDIRS + #if HAVE_DECL_KFSEVENTSTREAMEVENTFLAGMUSTSCANSUBDIRS    ADD_ICONST(kFSEventStreamEventFlagMustScanSubDirs);   #endif      #if HAVE_DECL_KFSEVENTSTREAMEVENTFLAGUSERDROPPED    ADD_ICONST(kFSEventStreamEventFlagUserDropped);   #endif      #if HAVE_DECL_KFSEVENTSTREAMEVENTFLAGKERNELDROPPED    ADD_ICONST(kFSEventStreamEventFlagKernelDropped);   #endif
pike.git/src/modules/FSEvents/fsevents.cmod:619:    ADD_ICONST(kFSEventStreamEventIdSinceNow);   #endif      }      PIKE_MODULE_EXIT   {    EXIT;   }    - /*! @endclass -  */ -  +    /*! @endmodule    */      /*! @endmodule    */