~ubuntu-branches/ubuntu/jaunty/gnome-do-plugins/jaunty-proposed

« back to all changes in this revision

Viewing changes to VirtualBox/src/VMThread.cs

  • Committer: Bazaar Package Importer
  • Author(s): Christopher James Halse Rogers, Christopher James Halse Rogers, Iain Lane
  • Date: 2009-02-05 16:58:51 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20090205165851-bku2c9rmrny93b31
Tags: 0.8.0.2+dfsg-1~ubuntu1
[ Christopher James Halse Rogers ]
* New upstream version
* debian/control:
  + gnome-sharp2 transition (LP: #314516)
  + Add banshee build-dep
  + Drop monodevelop build-dep; upstream uses mautil rather than mdtool now
  + Bump required gnome-do version in Build-Dep & Depends.
  + Suggest Banshee
* debian/copyright:
  + Refresh for new upstream version; new plugins added.
* debian/rules:
  + Rework clean target to simply delete files generated by autoreconf,
    rather than trying to preserve them.
  + Remove XDG_CONFIG_DIR hack needed for mdtool
* debian/patches/01_firefox_iceweasel_rename:
  + Refresh for new upsteam changes.
  + Extend to also make the Firefox bookmark plugin index iceweasel bookmarks

[ Iain Lane ]
* Tag pkg-cli-apps SVN revision into Jaunty, to get in before Feature
  Freeze. Should be a sync after the next Debian upload.
* debian/control: Add ${misc:Depends} build-dep 
* debian/rules: Do not fail if configure is missing (e.g. clean twice in a
  row) 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// VMThread.cs
 
2
//
 
3
//  GNOME Do is the legal property of its developers.
 
4
//  Please refer to the COPYRIGHT file distributed with this
 
5
//  source distribution.
 
6
//
 
7
//  This program is free software: you can redistribute it and/or modify
 
8
//  it under the terms of the GNU General Public License as published by
 
9
//  the Free Software Foundation, either version 3 of the License, or
 
10
//  (at your option) any later version.
 
11
//
 
12
//  This program is distributed in the hope that it will be useful,
 
13
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
//  GNU General Public License for more details.
 
16
//
 
17
//  You should have received a copy of the GNU General Public License
 
18
//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
19
 
 
20
 
 
21
using System;
 
22
using System.Collections.Generic;
 
23
using System.Diagnostics;
 
24
 
 
25
 
 
26
using Do.Platform;
 
27
 
 
28
namespace VirtualBox
 
29
{
 
30
        public class VMThread
 
31
        {
 
32
                private string op1;
 
33
                private string op2;
 
34
                private VMState NewState;
 
35
                private VMItem vm;
 
36
                
 
37
                //complicated constructor if you want to supply everything
 
38
                public VMThread(string o1, string o2, VMState ns, ref VMItem v)
 
39
                {
 
40
                        this.op1 = o1;
 
41
                        this.op2 = o2;
 
42
                        this.NewState = ns;
 
43
                        this.vm = v;
 
44
                }
 
45
                
 
46
                //empty constructor, only for complex actions
 
47
                public VMThread(ref VMItem v)
 
48
                {
 
49
                        this.vm = v;    
 
50
                }
 
51
                
 
52
                //simple constructor, to make things easy
 
53
                public VMThread(VMState ns, ref VMItem v)
 
54
                {
 
55
                        NewState = ns;
 
56
                        vm = v;
 
57
                        op1 = "VBoxManage";
 
58
                        op2 = "controlvm " + v.Uuid + " ";
 
59
                        switch (NewState) //do some action, depending on what the desired NewState is
 
60
                        {
 
61
                        case VMState.saved:
 
62
                                op2 += "savestate";
 
63
                                break;
 
64
                        case VMState.off:
 
65
                                op2 += "poweroff";
 
66
                                break;
 
67
                        case VMState.on:
 
68
                                if (v.Status == VMState.paused)
 
69
                                        op2 += "resume";
 
70
                                else if ((v.Status == VMState.off) || (v.Status == VMState.saved))
 
71
                                        op2 = "startvm " + v.Uuid + " -type gui";
 
72
                                break;
 
73
                        case VMState.paused:
 
74
                                op2 += "pause";
 
75
                                break;
 
76
                        case VMState.headless:
 
77
                                if (v.Status == VMState.paused)
 
78
                                        op2 += "resume";
 
79
                                else if ((v.Status == VMState.off) || (v.Status == VMState.saved))
 
80
                                        op2 = "startvm " + v.Uuid + " -type vrdp";
 
81
                                break;
 
82
                        }       
 
83
                }
 
84
                
 
85
                public void DoAction()
 
86
                {
 
87
                        try 
 
88
                        {
 
89
                                if (!CheckState())
 
90
                                {
 
91
                                        Log.Error("State mismatch for {0}.", vm.Name);
 
92
                                        return;
 
93
                                }
 
94
                                vm.Status = VMState.limbo;
 
95
                                ProcessStartInfo ps = new ProcessStartInfo (op1, op2);
 
96
                                ps.UseShellExecute = false;
 
97
                                ps.RedirectStandardOutput = true;
 
98
                                using (Process p = Process.Start (ps)) {
 
99
                                        Log.Info("Execution thread for {0} started.", vm.Name);
 
100
                                        p.WaitForExit ();
 
101
                                        if (p.HasExited)
 
102
                                        {
 
103
                                                vm.Status = NewState;
 
104
                                                Log.Info("Execution thread for {0} finished.", vm.Name);
 
105
                                        }
 
106
                                }       
 
107
                        }
 
108
                        catch 
 
109
                        {
 
110
                                Log.Fatal("Something horrible happened to {0}.", vm.Name);
 
111
                        }
 
112
                }
 
113
                
 
114
                public void DoShutdownRestoreAction()
 
115
                {
 
116
                        try
 
117
                        {
 
118
                                if (!CheckState())
 
119
                                {
 
120
                                        Log.Error("State mismatch for {0}", vm.Name);
 
121
                                        return;
 
122
                                }
 
123
                                vm.Status = VMState.limbo;
 
124
                                List<ProcessStartInfo> Processes = new List<ProcessStartInfo>();
 
125
                                Processes.Add( new ProcessStartInfo ("VBoxManage", "controlvm " + vm.Uuid + " poweroff") );
 
126
                                Processes.Add( new ProcessStartInfo ("sleep", "2") );
 
127
                                Processes.Add( new ProcessStartInfo ("VBoxManage", "snapshot " + vm.Uuid + " discardcurrent -state") );
 
128
                                
 
129
                                Log.Info("Execution thread for {0} started.", vm.Name);
 
130
                                foreach (ProcessStartInfo ps in Processes)
 
131
                                {
 
132
                                        ps.UseShellExecute = false;
 
133
                                        ps.RedirectStandardOutput = true;
 
134
                                        using (Process p = Process.Start (ps))
 
135
                                                p.WaitForExit ();
 
136
                                }
 
137
                                Log.Info("Execution thread for {0} finished.", vm.Name);
 
138
                                vm.Status = VMState.off;
 
139
                        }
 
140
                        catch 
 
141
                        {
 
142
                                Log.Fatal("Something horrible happened to {0}.", vm.Name);
 
143
                        }
 
144
                }
 
145
                
 
146
                public bool CheckState()
 
147
                {
 
148
                        return (vm.Status == vm.CurrentState) ? true : false;
 
149
                }
 
150
        }
 
151
}