"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "system/DetectNetworkConfigChangesSession.cpp" between
muscle8.20.zip and muscle8.30.zip

About: MUSCLE (Multi User Server Client Linking Environment) is a messaging server and networking API. The included server program ("muscled") lets its clients message each other, and/or store information in its serverside hierarchical database.

DetectNetworkConfigChangesSession.cpp  (muscle8.20):DetectNetworkConfigChangesSession.cpp  (muscle8.30)
skipping to change at line 96 skipping to change at line 96
// any pressure to minimize the number of DetectNetworkConfigChangesSessions it creates. // any pressure to minimize the number of DetectNetworkConfigChangesSessions it creates.
class DetectNetworkConfigChangesThread : public Thread class DetectNetworkConfigChangesThread : public Thread
{ {
public: public:
DetectNetworkConfigChangesThread() DetectNetworkConfigChangesThread()
: Thread(false) : Thread(false)
, _threadKeepGoing(false) , _threadKeepGoing(false)
, _isComputerSleeping(false) , _isComputerSleeping(false)
#ifdef __APPLE__ #ifdef __APPLE__
, _threadRunLoop(NULL) , _threadRunLoop(NULL)
, _rootPortPointer(NULL)
#elif WIN32 #elif WIN32
, _wakeupSignal(MY_INVALID_HANDLE_VALUE) , _wakeupSignal(MY_INVALID_HANDLE_VALUE)
#endif #endif
{ {
// empty // empty
} }
virtual ~DetectNetworkConfigChangesThread() virtual ~DetectNetworkConfigChangesThread()
{ {
MASSERT(_registeredSessions.IsEmpty(), "DetectNetworkConfigChangesThread d estroyed while sessions were still registered"); MASSERT(_registeredSessions.IsEmpty(), "DetectNetworkConfigChangesThread d estroyed while sessions were still registered");
skipping to change at line 140 skipping to change at line 141
} }
void SleepCallback(bool isAboutToSleep) void SleepCallback(bool isAboutToSleep)
{ {
if (isAboutToSleep != _isComputerSleeping) if (isAboutToSleep != _isComputerSleeping)
{ {
_isComputerSleeping = isAboutToSleep; _isComputerSleeping = isAboutToSleep;
static Message _aboutToSleepMessage(DNCCS_MESSAGE_ABOUT_TO_SLEEP); static Message _aboutToSleepMessage(DNCCS_MESSAGE_ABOUT_TO_SLEEP);
static Message _justWokeUpMessage(DNCCS_MESSAGE_JUST_WOKE_UP); static Message _justWokeUpMessage(DNCCS_MESSAGE_JUST_WOKE_UP);
(void) ThreadSafeSendMessageToSessions(MessageRef(isAboutToSleep ? &_ab outToSleepMessage : &_justWokeUpMessage, false)); (void) ThreadSafeSendMessageToSessions(DummyMessageRef(isAboutToSleep ? _aboutToSleepMessage : _justWokeUpMessage));
} }
} }
#ifdef __APPLE__ #ifdef __APPLE__
void SleepCallback(natural_t messageType, long messageArgument) void SleepCallback(natural_t messageType, long messageArgument)
{ {
switch(messageType) switch(messageType)
{ {
case kIOMessageCanSystemSleep: case kIOMessageCanSystemSleep:
/* Idle sleep is about to kick in. This message will not be sent for forced sleep. /* Idle sleep is about to kick in. This message will not be sent for forced sleep.
skipping to change at line 252 skipping to change at line 253
} }
void SignalInterfacesChanged(const Hashtable<String, Void> & optInterfaceName s) void SignalInterfacesChanged(const Hashtable<String, Void> & optInterfaceName s)
{ {
MessageRef msg; // demand-allocated MessageRef msg; // demand-allocated
if (optInterfaceNames.HasItems()) if (optInterfaceNames.HasItems())
{ {
msg = GetMessageFromPool(DNCCS_MESSAGE_INTERFACES_CHANGED); msg = GetMessageFromPool(DNCCS_MESSAGE_INTERFACES_CHANGED);
if (msg()) for (HashtableIterator<String, Void> iter(optInterfaceNames) ; iter.HasData(); iter++) msg()->AddString("if", iter.GetKey()); if (msg()) for (HashtableIterator<String, Void> iter(optInterfaceNames) ; iter.HasData(); iter++) msg()->AddString("if", iter.GetKey());
} }
static Message _msg(DNCCS_MESSAGE_INTERFACES_CHANGED);
ThreadSafeSendMessageToSessions(msg() ? msg : MessageRef(&_msg, false)); static Message _defaultMsg(DNCCS_MESSAGE_INTERFACES_CHANGED);
if (msg()) ThreadSafeSendMessageToSessions(msg);
else ThreadSafeSendMessageToSessions(DummyMessageRef(_defaultMsg));
} }
protected: protected:
virtual void InternalThreadEntry() virtual void InternalThreadEntry()
{ {
# if defined(MUSCLE_USE_DUMMY_DETECT_NETWORK_CONFIG_CHANGES_SESSION) # if defined(MUSCLE_USE_DUMMY_DETECT_NETWORK_CONFIG_CHANGES_SESSION)
// empty // empty
# elif defined(__APPLE__) # elif defined(__APPLE__)
_threadRunLoop = CFRunLoopGetCurrent(); _threadRunLoop = CFRunLoopGetCurrent();
skipping to change at line 311 skipping to change at line 314
CFRunLoopRemoveSource(CFRunLoopGetCurrent(), sourceRef, kCFRunLoopDefau ltMode); CFRunLoopRemoveSource(CFRunLoopGetCurrent(), sourceRef, kCFRunLoopDefau ltMode);
CFRelease(storeRef); CFRelease(storeRef);
CFRelease(sourceRef); CFRelease(sourceRef);
} }
if (powerNotifyRunLoopSource) CFRunLoopRemoveSource(CFRunLoopGetCurrent(), powerNotifyRunLoopSource, kCFRunLoopDefaultMode); if (powerNotifyRunLoopSource) CFRunLoopRemoveSource(CFRunLoopGetCurrent(), powerNotifyRunLoopSource, kCFRunLoopDefaultMode);
if (powerNotifyPortRef) if (powerNotifyPortRef)
{ {
(void) IODeregisterForSystemPower(&root_port); (void) IODeregisterForSystemPower(&root_port);
(void) IONotificationPortDestroy(powerNotifyPortRef); (void) IONotificationPortDestroy(powerNotifyPortRef);
} }
_rootPortPointer = NULL;
# elif defined(WIN32) # elif defined(WIN32)
#define WINDOW_CLASS_NAME _T("DetectNetworkConfigChangesThread_HiddenWndClass" ) #define WINDOW_CLASS_NAME _T("DetectNetworkConfigChangesThread_HiddenWndClass" )
#define WINDOW_MENU_NAME _T("DetectNetworkConfigChangesThread_MainMenu") #define WINDOW_MENU_NAME _T("DetectNetworkConfigChangesThread_MainMenu")
// Gotta create a hidden window to receive WM_POWERBROADCAST events, lame- o! // Gotta create a hidden window to receive WM_POWERBROADCAST events, lame- o!
// Register the window class for the main window. // Register the window class for the main window.
WNDCLASS window_class; memset(&window_class, 0, sizeof(window_class)); WNDCLASS window_class; memset(&window_class, 0, sizeof(window_class));
window_class.style = 0; window_class.style = 0;
window_class.lpfnWndProc = (WNDPROC) dnccsWindowHandler; window_class.lpfnWndProc = (WNDPROC) dnccsWindowHandler;
window_class.cbClsExtra = 0; window_class.cbClsExtra = 0;
skipping to change at line 370 skipping to change at line 373
MSG message; MSG message;
while(PeekMessage(&message, NULL, 0, 0, PM_REMOVE)) DispatchMe ssage(&message); while(PeekMessage(&message, NULL, 0, 0, PM_REMOVE)) DispatchMe ssage(&message);
} }
::HANDLE events[] = {olap.hEvent, _wakeupSignal}; ::HANDLE events[] = {olap.hEvent, _wakeupSignal};
DWORD waitResult = hiddenWindow ? MsgWaitForMultipleObjects(ARRAY ITEMS(events), events, false, INFINITE, QS_ALLINPUT) : WaitForMultipleObjects(AR RAYITEMS(events), events, false, INFINITE); DWORD waitResult = hiddenWindow ? MsgWaitForMultipleObjects(ARRAY ITEMS(events), events, false, INFINITE, QS_ALLINPUT) : WaitForMultipleObjects(AR RAYITEMS(events), events, false, INFINITE);
if (waitResult == WAIT_OBJECT_0) if (waitResult == WAIT_OBJECT_0)
{ {
// Serialized since the NotifyUnicast*Change() callbacks get c alled from a different thread // Serialized since the NotifyUnicast*Change() callbacks get c alled from a different thread
static Message _msg(DNCCS_MESSAGE_INTERFACES_CHANGED); static Message _msg(DNCCS_MESSAGE_INTERFACES_CHANGED);
ThreadSafeSendMessageToSessions(MessageRef(&_msg, false)); ThreadSafeSendMessageToSessions(DummyMessageRef(_msg));
} }
else if ((hiddenWindow)&&(waitResult == DWORD(WAIT_OBJECT_0+ARRAY ITEMS(events)))) else if ((hiddenWindow)&&(waitResult == DWORD(WAIT_OBJECT_0+ARRAY ITEMS(events))))
{ {
// Message received from Window-message-handler; go around the loop to process it // Message received from Window-message-handler; go around the loop to process it
} }
else else
{ {
// Anything else is an error and we should pack it in // Anything else is an error and we should pack it in
(void) CancelIPChangeNotify(&olap); (void) CancelIPChangeNotify(&olap);
_threadKeepGoing = false; _threadKeepGoing = false;
skipping to change at line 565 skipping to change at line 568
if (err == noErr) if (err == noErr)
{ {
CFDictionaryRef curVals = SCDynamicStoreCopyMultiple(ref, NULL, patternLis t); CFDictionaryRef curVals = SCDynamicStoreCopyMultiple(ref, NULL, patternLis t);
if (curVals) if (curVals)
{ {
CFDictionaryApplyFunction(curVals, StoreRecordFunc, &keyToInterfaceName ); CFDictionaryApplyFunction(curVals, StoreRecordFunc, &keyToInterfaceName );
CFRelease(curVals); CFRelease(curVals);
} }
} }
if (err == noErr) err = MoreSCErrorBoolean(SCDynamicStoreSetNotificationKeys( err = MoreSCErrorBoolean(SCDynamicStoreSetNotificationKeys(ref, NULL, pattern
ref, NULL, patternList)); List));
if (err == noErr) if (err == noErr)
{ {
rls = SCDynamicStoreCreateRunLoopSource(NULL, ref, 0); rls = SCDynamicStoreCreateRunLoopSource(NULL, ref, 0);
err = MoreSCError(rls); err = MoreSCError(rls);
} }
// Clean up. // Clean up.
CFQRelease(patterns[0]); CFQRelease(patterns[0]);
CFQRelease(patterns[1]); CFQRelease(patterns[1]);
CFQRelease(patterns[2]); CFQRelease(patterns[2]);
skipping to change at line 591 skipping to change at line 595
} }
*storeRef = ref; *storeRef = ref;
*sourceRef = rls; *sourceRef = rls;
assert( (err == noErr) == (*storeRef != NULL) ); assert( (err == noErr) == (*storeRef != NULL) );
assert( (err == noErr) == (*sourceRef != NULL) ); assert( (err == noErr) == (*sourceRef != NULL) );
return err; return err;
} }
static void SleepCallback(void * refCon, io_service_t /*service*/, natural_t mes static void SleepCallback(void * refCon, io_service_t /*service*/, natural_t mes
sageType, void * messageArgument) {((DetectNetworkConfigChangesThread *)refCon)- sageType, void * messageArgument) {static_cast<DetectNetworkConfigChangesThread
>SleepCallback(messageType, (long)messageArgument);} *>(refCon)->SleepCallback(messageType, (long)messageArgument);}
static void IPConfigChangedCallback(SCDynamicStoreRef store, CFArrayRef changedK static void IPConfigChangedCallback(SCDynamicStoreRef store, CFArrayRef changedK
eys, void * info) {((DetectNetworkConfigChangesThread *) info)->IPConfigChanged( eys, void * info) {static_cast<DetectNetworkConfigChangesThread *>(info)->IPConf
store, changedKeys);} igChanged(store, changedKeys);}
# endif // __APPLE__ # endif // __APPLE__
# if defined(WIN32) # if defined(WIN32)
# if !defined(MUSCLE_AVOID_NETIOAPI) # if !defined(MUSCLE_AVOID_NETIOAPI)
VOID __stdcall AddressCallback(IN PVOID context, IN PMIB_UNICASTIPADDRESS_ROW Ad dress OPTIONAL, IN MIB_NOTIFICATION_TYPE /*NotificationType*/) VOID __stdcall AddressCallback(IN PVOID context, IN PMIB_UNICASTIPADDRESS_ROW Ad dress OPTIONAL, IN MIB_NOTIFICATION_TYPE /*NotificationType*/)
{ {
if (Address != NULL) ((DetectNetworkConfigChangesThread *)context)->SignalInt erfacesChanged(Address->InterfaceIndex); if (Address != NULL) static_cast<DetectNetworkConfigChangesThread *>(context) ->SignalInterfacesChanged(Address->InterfaceIndex);
} }
VOID __stdcall InterfaceCallback(IN PVOID context, IN PMIB_IPINTERFACE_ROW inter faceRow, IN MIB_NOTIFICATION_TYPE /*NotificationType*/) VOID __stdcall InterfaceCallback(IN PVOID context, IN PMIB_IPINTERFACE_ROW inter faceRow, IN MIB_NOTIFICATION_TYPE /*NotificationType*/)
{ {
if (interfaceRow != NULL) ((DetectNetworkConfigChangesThread *)context)->Sign alInterfacesChanged(interfaceRow->InterfaceIndex); if (interfaceRow != NULL) static_cast<DetectNetworkConfigChangesThread *>(con text)->SignalInterfacesChanged(interfaceRow->InterfaceIndex);
} }
# endif # endif
static LRESULT CALLBACK dnccsWindowHandler(HWND hWnd, UINT message, WPARAM wPara m, LPARAM lParam) static LRESULT CALLBACK dnccsWindowHandler(HWND hWnd, UINT message, WPARAM wPara m, LPARAM lParam)
{ {
if (message == WM_POWERBROADCAST) if (message == WM_POWERBROADCAST)
{ {
switch(wParam) switch(wParam)
{ {
case PBT_APMRESUMEAUTOMATIC: case PBT_APMRESUMESUSPEND: case PBT_APMQUE RYSUSPENDFAILED: case PBT_APMRESUMECRITICAL: case PBT_APMRESUMEAUTOMATIC: case PBT_APMRESUMESUSPEND: case PBT_APMQUE RYSUSPENDFAILED: case PBT_APMRESUMECRITICAL:
((DetectNetworkConfigChangesThread *)(GetWindowLongPtr(hWnd, GWLP_US ERDATA)))->SleepCallback(false); reinterpret_cast<DetectNetworkConfigChangesThread *>(GetWindowLongPt r(hWnd, GWLP_USERDATA))->SleepCallback(false);
break; break;
case PBT_APMQUERYSUSPEND: case PBT_APMSUSPEND: case PBT_APMQUERYSUSPEND: case PBT_APMSUSPEND:
((DetectNetworkConfigChangesThread *)(GetWindowLongPtr(hWnd, GWLP_US ERDATA)))->SleepCallback(true); reinterpret_cast<DetectNetworkConfigChangesThread *>(GetWindowLongPt r(hWnd, GWLP_USERDATA))->SleepCallback(true);
break; break;
default: default:
// empty // empty
break; break;
} }
} }
return DefWindowProc(hWnd, message, wParam, lParam); return DefWindowProc(hWnd, message, wParam, lParam);
} }
# endif # endif
skipping to change at line 660 skipping to change at line 664
return ret; return ret;
} }
static status_t UnRegisterFromSingletonThread(DetectNetworkConfigChangesSession * s) static status_t UnRegisterFromSingletonThread(DetectNetworkConfigChangesSession * s)
{ {
MutexGuard mg(_singletonThreadMutex); MutexGuard mg(_singletonThreadMutex);
if (_singletonThread) if (_singletonThread)
{ {
status_t ret; status_t ret;
if ((_singletonThread)&&(_singletonThread->UnregisterSession(s).IsOK(ret)) &&(_singletonThread->HasRegisteredSessions() == false)) if ((_singletonThread->UnregisterSession(s).IsOK(ret))&&(_singletonThread- >HasRegisteredSessions() == false))
{ {
delete _singletonThread; delete _singletonThread;
_singletonThread = NULL; _singletonThread = NULL;
} }
return ret; return ret;
} }
else return B_DATA_NOT_FOUND; else return B_DATA_NOT_FOUND;
} }
#endif #endif
 End of changes. 12 change blocks. 
18 lines changed or deleted 22 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)