[MacRuby] #1049: Can't get the event path from FSEventStreamCallback
#1049: Can't get the event path from FSEventStreamCallback ---------------------------+------------------------------------------------ Reporter: haxie1@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: ---------------------------+------------------------------------------------ MacRuby 0.9 r5024 BridgeSupport Preview 2 {{{ framework 'Foundation' framework 'CoreServices' callback = Proc.new do |stream, callback_info, numb_events, paths, flags, ids| puts "callback" puts paths #Pointer puts paths.type #C paths.cast!("@") puts paths[0] #NSCFArray paths[0].count #crash end context = nil watchPath = ["/Users/Shared"] stream = FSEventStreamCreate(KCFAllocatorDefault, callback, context, watchPath, KFSEventStreamEventIdSinceNow, 0.3, KFSEventStreamCreateFlagUseCFTypes) if !stream puts "Failed" exit 1 end queue = Dispatch::Queue.new("fseventqueue") p = queue.dispatch_object FSEventStreamSetDispatchQueue(stream, p) if ! FSEventStreamStart(stream) puts "Failed to start" exit 1 end trap("INT") { FSEventStreamStop(stream) FSEventStreamInvalidate(stream) exit 0 } Dispatch::Queue.main.run }}} When I run this, I get called back when /Users/Shared changes, but my callbacks 'paths' argument doesn't have any useful data. If I cast the paths Pointer to an object I get an NSCFArray, but calling anything on it throws an exception (NoMethodError). Am I doing it wrong, or is the callbacks 'paths' param pointing to the great unknown? -- Ticket URL: <http://www.macruby.org/trac/ticket/1049> MacRuby <http://macruby.org/>
#1049: Can't get the event path from FSEventStreamCallback ---------------------------+------------------------------------------------ Reporter: haxie1@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: ---------------------------+------------------------------------------------ Comment(by lsansonetti@…): The callback is defined like this: {{{ typedef void ( *FSEventStreamCallback )( ConstFSEventStreamRef streamRef, void *clientCallBackInfo, size_t numEvents, void *eventPaths, const FSEventStreamEventFlags eventFlags[], const FSEventStreamEventId eventIds[]); }}} Here, eventPaths is a void pointer, so MacRuby will give you a Pointer object. However, apparently, it looks like FSEvents will yield an NSArray instead, in this snippet. In C, one would simply cast eventPaths as an NSArray, but in MacRuby, this isn't possible. Using #cast! on the Pointer will simply change the pointer type, and in your case, you're getting what an NSArray structure points to as its first pointer field, which is the isa (class). -- Ticket URL: <http://www.macruby.org/trac/ticket/1049#comment:1> MacRuby <http://macruby.org/>
#1049: Can't get the event path from FSEventStreamCallback ---------------------------+------------------------------------------------ Reporter: haxie1@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: ---------------------------+------------------------------------------------ Comment(by lsansonetti@…): I'm afraid this cannot be fixed in MacRuby, and should be done by BridgeSupport. -- Ticket URL: <http://www.macruby.org/trac/ticket/1049#comment:2> MacRuby <http://macruby.org/>
participants (1)
-
MacRuby