aboutsummaryrefslogtreecommitdiffstats
path: root/src/native
diff options
context:
space:
mode:
authorLyubomir Marinov <lyubomir.marinov@jitsi.org>2013-04-07 17:03:58 +0000
committerLyubomir Marinov <lyubomir.marinov@jitsi.org>2013-04-07 17:03:58 +0000
commitc2f63cbef175789688ea0fee137465447e3e37dc (patch)
tree61f4ee3ef4eff7e54a8aeb9f032bcdffc4f0506d /src/native
parent1b2f91a6db08f2ee44f9b8ba747c4a02ae7361c5 (diff)
downloadjitsi-c2f63cbef175789688ea0fee137465447e3e37dc.zip
jitsi-c2f63cbef175789688ea0fee137465447e3e37dc.tar.gz
jitsi-c2f63cbef175789688ea0fee137465447e3e37dc.tar.bz2
Sanitizes sysactivitynotifications.dll in order to make it easier to determine why it crashes.
Diffstat (limited to 'src/native')
-rw-r--r--src/native/build.xml37
-rw-r--r--src/native/sysactivity/net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications.cpp589
-rw-r--r--src/native/sysactivity/net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications.h87
3 files changed, 270 insertions, 443 deletions
diff --git a/src/native/build.xml b/src/native/build.xml
index 6a3e3ad..9a4fc00 100644
--- a/src/native/build.xml
+++ b/src/native/build.xml
@@ -597,18 +597,20 @@
<cc outtype="shared" name="gcc" outfile="${native_install_dir}/sysactivitynotifications"
objdir="${obj}">
- <!-- common compiler flags -->
+ <!-- Common compiler flags -->
+ <compilerarg value="-D_JNI_IMPLEMENTATION_" />
+ <compilerarg value="-m32" if="cross_32" unless="is.running.macos" />
+ <compilerarg value="-m64" if="cross_64" unless="is.running.macos" />
+ <compilerarg value="-O2" />
<compilerarg value="-Wall" />
<compilerarg value="-Wextra" />
- <compilerarg value="-m32" if="cross_32" unless="is.running.macos" />
- <compilerarg value="-m64" if="cross_64" unless="is.running.macos" />
+ <!-- Common linker flags -->
<linkerarg value="-m32" if="cross_32" unless="is.running.macos" />
<linkerarg value="-m64" if="cross_64" unless="is.running.macos" />
- <!-- Mac OS X specific flags -->
+ <!-- Mac OS X-specific flags -->
<compilerarg value="-mmacosx-version-min=10.5" if="is.running.macos"/>
- <compilerarg value="-O2" if="is.running.macos"/>
<compilerarg value="-arch" if="is.running.macos"/>
<compilerarg value="x86_64" if="is.running.macos"/>
<compilerarg value="-arch" if="is.running.macos"/>
@@ -636,12 +638,9 @@
<linkerarg value="-framework" if="is.running.macos" />
<linkerarg value="IOKit" if="is.running.macos" />
- <fileset dir="${src}/native/sysactivity"
- includes="*.m" if="is.running.macos"/>
-
- <!-- Linux specific flags -->
- <fileset dir="${src}/native/sysactivity" includes="*.c" if="is.running.linux" />
+ <fileset dir="${src}/native/sysactivity" includes="*.m" if="is.running.macos"/>
+ <!-- Linux-specific flags -->
<compilerarg value="-I/usr/include/gtk-2.0" if="is.running.linux" />
<compilerarg value="-I/usr/include/glib-2.0/" if="is.running.linux" />
<compilerarg value="-I/usr/include/cairo/" if="is.running.linux" />
@@ -654,16 +653,26 @@
<compilerarg value="-I/usr/lib/i386-linux-gnu/glib-2.0/include" if="is.running.linux" />
<compilerarg value="-I/usr/lib/i386-linux-gnu/gtk-2.0/include" if="is.running.linux" />
- <compilerarg value="-m32" if="cross_32" unless="is.running.macos" />
- <compilerarg value="-m64" if="cross_64" unless="is.running.macos" />
<compilerarg value="-I${system.JAVA_HOME}/include" if="is.running.linux" />
<compilerarg value="-I${system.JAVA_HOME}/include/linux" if="is.running.linux" />
- <linkerarg value="-m32" if="cross_32" unless="is.running.macos" />
- <linkerarg value="-m64" if="cross_64" unless="is.running.macos" />
<linkerarg value="-lgdk-x11-2.0" if="is.running.linux" />
<linkerarg value="-lXss" if="is.running.linux" />
<linkerarg value="-Wl,-z,relro" if="is.running.debian"/>
+
+ <fileset dir="${src}/native/sysactivity" includes="*.c" if="is.running.linux" />
+
+ <!-- Windows-specific flags -->
+ <compilerarg value="-D_WIN32_WINNT=0x0502" if="is.running.windows" />
+ <compilerarg value="-DWINVER=0x0502" if="is.running.windows" />
+ <compilerarg value="-I${system.JAVA_HOME}/include" if="is.running.windows" />
+ <compilerarg value="-I${system.JAVA_HOME}/include/win32" if="is.running.windows" />
+
+ <linkerarg value="-osysactivitynotifications.dll" if="is.running.windows" />
+ <linkerarg value="-liphlpapi" location="end" if="is.running.windows" />
+ <linkerarg value="-Wl,--kill-at" if="is.running.windows" />
+
+ <fileset dir="${src}/native/sysactivity" includes="*.cpp" if="is.running.windows" />
</cc>
</target>
<!-- compile sysactivity library for Windows
diff --git a/src/native/sysactivity/net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications.cpp b/src/native/sysactivity/net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications.cpp
index e4a2b80..bfa6703 100644
--- a/src/native/sysactivity/net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications.cpp
+++ b/src/native/sysactivity/net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications.cpp
@@ -9,470 +9,289 @@
/**
* \def WIN32_LEAN_AND_MEAN
- * \brief Exclude not commonly used headers from win32 API.
+ * \brief Excludes not commonly used headers from Win32 API.
*
- * It excludes some unused stuff from windows headers and
- * by the way code compiles faster.
+ * Excludes some unused stuff from Windows headers which allows the code to
+ * compile faster.
*/
#define WIN32_LEAN_AND_MEAN
-#include <winsock2.h>
-#include <ws2def.h>
-#include <ws2ipdef.h>
#include <windows.h>
-#include <iphlpapi.h>
-#include <process.h>
-#include <tchar.h>
-
-// cache for the JavaVM* pointer
-JavaVM *jvm;
-
-// cache for the a generic pointer
-jobject delegateObject;
-
-// thread id
-UINT uThreadId;
-
-// cache for the instance handle
-HINSTANCE hInstance;
-
-void RegisterWindowClassW();
-LRESULT CALLBACK WndProcW(HWND, UINT, WPARAM, LPARAM);
-HRESULT callback(UINT Msg, WPARAM wParam, LPARAM lParam);
-
-void notify(int notificationType);
-void notifyNetwork(int family,
- long luidIndex,
- char* name,
- long type,
- bool connected);
-
-typedef void (WINAPI *NIpIfaceChange)(ADDRESS_FAMILY,
- PIPINTERFACE_CHANGE_CALLBACK,
- PVOID,
- BOOLEAN,
- HANDLE);
-typedef NETIO_STATUS (*FnConvertInterfaceLuidToNameA)(
- const NET_LUID *,
- PSTR,
- SIZE_T);
-typedef NETIO_STATUS (*FnGetIpInterfaceEntry)(
- PMIB_IPINTERFACE_ROW);
-
-OVERLAPPED overlap;
-
-/*static HHOOK hhookSysMsg;
-
-static LRESULT CALLBACK msghook(int nCode, WPARAM wParam, LPARAM lParam)
+#include <iphlpapi.h> /* CancelIPChangeNotify, NotifyAddrChange */
+#include <process.h> /* _beginthreadex */
+#include <stdint.h> /* uintptr_t */
+
+static void SystemActivityNotifications_notify(jint type);
+unsigned WINAPI SystemActivityNotifications_runMessageLoop(LPVOID);
+LRESULT CALLBACK SystemActivityNotifications_wndProc(HWND, UINT, WPARAM, LPARAM);
+
+/**
+ * The Java object which has been set on the SystemActivityNotifications class
+ * with a call to the setDelegate method.
+ */
+static jobject SystemActivityNotifications_delegate = NULL;
+static OVERLAPPED SystemActivityNotifications_overlapped;
+static JavaVM *SystemActivityNotifications_vm;
+
+JNIEXPORT jlong JNICALL
+Java_net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_allocAndInit
+ (JNIEnv* env, jclass clazz)
{
- if(nCode < 0)
- {
- CallNextHookEx(hhookSysMsg, nCode, wParam, lParam);
- return 0;
- }
+ (void) env;
+ (void) clazz;
- LPMSG msg = (LPMSG)lParam;
+ HINSTANCE hInstance = GetModuleHandle(NULL);
- if(msg->message == WM_SYSCOMMAND)
+ if (hInstance)
{
- if(wParam == SC_SCREENSAVE)
+ LPCWSTR lpszClassName = L"Jitsi SystemActivityNotifications Window";
+ WNDCLASSEXW wcex;
+
+ wcex.cbSize = sizeof(WNDCLASSEXW);
+ wcex.cbClsExtra = 0;
+ wcex.cbWndExtra = 0;
+ wcex.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
+ wcex.hIcon = 0;
+ wcex.hIconSm = 0;
+ wcex.hCursor = 0;
+ wcex.hInstance = hInstance;
+ wcex.lpfnWndProc = SystemActivityNotifications_wndProc;
+ wcex.lpszClassName = lpszClassName;
+ wcex.lpszMenuName = 0;
+ wcex.style = CS_HREDRAW | CS_VREDRAW;
+
+ if (RegisterClassExW(&wcex))
{
- notify(net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_SCREENSAVER_START);
- }
- else if(wParam == SC_MONITORPOWER)
- {
- if(lParam == -1)
- {
- notify(net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_DISPLAY_WAKE);
- }
- else if(lParam == 2)
+ HWND hWnd
+ = CreateWindowW(
+ lpszClassName,
+ /* lpWindowName*/ NULL,
+ WS_OVERLAPPEDWINDOW,
+ /* x */ CW_USEDEFAULT,
+ /* y */ CW_USEDEFAULT,
+ /* nWidth */ CW_USEDEFAULT,
+ /* nHeight */ CW_USEDEFAULT,
+ /* hWndParent */ NULL,
+ /* hMenu */ NULL,
+ hInstance,
+ /* LPVOID */ NULL);
+
+ if (hWnd)
{
- notify(net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_DISPLAY_SLEEP);
+ ZeroMemory(
+ &SystemActivityNotifications_overlapped,
+ sizeof(SystemActivityNotifications_overlapped));
+
+ uintptr_t thrdh
+ = _beginthreadex(
+ /* security */ NULL,
+ /* stack_size */ 0,
+ SystemActivityNotifications_runMessageLoop,
+ (LPVOID) hWnd,
+ /* initflag */ 0,
+ /* thrdaddr */ NULL);
+
+ return (jlong) thrdh;
}
}
}
- return CallNextHookEx(hhookSysMsg, nCode, wParam, lParam);
+ return 0;
}
-*/
-unsigned WINAPI CreateWndThreadW(LPVOID pThreadParam)
+JNIEXPORT jlong JNICALL
+Java_net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_getLastInput
+ (JNIEnv* env, jclass clazz)
{
- hInstance = GetModuleHandle (NULL);
- RegisterWindowClassW();
-
- /*
- hhookSysMsg = SetWindowsHookEx(
- WH_MSGFILTER,
- (HOOKPROC)msghook,
- hInstance,
- GetCurrentThreadId());
- if(hhookSysMsg == NULL)
- {
- fprintf(stderr, "Failed to create hoook %i\n", GetLastError() );
- fflush(stderr);
- }
- */
-
- HWND hWnd = CreateWindowW( L"Jitsi Window Hook", NULL, WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
- NULL, NULL, hInstance, NULL);
- if( hWnd == NULL)
- {
- fprintf(stderr, "Failed to create window\n" );
- fflush(stderr);
+ (void) env;
+ (void) clazz;
- return( 0 );
-
- }else
- {
- MSG Msg;
-
- while(GetMessageW(&Msg, hWnd, 0, 0)) {
-
- TranslateMessage(&Msg);
+ LASTINPUTINFO lii;
- DispatchMessageW(&Msg);
- }
+ lii.cbSize = sizeof(LASTINPUTINFO);
+ lii.dwTime = 0;
+ return GetLastInputInfo(&lii) ? (GetTickCount() - lii.dwTime) : -1;
+}
- return Msg.wParam;
- }
+JNIEXPORT void JNICALL
+Java_net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_release
+ (JNIEnv* env, jclass clazz, jlong ptr)
+{
+ Java_net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_setDelegate(
+ env,
+ clazz,
+ ptr,
+ NULL);
}
-/*
- * Class: net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications
- * Method: setDelegate
- * Signature: (Lnet/java/sip/communicator/impl/sysactivity/SystemActivityNotifications/NotificationsDelegate;)V
- */
-JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_setDelegate
- (JNIEnv* jniEnv, jclass clazz, jlong ptr, jobject m_delegate)
+JNIEXPORT void JNICALL
+Java_net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_setDelegate
+ (JNIEnv* env, jclass clazz, jlong ptr, jobject delegate)
{
- if (delegateObject)
+ (void) clazz;
+ (void) ptr;
+
+ if (SystemActivityNotifications_delegate)
{
- if (!jniEnv)
- jvm->AttachCurrentThread((void **)&jniEnv, NULL);
- jniEnv->DeleteGlobalRef(delegateObject);
- delegateObject = NULL;
- jvm = NULL;
+ env->DeleteGlobalRef(SystemActivityNotifications_delegate);
+ SystemActivityNotifications_delegate = NULL;
}
-
- if (m_delegate)
+ if (delegate)
{
- m_delegate = jniEnv->NewGlobalRef(m_delegate);
- if (m_delegate)
- {
- jniEnv->GetJavaVM(&(jvm));
- delegateObject = m_delegate;
- }
+ delegate = env->NewGlobalRef(delegate);
+ if (delegate)
+ SystemActivityNotifications_delegate = delegate;
}
}
-/*
- * Class: net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications
- * Method: allocAndInit
- * Signature: ()J
- */
-JNIEXPORT jlong JNICALL Java_net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_allocAndInit
- (JNIEnv* jniEnv, jclass clazz)
+JNIEXPORT void JNICALL
+Java_net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_start
+ (JNIEnv* env, jclass clazz, jlong ptr)
{
- HANDLE hThread;
+ (void) env;
+ (void) clazz;
+ (void) ptr;
- hThread = (HANDLE)_beginthreadex(NULL, 0, &CreateWndThreadW, NULL, 0, &uThreadId);
-
- if(!hThread)
+ do
{
- //throwException( env, "_beginthreadex", "initialisation failed" );
- }
+ HANDLE handle = NULL;
+
+ if (ERROR_IO_PENDING
+ != NotifyAddrChange(
+ &handle,
+ &SystemActivityNotifications_overlapped))
+ break; // Break in case of an error.
- return (jlong)hThread;
+ DWORD numberOfBytesTransferred;
+
+ if (!GetOverlappedResult(
+ handle,
+ &SystemActivityNotifications_overlapped,
+ &numberOfBytesTransferred,
+ /* bWait */ TRUE))
+ break; // Break in case of an error.
+
+ SystemActivityNotifications_notify(
+ net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_NETWORK_CHANGE);
+ }
+ while (TRUE);
}
-JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_release
- (JNIEnv* jniEnv, jclass clazz, jlong ptr)
+JNIEXPORT void JNICALL
+Java_net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_stop
+ (JNIEnv* env, jclass clazz, jlong ptr)
{
- if (!jniEnv)
- jvm->AttachCurrentThread((void **)&jniEnv, NULL);
- jniEnv->DeleteGlobalRef(delegateObject);
- delegateObject = NULL;
- jvm = NULL;
+ (void) env;
+ (void) clazz;
+ (void) ptr;
+
+ CancelIPChangeNotify(&SystemActivityNotifications_overlapped);
}
-static void InterfaceChangeCallback(
- PVOID CallerContext,
- PMIB_IPINTERFACE_ROW Row,
- MIB_NOTIFICATION_TYPE NotificationType)
+JNIEXPORT jint JNICALL
+JNI_OnLoad(JavaVM *vm, void *reserved)
{
- if(Row)
- {
- FnGetIpInterfaceEntry getIpIfaceEntry;
- getIpIfaceEntry = (FnGetIpInterfaceEntry)GetProcAddress(
- GetModuleHandle(TEXT("Iphlpapi.dll")),
- "GetIpInterfaceEntry");
-
- if(getIpIfaceEntry && getIpIfaceEntry(Row) == NO_ERROR)
- {
- FnConvertInterfaceLuidToNameA convertName;
- convertName = (FnConvertInterfaceLuidToNameA)GetProcAddress(
- GetModuleHandle(TEXT("Iphlpapi.dll")),
- "ConvertInterfaceLuidToNameA");
-
- char interfaceName[MAX_PATH];
- if (convertName &&
- convertName(&(Row->InterfaceLuid),
- interfaceName,
- sizeof(interfaceName))
- == NO_ERROR)
- {
- //fprintf( stderr, "Interface LUID Name : %s\n", interfaceName);
- }
+ (void) reserved;
- notifyNetwork(
- Row->Family,
- Row->InterfaceLuid.Info.NetLuidIndex,
- interfaceName,
- Row->InterfaceLuid.Info.IfType,
- Row->Connected);
- }
- }
+ SystemActivityNotifications_vm = vm;
+ return JNI_VERSION_1_4;
}
-/*
- * Class: net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications
- * Method: getLastInput
- * Signature: ()J
- */
-JNIEXPORT jlong JNICALL Java_net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_getLastInput
- (JNIEnv* jniEnv, jclass clazz)
+JNIEXPORT void JNICALL
+JNI_OnUnload(JavaVM *vm, void *reserved)
{
- DWORD result = 0;
-
- LASTINPUTINFO lii;
- memset(&lii, 0, sizeof(lii));
- lii.cbSize = sizeof(LASTINPUTINFO);
- if (GetLastInputInfo(&lii))
- {
- return GetTickCount() - lii.dwTime;
- }
+ (void) vm;
+ (void) reserved;
- return -1;
+ SystemActivityNotifications_vm = NULL;
}
-/*
- * Class: net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications
- * Method: start
- * Signature: (J)V
- */
-JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_start
- (JNIEnv* jniEnv, jclass clazz, jlong ptr)
+static void
+SystemActivityNotifications_notify(jint type)
{
-/*
- OSVERSIONINFOEX osVersionInfoEx;
- memset( &osVersionInfoEx, 0, sizeof(OSVERSIONINFOEX) );
- osVersionInfoEx.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
- GetVersionEx((OSVERSIONINFO*) &osVersionInfoEx );
+ jobject delegate = SystemActivityNotifications_delegate;
- if( osVersionInfoEx.dwMajorVersion == 5)
+ if (delegate)
{
-*/
- // XP
- while(true)
- {
- HANDLE hand = NULL;
- DWORD ret, bytes;
+ JavaVM *vm = SystemActivityNotifications_vm;
- hand = NULL;
- ZeroMemory(&overlap, sizeof(overlap));
- overlap.hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
- ret = NotifyAddrChange(&hand, &overlap);
+ if (vm)
+ {
+ JNIEnv *env;
- if(ret != ERROR_IO_PENDING )
+ if (0 == vm->AttachCurrentThreadAsDaemon((void **) &env, NULL))
{
- //fprintf(stderr, "NotifyAddrChange returned %d,
- // expected ERROR_IO_PENDING \n", ret);fflush(stderr);
-
- // break in case of error.
- break;
- }
+ jclass clazz = env->GetObjectClass(delegate);
- BOOL success = GetOverlappedResult(hand, &overlap, &bytes, TRUE);
+ if (clazz)
+ {
+ jmethodID methodID
+ = env->GetMethodID(clazz,"notify", "(I)V");
- if(!success)
- break;
-
- notify(net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_NETWORK_CHANGE);
- }
-/*
- }
- else if( osVersionInfoEx.dwMajorVersion > 5)
- {
- // Vista, 7, ....
- NIpIfaceChange nIpIfaceChange;
- nIpIfaceChange = (NIpIfaceChange)GetProcAddress(
- GetModuleHandle(TEXT("Iphlpapi.dll")),
- "NotifyIpInterfaceChange");
-
- if(nIpIfaceChange)
- {
- ADDRESS_FAMILY family = AF_UNSPEC;
- HANDLE hNotification;
-
- nIpIfaceChange(
- family,
- (PIPINTERFACE_CHANGE_CALLBACK)InterfaceChangeCallback,
- NULL,
- FALSE,
- &hNotification);
+ if (methodID)
+ env->CallVoidMethod(delegate, methodID, type);
+ }
+ env->ExceptionClear();
+ }
}
}
-*/
}
-/*
- * Class: net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications
- * Method: stop
- * Signature: (J)V
- */
-JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_stop
- (JNIEnv* jniEnv, jclass clazz, jlong ptr)
+unsigned WINAPI
+SystemActivityNotifications_runMessageLoop(LPVOID pv)
{
- CancelIPChangeNotify(&overlap);
-}
+ MSG msg;
+ HWND hWnd = (HWND) pv;
-void RegisterWindowClassW()
-{
- WNDCLASSEXW wcex;
-
- wcex.cbSize = sizeof(WNDCLASSEXW);
- wcex.style = CS_HREDRAW | CS_VREDRAW;
- wcex.lpfnWndProc = WndProcW;
- wcex.cbClsExtra = 0;
- wcex.cbWndExtra = 0;
- wcex.hInstance = hInstance;
- wcex.hIcon = 0;
- wcex.hCursor = 0;
- wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
- wcex.lpszMenuName = 0;
- wcex.lpszClassName = L"Jitsi Window Hook";
- wcex.hIconSm = 0;
-
- RegisterClassExW(&wcex);
-}
-
-LRESULT CALLBACK WndProcW(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
-{
- long res = callback( Msg, wParam, lParam );
-
- if ( res != -1 )
+ while (GetMessageW(&msg, hWnd, 0, 0))
{
- return( res );
+ TranslateMessage(&msg);
+ DispatchMessageW(&msg);
}
-
- return DefWindowProcW(hWnd, Msg, wParam, lParam);
+ return msg.wParam;
}
-HRESULT callback(UINT Msg, WPARAM wParam, LPARAM lParam)
+LRESULT CALLBACK
+SystemActivityNotifications_wndProc
+ (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
- JNIEnv *env;
-
- if ( jvm->AttachCurrentThread((void **)&env, NULL ))
- {
- fprintf( stderr, "failed to attach current thread to JVM\n" );fflush(stderr);
-
- return( -1 );
- }
-
- jlong result = -1;
-
- if (Msg == WM_POWERBROADCAST)
+ switch (uMsg)
{
+ case WM_POWERBROADCAST:
if (wParam == PBT_APMSUSPEND)
{
- notify(net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_SLEEP);
+ SystemActivityNotifications_notify(
+ net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_SLEEP);
return TRUE;
}
else if (wParam == PBT_APMRESUMESUSPEND)
{
- notify(net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_WAKE);
+ SystemActivityNotifications_notify(
+ net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_WAKE);
return TRUE;
}
- }
- else if (Msg == WM_QUERYENDSESSION)
- {
- notify(net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_QUERY_ENDSESSION);
- return TRUE;
- }
- else if (Msg == WM_ENDSESSION && wParam == TRUE)
- {
- // we fire the message only if we are really ending the session
- // is wParam is False means someone has canceled the shutdown/logoff
- notify(net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_ENDSESSION);
- return TRUE;
- }
-
- jvm->DetachCurrentThread();
-
- return((HRESULT)result );
-}
-
-void notify(int notificationType)
-{
- JNIEnv *jniEnv;
- jclass delegateClass = NULL;
-
- if (!delegateObject)
- return;
+ break; // WM_POWERBROADCAST
- if (0 != jvm->AttachCurrentThreadAsDaemon( (void **)&jniEnv, NULL))
- return;
-
- delegateClass = jniEnv->GetObjectClass(delegateObject);
- if(delegateClass)
- {
- jmethodID methodid = NULL;
+ case WM_QUERYENDSESSION:
+ SystemActivityNotifications_notify(
+ net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_QUERY_ENDSESSION);
+ return TRUE;
- methodid = jniEnv->GetMethodID(delegateClass,"notify", "(I)V");
- if(methodid)
+ case WM_ENDSESSION:
+ // We fire the message only if we are really ending the session. If
+ // wParam is FALSE, then someone has canceled the shutdown/logoff.
+ if (wParam == TRUE)
{
- jniEnv->CallVoidMethod(delegateObject, methodid, notificationType);
+ SystemActivityNotifications_notify(
+ net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_ENDSESSION);
+ return TRUE;
}
- }
- jniEnv->ExceptionClear();
-}
-
-void notifyNetwork(int family,
- long luidIndex,
- char* name,
- long type,
- bool connected)
-{
- JNIEnv *jniEnv;
- jclass delegateClass = NULL;
-
- if (!delegateObject)
- return;
-
- if (0 != jvm->AttachCurrentThreadAsDaemon( (void **)&jniEnv, NULL))
- return;
+ else
+ break; // WM_ENDSESSION
- delegateClass = jniEnv->GetObjectClass(delegateObject);
- if(delegateClass)
- {
- jmethodID methodid = NULL;
-
- methodid = jniEnv->GetMethodID(delegateClass,
- "notifyNetworkChange",
- "(IJLjava/lang/String;JZ)V");
-
- if(methodid)
- {
- jniEnv->CallVoidMethod(delegateObject, methodid,
- family,
- luidIndex,
- name ? jniEnv->NewStringUTF(name) : NULL,
- type,
- connected);
- }
+ default:
+ break;
}
- jniEnv->ExceptionClear();
-}
+ return DefWindowProcW(hWnd, uMsg, wParam, lParam);
+}
diff --git a/src/native/sysactivity/net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications.h b/src/native/sysactivity/net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications.h
index 7c5d55a..a0beeee 100644
--- a/src/native/sysactivity/net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications.h
+++ b/src/native/sysactivity/net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications.h
@@ -1,45 +1,53 @@
-/* DO NOT EDIT THIS FILE - it is machine generated */
+/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
-/* Header for class net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications */
-
-#ifndef _Included_net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications
+/* Header for class net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications */
+
+#ifndef _Included_net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications
#define _Included_net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications
-#ifdef __cplusplus
-extern "C" {
+#ifdef __cplusplus
+extern "C" {
#endif
-#undef net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_SLEEP
-#define net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_SLEEP 0L
-#undef net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_WAKE
-#define net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_WAKE 1L
-#undef net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_DISPLAY_SLEEP
+#undef net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_DISPLAY_SLEEP
#define net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_DISPLAY_SLEEP 2L
-#undef net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_DISPLAY_WAKE
+#undef net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_DISPLAY_WAKE
#define net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_DISPLAY_WAKE 3L
-#undef net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_SCREENSAVER_START
-#define net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_SCREENSAVER_START 4L
-#undef net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_SCREENSAVER_WILL_STOP
-#define net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_SCREENSAVER_WILL_STOP 5L
-#undef net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_SCREENSAVER_STOP
-#define net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_SCREENSAVER_STOP 6L
-#undef net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_SCREEN_LOCKED
-#define net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_SCREEN_LOCKED 7L
-#undef net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_SCREEN_UNLOCKED
-#define net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_SCREEN_UNLOCKED 8L
-#undef net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_NETWORK_CHANGE
-#define net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_NETWORK_CHANGE 9L
-#undef net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_DNS_CHANGE
+#undef net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_DNS_CHANGE
#define net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_DNS_CHANGE 10L
-#undef net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_QUERY_ENDSESSION
-#define net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_QUERY_ENDSESSION 11L
-#undef net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_ENDSESSION
+#undef net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_ENDSESSION
#define net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_ENDSESSION 12L
+#undef net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_NETWORK_CHANGE
+#define net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_NETWORK_CHANGE 9L
+#undef net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_QUERY_ENDSESSION
+#define net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_QUERY_ENDSESSION 11L
+#undef net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_SCREEN_LOCKED
+#define net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_SCREEN_LOCKED 7L
+#undef net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_SCREEN_UNLOCKED
+#define net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_SCREEN_UNLOCKED 8L
+#undef net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_SCREENSAVER_START
+#define net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_SCREENSAVER_START 4L
+#undef net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_SCREENSAVER_STOP
+#define net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_SCREENSAVER_STOP 6L
+#undef net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_SCREENSAVER_WILL_STOP
+#define net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_SCREENSAVER_WILL_STOP 5L
+#undef net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_SLEEP
+#define net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_SLEEP 0L
+#undef net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_WAKE
+#define net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_NOTIFY_WAKE 1L
/*
* Class: net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications
* Method: allocAndInit
* Signature: ()J
*/
JNIEXPORT jlong JNICALL Java_net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_allocAndInit
- (JNIEnv *, jclass);
+ (JNIEnv *, jclass);
+
+/*
+ * Class: net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications
+ * Method: getLastInput
+ * Signature: ()J
+ */
+JNIEXPORT jlong JNICALL Java_net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_getLastInput
+ (JNIEnv *, jclass);
/*
* Class: net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications
@@ -47,7 +55,7 @@ JNIEXPORT jlong JNICALL Java_net_java_sip_communicator_impl_sysactivity_SystemAc
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_release
- (JNIEnv *, jclass, jlong);
+ (JNIEnv *, jclass, jlong);
/*
* Class: net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications
@@ -55,7 +63,7 @@ JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_sysactivity_SystemAct
* Signature: (JLnet/java/sip/communicator/impl/sysactivity/SystemActivityNotifications/NotificationsDelegate;)V
*/
JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_setDelegate
- (JNIEnv *, jclass, jlong, jobject);
+ (JNIEnv *, jclass, jlong, jobject);
/*
* Class: net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications
@@ -63,7 +71,7 @@ JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_sysactivity_SystemAct
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_start
- (JNIEnv *, jclass, jlong);
+ (JNIEnv *, jclass, jlong);
/*
* Class: net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications
@@ -71,18 +79,9 @@ JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_sysactivity_SystemAct
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_stop
- (JNIEnv *, jclass, jlong);
-
-/*
- * Class: net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications
- * Method: getLastInput
- * Signature: ()J
- */
-JNIEXPORT jlong JNICALL Java_net_java_sip_communicator_impl_sysactivity_SystemActivityNotifications_getLastInput
- (JNIEnv *, jclass);
-
+ (JNIEnv *, jclass, jlong);
-#ifdef __cplusplus
-}
+#ifdef __cplusplus
+}
#endif
#endif