Discussion:
SystemConfiguration Callback
Frederik Seiffert
2005-02-17 12:55:20 UTC
Permalink
Hi!

I'm trying to get notifications about network configuration changes from
the SystemConfiguration framework in a Mach-O application. What I want
to do in RB is pretty much the same as this code:
<http://www.slamb.org/svn/repos/projects/netgrowler/SCDynamicStore.m>

While it is no problem to open the dynamic store with
SCDynamicStoreCreate passing a callback function with the RB AddressOf
operator, I'm not sure how to go about the
SCDynamicStoreCreateRunLoopSource call, which I seem to need in order
for the callback function to get called.

Is there a way to add a CFRunLoopSourceRef in RB? Or is there some other
way to get this working?

Thanks,
Frederik
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>
Charles Yeomans
2005-02-17 17:17:56 UTC
Permalink
Post by Frederik Seiffert
Hi!
I'm trying to get notifications about network configuration changes
from the SystemConfiguration framework in a Mach-O application. What I
<http://www.slamb.org/svn/repos/projects/netgrowler/SCDynamicStore.m>
While it is no problem to open the dynamic store with
SCDynamicStoreCreate passing a callback function with the RB AddressOf
operator, I'm not sure how to go about the
SCDynamicStoreCreateRunLoopSource call, which I seem to need in order
for the callback function to get called.
Is there a way to add a CFRunLoopSourceRef in RB? Or is there some
other way to get this working?
I expect that you can work with CFRunLoops in REALbasic, though I have
not tried it. The main problem is to make certain that your code
coexists with the app framework. My experience is that it's usually
possible to extend even low-level app functionality via declares. This
suggests that the framework is designed with considerable care --
something which is of course usually not visible in typical Rb use, but
which deserves to be acknowledged.

--------------
Charles Yeomans

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>
Charles Yeomans
2005-02-18 00:15:09 UTC
Permalink
Post by Charles Yeomans
Post by Frederik Seiffert
Is there a way to add a CFRunLoopSourceRef in RB? Or is there some
other way to get this working?
I expect that you can work with CFRunLoops in REALbasic, though I
have not tried it. The main problem is to make certain that your
code coexists with the app framework. My experience is that it's
usually possible to extend even low-level app functionality via
declares. This suggests that the framework is designed with
considerable care -- something which is of course usually not visible
in typical Rb use, but which deserves to be acknowledged.
Hi Charles,
thanks for the heads-up. :)
I just tried using CFRunLoopAddSource(CFRunLoopGetCurrent(), ...) in
REALbasic, but it doesn't seem to work: CFRunLoopGetCurrent() does
return some value, but my callback won't get called. I'll have to do
some more testing, but do you think it would be better to create and
run my own run loop? Would this work with RB's threading model? I'll
dig into this on the weekend, but I would appreciate any hints
beforehand.
I don't know, but I'd be interested in knowing what you find out.

--------------
Charles Yeomans

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>
support-9+jg12ILN6UkMvPuQOpXZQXbj/ (Christian Schmitz)
2005-02-18 01:35:23 UTC
Permalink
I just tried using CFRunLoopAddSource(CFRunLoopGetCurrent(), ...) in
REALbasic, but it doesn't seem to work: CFRunLoopGetCurrent() does
return some value, but my callback won't get called. I'll have to do
some more testing, but do you think it would be better to create and run
my own run loop? Would this work with RB's threading model?
It works, but not all events arrive while in debug mode.

Mfg
Christian
--
Nine thousand functions in one REALbasic plug-in. The MBS Plugin.
<http://www.monkeybreadsoftware.de/realbasic/plugins.shtml>
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>
Frederik Seiffert
2005-02-21 13:15:10 UTC
Permalink
Post by support-9+jg12ILN6UkMvPuQOpXZQXbj/ (Christian Schmitz)
I just tried using CFRunLoopAddSource(CFRunLoopGetCurrent(), ...) in
REALbasic, but it doesn't seem to work: CFRunLoopGetCurrent() does
return some value, but my callback won't get called. I'll have to do
some more testing, but do you think it would be better to create and run
my own run loop? Would this work with RB's threading model?
It works, but not all events arrive while in debug mode.
I'd be interested to know how you got it to work. For testing the
CFRunLoop stuff, I tried setting up a CFRunLoopTimer, but it doesn't
seem to fire (it should fire every second). I was using this code:

dim timer as Integer
Declare Function CFRunLoopGetCurrent Lib "CoreFoundation" () _
as Integer
Declare Sub CFRunLoopAddSource Lib "CoreFoundation" ( _
rl as Integer, _
source as Integer, _
mode as Integer)
declare function CFRunLoopTimerCreate lib "CoreFoundation" ( _
allocator as Integer, _
fireDate as Double, _
interval as Double, _
flags as Integer, _
order as Integer, _
callout as Ptr, _
context as Integer) as Integer
declare function CFAbsoluteTimeGetCurrent lib "CoreFoundation" () _
as Integer
declare sub CFRunLoopAddTimer lib "CoreFoundation" (_
rl as Integer, _
timer as Integer, _
mode as Integer)

