Fixes bugs 446089, 445267. adds a nsIdleService for OSSO and exposes osso functionality. This is a linux only change. r=stuart
authordougt@dougt-xubuntu
Fri, 25 Jul 2008 14:34:30 -0700
changeset 16235 33d9196aa5d52fff8248389b0c2325feaaa0b567
parent 16234 d0e438d64ea040ab525a10c954475cac5827eabe
child 16236 fcdfa3729ed5128a5b6a0808d71357cb9f86011f
push id860
push userdougt@mozilla.com
push dateSat, 26 Jul 2008 21:23:21 +0000
treeherdermozilla-central@33d9196aa5d5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersstuart
bugs446089, 445267
milestone1.9.1a2pre
Fixes bugs 446089, 445267. adds a nsIdleService for OSSO and exposes osso functionality. This is a linux only change. r=stuart
toolkit/xre/nsNativeAppSupportUnix.cpp
widget/src/gtk2/Makefile.in
widget/src/gtk2/nsIdleServiceOSSO.cpp
widget/src/gtk2/nsIdleServiceOSSO.h
widget/src/gtk2/nsWidgetFactory.cpp
--- a/toolkit/xre/nsNativeAppSupportUnix.cpp
+++ b/toolkit/xre/nsNativeAppSupportUnix.cpp
@@ -198,19 +198,64 @@ class nsNativeAppSupportUnix : public ns
 {
 public:
   NS_IMETHOD Start(PRBool* aRetVal);
   NS_IMETHOD Stop( PRBool *aResult);
 
 private:
 #ifdef NS_OSSO
   osso_context_t *m_osso_context;    
+  /* A note about why we need to have m_hw_state:
+     the osso hardware callback does not tell us what changed, just
+     that something has changed.  We need to keep track of state so
+     that we can determine what has changed.
+  */  
+  osso_hw_state_t m_hw_state;
 #endif
 };
 
