2009-11-16 20:19:13 -07:00
|
|
|
// Test suspend/resume
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <climits>
|
|
|
|
#include <vector>
|
|
|
|
#include <ctime>
|
|
|
|
#include <string>
|
|
|
|
using namespace std;
|
|
|
|
|
2010-05-25 22:48:23 -06:00
|
|
|
#include <DFHack.h>
|
2011-05-17 00:36:38 -06:00
|
|
|
#include <dfhack/extra/termutil.h>
|
2011-05-14 22:10:47 -06:00
|
|
|
|
2009-11-16 20:19:13 -07:00
|
|
|
int main (void)
|
|
|
|
{
|
2011-05-14 22:10:47 -06:00
|
|
|
bool temporary_terminal = TemporaryTerminal();
|
2009-11-16 20:19:13 -07:00
|
|
|
string blah;
|
2010-05-23 15:06:10 -06:00
|
|
|
DFHack::ContextManager DFMgr("Memory.xml");
|
|
|
|
DFHack::Context * DF;
|
2010-03-26 06:01:46 -06:00
|
|
|
try
|
2009-11-16 20:19:13 -07:00
|
|
|
{
|
2010-05-23 15:06:10 -06:00
|
|
|
DF = DFMgr.getSingleContext();
|
|
|
|
DF->Attach();
|
2010-03-26 06:01:46 -06:00
|
|
|
}
|
|
|
|
catch (exception& e)
|
|
|
|
{
|
|
|
|
cerr << e.what() << endl;
|
2011-05-14 22:10:47 -06:00
|
|
|
if(temporary_terminal)
|
2010-03-26 06:01:46 -06:00
|
|
|
cin.ignore();
|
2009-11-16 20:19:13 -07:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
cout << "Attached, DF should be suspended now" << endl;
|
|
|
|
getline(cin, blah);
|
|
|
|
|
2010-05-23 15:06:10 -06:00
|
|
|
DF->Resume();
|
2009-11-16 20:19:13 -07:00
|
|
|
cout << "Resumed, DF should be running" << endl;
|
|
|
|
getline(cin, blah);
|
|
|
|
|
2010-05-23 15:06:10 -06:00
|
|
|
DF->Suspend();
|
2009-11-16 20:19:13 -07:00
|
|
|
cout << "Suspended, DF should be suspended now" << endl;
|
|
|
|
getline(cin, blah);
|
|
|
|
|
2010-05-23 15:06:10 -06:00
|
|
|
DF->Resume();
|
2010-01-01 19:25:21 -07:00
|
|
|
cout << "Resumed, testing ForceResume. Suspend using SysInternals Process Explorer" << endl;
|
|
|
|
getline(cin, blah);
|
2009-11-18 18:48:18 -07:00
|
|
|
|
2010-05-23 15:06:10 -06:00
|
|
|
DF->ForceResume();
|
2010-01-01 19:25:21 -07:00
|
|
|
cout << "ForceResumed. DF should be running." << endl;
|
|
|
|
getline(cin, blah);
|
2009-11-18 18:48:18 -07:00
|
|
|
|
2010-05-23 15:06:10 -06:00
|
|
|
if(!DF->Detach())
|
2009-11-16 20:19:13 -07:00
|
|
|
{
|
|
|
|
cerr << "Can't detach from DF" << endl;
|
2011-05-14 22:10:47 -06:00
|
|
|
if(temporary_terminal)
|
|
|
|
cin.ignore();
|
2009-11-16 20:19:13 -07:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
cout << "Detached, DF should be running again" << endl;
|
2011-05-14 22:10:47 -06:00
|
|
|
if(temporary_terminal)
|
|
|
|
getline(cin, blah);
|
2009-11-16 20:19:13 -07:00
|
|
|
return 0;
|
2010-01-01 19:25:21 -07:00
|
|
|
}
|