File: ARCer.h

package info (click to toggle)
magnus 20060324-3
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 19,404 kB
  • ctags: 20,466
  • sloc: cpp: 130,118; ansic: 37,076; tcl: 10,970; perl: 1,109; makefile: 963; sh: 403; yacc: 372; csh: 57; awk: 33; asm: 10
file content (225 lines) | stat: -rw-r--r-- 7,335 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
// Copyright (C) 1995 The New York Group Theory Cooperative
// See magnus/doc/COPYRIGHT for the full notice.

// Contents: Declaration of class ARCer.
//
// Principal Author: Dmitry Bormotov.
//
// Status: in progress
//
// Revision History:
//
// * 7/96 Dmitry B. made porting to gcc 2.7.2.
//

#ifndef _ARCER_H_
#define _ARCER_H_


#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <fstream.h>
#include <iostream.h>
#include <sys/wait.h>
#include "MagnusHome.h"
#include "ComputationManager.h"


// ----------------------------- ARCer ------------------------------------- //

//@njz: added to avoid complain of GCC-4.0.1
class ComputationManager;
//

class ARCer
{

public:


  /////////////////////////////////////////////////////////////////////////
  //                                                                     //
  // Constructors:                                                       //
  //                                                                     //
  /////////////////////////////////////////////////////////////////////////

  ARCer( ComputationManager& boss, const int delay = 1 );

    
  /////////////////////////////////////////////////////////////////////////
  //                                                                     //
  // Accessors:                                                          //
  //                                                                     //
  /////////////////////////////////////////////////////////////////////////
 
  bool isInterrupted() { return bInterrupted; }
  
  int getPid( ) { return pid; }

  int delay( ) { return theDelay; }

  virtual bool takeControl( );
  
  virtual void terminate( );

       
  /////////////////////////////////////////////////////////////////////////
  //                                                                     //
  // IPC interaction members:                                            //
  //                                                                     //
  /////////////////////////////////////////////////////////////////////////

  virtual void runComputation( ) = 0;

  virtual void writeResults( ostream& ) = 0;

  virtual void readResults( istream& ) = 0;
 

  /////////////////////////////////////////////////////////////////////////
  //                                                                     //
  // Data Members:                                                       //
  //                                                                     //
  /////////////////////////////////////////////////////////////////////////
  
  Chars startDir;

protected:
  
  int pid;
  int theDelay;
  bool bInterrupted;
  ComputationManager& theBoss;
};


// ------------------------- ExternalARCer --------------------------------- //


class ExternalARCer : public ARCer
{
  
public:

  /////////////////////////////////////////////////////////////////////////
  //                                                                     //
  // Constructors:                                                       //
  //                                                                     //
  /////////////////////////////////////////////////////////////////////////

  ExternalARCer( ComputationManager& boss, 
		 const char* cmdline, 
		 const int delay = 1 );

  
  /////////////////////////////////////////////////////////////////////////
  //                                                                     //
  // Accessors:                                                          //
  //                                                                     //
  /////////////////////////////////////////////////////////////////////////
 
  // Inherited from ARCer:
  //
  // bool isInterrupted( );
  // int  getPid( );
  // void terminate( );

  virtual bool takeControl( );

       
  /////////////////////////////////////////////////////////////////////////
  //                                                                     //
  // IPC interaction members:                                            //
  //                                                                     //
  /////////////////////////////////////////////////////////////////////////

  virtual void writeArguments( ostream& ) = 0;

  virtual void readResults( istream& ) = 0;
 

private:

  /////////////////////////////////////////////////////////////////////////
  //                                                                     //
  // Private functions:                                                  //
  //                                                                     //
  /////////////////////////////////////////////////////////////////////////

  void writeResults( ostream& ) { }

  void runComputation( );
  
 
  /////////////////////////////////////////////////////////////////////////
  //                                                                     //
  // Data members:                                                       //
  //                                                                     //
  /////////////////////////////////////////////////////////////////////////
    
  Chars theCmdLine;
  Chars argFN;
  Chars resultFN;
};


// @db The following class is an experimental version of new ARCer
// class and included here just because of the NormalClosure.

// ----------------------------- ARCer2 ------------------------------------ //


class ARCer2 : public ARCer
{
  
public:

  enum State { RUNNING, READING, FINISHED };

  /////////////////////////////////////////////////////////////////////////
  //                                                                     //
  // Constructors:                                                       //
  //                                                                     //
  /////////////////////////////////////////////////////////////////////////

  ARCer2( ComputationManager& boss, const int delay = 1 );

  ~ARCer2( ) { delete in; }

    
  /////////////////////////////////////////////////////////////////////////
  //                                                                     //
  // Accessors:                                                          //
  //                                                                     //
  /////////////////////////////////////////////////////////////////////////
 
  virtual bool takeControl( );

  void terminate( );
 
         
  /////////////////////////////////////////////////////////////////////////
  //                                                                     //
  // IPC interaction members:                                            //
  //                                                                     //
  /////////////////////////////////////////////////////////////////////////

  virtual bool readResults2( istream& ) = 0;
 

  /////////////////////////////////////////////////////////////////////////
  //                                                                     //
  // Data Members:                                                       //
  //                                                                     //
  /////////////////////////////////////////////////////////////////////////

private:
  
  State state;
  ifstream* in;
};


#endif