timer = CFRunLoopTimerCreate(0, CFAbsoluteTimeGetCurrent(), 1, 0, _
0, AddressOf TimerCallBack, 0)
if timer <> 0 then
CFRunLoopAddTimer(CFRunLoopGetCurrent(), timer, _
NewCFStringMBS("kCFRunLoopCommonModes").Handle)
else
MsgBox "failed to create timer"
end if


TimerCallBack is a public function in a module like this:

Sub TimerCallBack(timer as Integer, info as Integer)
'typedef void (*CFRunLoopTimerCallBack) (
' CFRunLoopTimerRef timer,
' void *info
');
MsgBox "TimerCallBack!"
End Sub

Could the problem be the "kCFRunLoopCommonModes" string? It's a constant
in the CoreFoundation framework whose name is the same as the constant
itself. I guess it depends on whether Apple compares pointers or
strings. I tried loading the constant with SoftDeclareMBS from
CoreFoundation.framework but it cannot be found.

Thanks for your help.

Frederik
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>
Charles Yeomans
2005-02-21 17:09:58 UTC
Permalink
Post by Frederik Seiffert
Post by support-9+jg12ILN6UkMvPuQOpXZQXbj/ (Christian Schmitz)
I just tried using CFRunLoopAddSource(CFRunLoopGetCurrent(), ...) in
REALbasic, but it doesn't seem to work: CFRunLoopGetCurrent() does
return some value, but my callback won't get called. I'll have to do
some more testing, but do you think it would be better to create and run
my own run loop? Would this work with RB's threading model?
It works, but not all events arrive while in debug mode.
I'd be interested to know how you got it to work. For testing the
CFRunLoop stuff, I tried setting up a CFRunLoopTimer, but it doesn't
dim timer as Integer
Declare Function CFRunLoopGetCurrent Lib "CoreFoundation" () _
as Integer
Declare Sub CFRunLoopAddSource Lib "CoreFoundation" ( _
rl as Integer, _
source as Integer, _
mode as Integer)
declare function CFRunLoopTimerCreate lib "CoreFoundation" ( _
allocator as Integer, _
fireDate as Double, _
interval as Double, _
flags as Integer, _
order as Integer, _
callout as Ptr, _
context as Integer) as Integer
declare function CFAbsoluteTimeGetCurrent lib "CoreFoundation" () _
as Integer
declare sub CFRunLoopAddTimer lib "CoreFoundation" (_
rl as Integer, _
timer as Integer, _
mode as Integer)
timer = CFRunLoopTimerCreate(0, CFAbsoluteTimeGetCurrent(), 1, 0, _
0, AddressOf TimerCallBack, 0)
if timer <> 0 then
CFRunLoopAddTimer(CFRunLoopGetCurrent(), timer, _
NewCFStringMBS("kCFRunLoopCommonModes").Handle)
else
MsgBox "failed to create timer"
end if
Sub TimerCallBack(timer as Integer, info as Integer)
'typedef void (*CFRunLoopTimerCallBack) (
' CFRunLoopTimerRef timer,
' void *info
');
MsgBox "TimerCallBack!"
End Sub
Could the problem be the "kCFRunLoopCommonModes" string? It's a
constant in the CoreFoundation framework whose name is the same as the
constant itself. I guess it depends on whether Apple compares pointers
or strings. I tried loading the constant with SoftDeclareMBS from
CoreFoundation.framework but it cannot be found.
You have two problems. First, CFAbsoluteTimeGetCurrent returns a
Double, not an Integer. Second, pass the constant
"kCFRunLoopDefaultMode" in the mode parameter of CFRunLoopAddTimer.


Charles Yeomans

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>
Frederik Seiffert
2005-02-21 18:46:17 UTC
Permalink
Post by Charles Yeomans
Post by Frederik Seiffert
Could the problem be the "kCFRunLoopCommonModes" string? It's a
constant in the CoreFoundation framework whose name is the same as the
constant itself. I guess it depends on whether Apple compares pointers
or strings. I tried loading the constant with SoftDeclareMBS from
CoreFoundation.framework but it cannot be found.
You have two problems. First, CFAbsoluteTimeGetCurrent returns a
Double, not an Integer. Second, pass the constant
"kCFRunLoopDefaultMode" in the mode parameter of CFRunLoopAddTimer.
Ok, as I suspected the problem was the constant. Using the following
code to load the constant from the CoreFoundation framework all works
very well.

<http://support.realsoftware.com/listarchives/realbasic-nug/2004-04/msg03264.html>

Thanks for all the help!

Frederik
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

support-9+jg12ILN6UkMvPuQOpXZQXbj/ (Christian Schmitz)
2005-02-18 01:35:24 UTC
Permalink
Post by Frederik Seiffert
Hi!
I'm trying to get notifications about network configuration changes from
the SystemConfiguration framework in a Mach-O application. What I want
<http://www.slamb.org/svn/repos/projects/netgrowler/SCDynamicStore.m>
It's something I could add to my plugins...

Which already cover the stuff from the SystemConfiguration framework
people asked for...

Mfg
Christian
--
Nine thousand functions in one REALbasic plug-in. The MBS Plugin.
<http://www.monkeybreadsoftware.de/realbasic/plugins.shtml>
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>
Loading...