~do-win/do/test-paths

« back to all changes in this revision

Viewing changes to Do.Platform.Windows/src/Do.Platform/Do.Platform.Windows/SystemService.cs

  • Committer: Chris S.
  • Date: 2009-06-21 11:18:12 UTC
  • Revision ID: chris@szikszoy.com-20090621111812-5aigiqs3mfth11e8
begin to windows-ize SystemServices.cs

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
18
//
19
19
 
20
 
using System;
21
 
using System.Reflection;
22
 
 
23
 
using NDesk.DBus;
24
 
using org.freedesktop.DBus;
25
 
 
26
 
using Do.Platform.ServiceStack;
27
 
using Do.Platform.Windows.DBus;
 
20
using System;
 
21
using System.Diagnostics;
 
22
using System.Windows.Forms;
 
23
 
 
24
using Do.Platform.ServiceStack;
28
25
 
29
26
using Gnome;
30
27
 
31
28
namespace Do.Platform.Windows
32
29
{
33
30
        
34
 
        public class SystemService : AbstractSystemService, IController, IInitializedService
 
31
        public class SystemService : AbstractSystemService, IInitializedService
35
32
        {
36
33
                delegate void BoolDelegate (bool val);
37
 
                
38
 
                const string PowerManagementName = "org.freedesktop.PowerManagement";
39
 
                const string PowerManagementPath = "/org/freedesktop/PowerManagement";
 
34
 
40
35
                const string AutoStartKey = "Hidden";
41
36
                
42
 
                [Interface(PowerManagementName)]
43
 
                interface IPowerManagement
44
 
                {
45
 
                        bool GetOnBattery ();
46
 
                        event BoolDelegate OnBatteryChanged;
47
 
                }
48
 
                
49
 
                IPowerManagement power;
50
37
                DesktopItem autostartfile;
51
38
                
52
39
                public void Initialize ()
53
40
                {
 
41
            // not sure if there are any battery state related events
 
42
            // the only ones I could find were for windows mobile & windows CE
 
43
            // - Chris S.
 
44
 
 
45
            /*
54
46
                        try {
55
47
                                BusG.Init ();
56
48
                                if (Bus.Session.NameHasOwner (PowerManagementName)) {
61
53
                                Log<SystemService>.Error ("Could not initialize dbus: {0}", e.Message);
62
54
                                Log<SystemService>.Debug (e.StackTrace);
63
55
                        }
 
56
             * */
64
57
                }
65
58
 
66
59
                void PowerOnBatteryChanged (bool val)
71
64
                public override bool GetOnBatteryPower ()
72
65
                {
73
66
                        try {
74
 
                                if (power == null && !Bus.Session.NameHasOwner (PowerManagementName))
75
 
                                        return false;
76
 
                                if (power == null)
77
 
                                        power = Bus.Session.GetObject<IPowerManagement> (PowerManagementName, new ObjectPath (PowerManagementPath));
78
 
                                return power.GetOnBattery ();
 
67
                                return SystemInformation.PowerStatus.PowerLineStatus == PowerLineStatus.Offline;
79
68
                        } catch (Exception e) {
80
69
                                Log<SystemService>.Error ("Could not GetOnBattery: {0}", e.Message);
81
70
                                Log<SystemService>.Debug (e.StackTrace);
86
75
                public override void EnsureSingleApplicationInstance ()
87
76
                {
88
77
                        try {
89
 
                                IController controller = Registrar.GetControllerInstance ();
90
 
                                if (controller == null) {
91
 
                                        // No IController found on the bus, so no other
92
 
                                        // instance is running. Register self.
 
78
 
 
79
                                if (Process.GetProcessesByName (Process.GetCurrentProcess ().ProcessName).Length > 1) {
93
80
                                        Log<SystemService>.Debug ("No other application instance detected. Continue startup.");
94
 
                                        Registrar.RegisterController (this);
95
81
                                } else {
96
 
                                        // Another IController was found, so summon it
97
 
                                        // and exit.
98
 
                                        Log<SystemService>.Debug ("Existing application instance detected. Summon and bail.");
99
 
                                        controller.Summon ();
 
82
                                        Log<SystemService>.Debug ("Existing application instance detected. Summon and bail.");
 
83
                    Summon ();
100
84
                                        System.Environment.Exit (0);
101
85
                                }
102
86
                        } catch (Exception e) {