+#ifdef NS_OSSO
+static void OssoHardwareCallback(osso_hw_state_t *state, gpointer data)
+{
+  NS_ASSERTION(state, "osso_hw_state_t must not be null.");
+  NS_ASSERTION(data, "data must not be null.");
+
+  osso_hw_state_t* ourState = (osso_hw_state_t*) data;
+
+  if (state->shutdown_ind) {
+    nsCOMPtr<nsIAppStartup> appService =  do_GetService("@mozilla.org/toolkit/app-startup;1");
+    if (appService)
+      appService->Quit(nsIAppStartup::eForceQuit);
+    return;
+  }
+    
+  if (state->memory_low_ind) {
+    if (ourState->memory_low_ind) {
+      nsCOMPtr<nsIObserverService> os = do_GetService("@mozilla.org/observer-service;1");
+      if (os)
+        os->NotifyObservers(nsnull, "memory-pressure", NS_LITERAL_STRING("low-memory").get());
+    }
+  }
+  
+  if (state->system_inactivity_ind != ourState->system_inactivity_ind) {
+      nsCOMPtr<nsIObserverService> os = do_GetService("@mozilla.org/observer-service;1");
+      if (!os)
+        return;
+ 
+      if (state->system_inactivity_ind)
+          os->NotifyObservers(nsnull, "system-idle", nsnull);
+      else
+          os->NotifyObservers(nsnull, "system-active", nsnull);
+  }
+
+  memcpy(ourState, state, sizeof(osso_hw_state_t));
+}
+
+#endif
+
 NS_IMETHODIMP
 nsNativeAppSupportUnix::Start(PRBool *aRetVal)
 {
   NS_ASSERTION(gAppData, "gAppData must not be null.");
 
   if (gtk_major_version < MIN_GTK_MAJOR_VERSION ||
       (gtk_major_version == MIN_GTK_MAJOR_VERSION && gtk_minor_version < MIN_GTK_MINOR_VERSION)) {
     GtkWidget* versionErrDialog = gtk_message_dialog_new(NULL,
@@ -224,26 +269,35 @@ nsNativeAppSupportUnix::Start(PRBool *aR
                      MIN_GTK_MAJOR_VERSION,
                      MIN_GTK_MINOR_VERSION);
     gtk_dialog_run(GTK_DIALOG(versionErrDialog));
     gtk_widget_destroy(versionErrDialog);
     exit(0);
   }
 
 #ifdef NS_OSSO
+  /* zero state out. */
+  memset(&m_hw_state, 0, sizeof(osso_hw_state_t));
+
   /* Initialize maemo application */
   m_osso_context = osso_initialize(gAppData->name, 
                                    gAppData->version ? gAppData->version : "1.0",
                                    PR_TRUE,
                                    nsnull);
 
   /* Check that initilialization was ok */
   if (m_osso_context == nsnull) {
       return NS_ERROR_FAILURE;
   }
+
+  osso_hw_set_event_cb(m_osso_context,
+                       nsnull,
+                       OssoHardwareCallback,
+                       &m_hw_state);
+
 #endif
 
   *aRetVal = PR_TRUE;
 
   PRLibrary *gnomeuiLib = PR_LoadLibrary("libgnomeui-2.so.0");
   if (!gnomeuiLib)
     return NS_OK;
 
@@ -306,16 +360,17 @@ NS_IMETHODIMP
 nsNativeAppSupportUnix::Stop( PRBool *aResult )
 {
   NS_ENSURE_ARG( aResult );
   *aResult = PR_TRUE;
 
 #ifdef NS_OSSO
   if (m_osso_context)
   {
+    osso_hw_unset_event_cb(m_osso_context, nsnull);
     osso_deinitialize(m_osso_context);
     m_osso_context = nsnull;
   }
 #endif
   return NS_OK;
 }
 
 nsresult
--- a/widget/src/gtk2/Makefile.in
+++ b/widget/src/gtk2/Makefile.in
@@ -102,19 +102,23 @@ CPPSRCS		= \
 		nsDragService.cpp \
 		nsFilePicker.cpp \
 		nsSound.cpp \
 		nsNativeKeyBindings.cpp \
 		nsScreenGtk.cpp \
 		nsScreenManagerGtk.cpp \
 		nsImageToPixbuf.cpp \
 		nsAccessibilityHelper.cpp \
-		nsIdleServiceGTK.cpp \
 		$(NULL)
 
+ifdef NS_OSSO
+CPPSRCS         += nsIdleServiceOSSO.cpp
+else
+CPPSRCS         += nsIdleServiceGTK.cpp
+endif
 
 ifdef NS_PRINTING
 CPPSRCS		+= \
 		nsDeviceContextSpecG.cpp \
 		nsPrintOptionsGTK.cpp \
 		nsPrintDialogGTK.cpp \
 		nsPrintSettingsGTK.cpp \
 		$(NULL)
new file mode 100644
--- /dev/null
+++ b/widget/src/gtk2/nsIdleServiceOSSO.cpp
@@ -0,0 +1,82 @@
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Idle Service for OSSO.
+ *
+ * The Initial Developer of the Original Code is Mozilla Corporation
+ * Portions created by the Initial Developer are Copyright (C) 2008
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *  Doug Turner <dougt@meer.net>  (Original Author)
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+#include "nsIdleServiceOSSO.h"
+#include "nsIObserverService.h"
+#include "nsServiceManagerUtils.h"
+#include "prtime.h"
+
+#include <gtk/gtk.h>
+
+NS_IMPL_ISUPPORTS2(nsIdleServiceOSSO, nsIIdleService, nsIObserver)
+
+nsIdleServiceOSSO::nsIdleServiceOSSO()
+ : mIdle(PR_FALSE)
+{
+  nsCOMPtr<nsIObserverService> obsServ = do_GetService("@mozilla.org/observer-service;1");
+  obsServ->AddObserver(this, "system-idle", PR_FALSE);
+  obsServ->AddObserver(this, "system-active", PR_FALSE);
+}
+
+nsIdleServiceOSSO::~nsIdleServiceOSSO()
+{
+}
+
+NS_IMETHODIMP
+nsIdleServiceOSSO::GetIdleTime(PRUint32 *aTimeDiff)
+{ 
+  if (mIdle) {
+    *aTimeDiff = ( PR_Now() - mIdleSince ) / PR_USEC_PER_MSEC;
+    return NS_OK;
+  }
+
+  *aTimeDiff = 0;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+nsIdleServiceOSSO::Observe(nsISupports *aSubject, const char *aTopic, const PRUnichar *aData)
+{
+  if (!strcmp(aTopic, "system-idle")) {
+    mIdle = PR_TRUE;
+    mIdleSince = PR_Now();
+  }
+  else if (!strcmp(aTopic, "system-active")) {
+    mIdle = PR_FALSE;
+  }
+
+  return NS_OK;
+}
new file mode 100644
--- /dev/null
+++ b/widget/src/gtk2/nsIdleServiceOSSO.h
@@ -0,0 +1,59 @@
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Idle Service for OSSO.
+ *
+ * The Initial Developer of the Original Code is Mozilla Corporation
+ * Portions created by the Initial Developer are Copyright (C) 2008
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *  Doug Turner <dougt@meer.net>  (Original Author)
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+#ifndef nsIdleServiceOSSO_h__
+#define nsIdleServiceOSSO_h__
+
+#include "nsIdleService.h"
+#include "nsIObserver.h"
+
+class nsIdleServiceOSSO : public nsIdleService, public nsIObserver
+{
+public:
+    NS_DECL_ISUPPORTS
+    NS_DECL_NSIOBSERVER
+
+    nsIdleServiceOSSO();
+
+    NS_IMETHOD GetIdleTime(PRUint32* idleTime);
+
+private:
+    ~nsIdleServiceOSSO();
+    PRBool mIdle;
+    PRTime mIdleSince;
+};
+
+#endif // nsIdleServiceOSSO_h__
--- a/widget/src/gtk2/nsWidgetFactory.cpp
+++ b/widget/src/gtk2/nsWidgetFactory.cpp
@@ -58,18 +58,23 @@
 #include "nsPrintOptionsGTK.h"
 #include "nsPrintSession.h"
 #include "nsDeviceContextSpecG.h"
 #endif
 
 #include "nsIPrefService.h"
 #include "nsIPrefBranch.h"
 #include "nsImageToPixbuf.h"
+#include "nsPrintDialogGTK.h"
+
+#ifdef NS_OSSO
+#include "nsIdleServiceOSSO.h"
+#else
 #include "nsIdleServiceGTK.h"
-#include "nsPrintDialogGTK.h"
+#endif
 
 #ifdef NATIVE_THEME_SUPPORT
 #include "nsNativeThemeGTK.h"
 #endif
 
 #include "nsIComponentRegistrar.h"
 #include "nsComponentManagerUtils.h"
 #include "nsAutoPtr.h"
@@ -92,17 +97,22 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsHTMLFor
 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsClipboard, Init)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsDragService)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsSound)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsScreenManagerGtk)
 #ifdef NATIVE_THEME_SUPPORT
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsNativeThemeGTK)
 #endif
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsImageToPixbuf)
+
+#ifdef NS_OSSO
+NS_GENERIC_FACTORY_CONSTRUCTOR(nsIdleServiceOSSO)
+#else
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsIdleServiceGTK)
+#endif
 
 #ifdef NS_PRINTING
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsDeviceContextSpecGTK)
 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrintOptionsGTK, Init)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsPrinterEnumeratorGTK)
 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrintSession, Init)
 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrintDialogServiceGTK, Init)
 #endif
@@ -280,20 +290,28 @@ static const nsModuleComponentInfo compo
     NS_PRINTDIALOGSERVICE_CID,
     NS_PRINTDIALOGSERVICE_CONTRACTID,
     nsPrintDialogServiceGTKConstructor },
 #endif 
   { "Image to gdk-pixbuf converter",
     NS_IMAGE_TO_PIXBUF_CID,
     "@mozilla.org/widget/image-to-gdk-pixbuf;1",
     nsImageToPixbufConstructor },
+#ifdef NS_OSSO
   { "User Idle Service",
     NS_IDLE_SERVICE_CID,
     "@mozilla.org/widget/idleservice;1",
+    nsIdleServiceOSSOConstructor },  
+#else
+{ "User Idle Service",
+    NS_IDLE_SERVICE_CID,
+    "@mozilla.org/widget/idleservice;1",
     nsIdleServiceGTKConstructor },
+#endif //NS_OSSO
+
 };
 
 PR_STATIC_CALLBACK(void)
 nsWidgetGtk2ModuleDtor(nsIModule *aSelf)
 {
   nsFilePicker::Shutdown();
   nsSound::Shutdown();
   nsWindow::ReleaseGlobals();