Using a pointer to pointer from Nu

5 views
Skip to first unread message

sasha

unread,
Sep 18, 2009, 3:46:49 AM9/18/09
to Programming Nu
Hello,

Could anybody please tell me, if it is possible to work with pointers
like void** from within Nu? Exactly I've recently tried to get the USB
device properties using Mac OS X IOKit API. So I did the following:
----------------
(import Cocoa)
(load "Nu:cocoa")

(function . (obj) (puts (obj description)))

(bridge function IOServiceMatching "@r*")
(bridge function IOServiceGetMatchingServices "i^v@^^v")
(bridge function IOIteratorNext "^v^v")
(bridge function IORegistryEntryCreateCFProperties "i^v^@^vi")
(bridge constant kIOMasterPortDefault "^v")

(set uinfo (IOServiceMatching "IOUSBDevice"))

;; HERE IS A PROBLEM
(set iter (NuPointer new)) ;?
(IOServiceGetMatchingServices kIOMasterPortDefault uinfo iter) ;?

(while (set dev (IOIteratorNext iter))) ;?
(set props (NuReference new))
(set allocator (NuPointer new))

(unless (IORegistryEntryCreateCFProperties dev props nil 0)
(. (props value))))
------------

The problem is with getting value of 'iter' from call to
IOServiceGetMatchingServices and using it in the calls to
IOIteratorNext. Is there some way to do it?

Thanks,
Aleksandr

sasha

unread,
Sep 18, 2009, 5:37:58 AM9/18/09
to Programming Nu
Oops!
I was wrong - iter is not a pointer, but plain unsigned int. The tags
have played a joke with me, so when I was looking for what was a type
of mach_port_t, they showed me a line from port.h file in the Kernel
framework. And I wasn't attentive enough to notice that. So here is
the working version:

(import Cocoa)
(load "Nu:cocoa")

(function . (obj) (puts (obj description)))

(bridge function IOServiceMatching "@r*")
(bridge function IOServiceGetMatchingServices "II@^I")
(bridge function IOIteratorNext "II")
(bridge function IORegistryEntryCreateCFProperties "II^@^VI")

(bridge constant kIOMasterPortDefault "I")

(set uinfo (IOServiceMatching "IOUSBDevice"))
(set p-iter (NuPointer new))

(unless (IOServiceGetMatchingServices kIOMasterPortDefault uinfo p-
iter)

(while (set dev (IOIteratorNext (p-iter value)))
(set r-props (NuReference new))
(set allocator (NuPointer new))
(unless (IORegistryEntryCreateCFProperties dev r-props nil 0)
(. (r-props value)))))
Reply all
Reply to author
Forward
0 new messages