2 //=============================================================================
6 * This file implements the command possible to execute on the
7 * concurrency service's lock set interface. The file also contains
8 * an implementation of a command list used by the command parser to
9 * store the commands to be executed.
11 * @author Torben Worm <tworm@cs.wustl.edu>
13 //=============================================================================
16 #include "orbsvcs/CosConcurrencyControlC.h"
18 #ifndef _CC_COMMAND_H_
19 #define _CC_COMMAND_H_
24 * @brief Defines an abstact class for the commands towards the lock set
26 * This class declares an interface to run a test towards one or more
27 * lock sets in the concurrency service. The class provides a virtual
28 * execute method that is common for all its subclasses. It is also the
29 * the base class for the auxillary commands start, wait, and sleep.
35 virtual ~CC_Command();
37 /// Abstract execute method
38 virtual int execute() = 0;
41 /// Function to look up the lock set we are operating on, or if the
42 /// name is "" return the global lock set variable
43 CosConcurrencyControl::LockSet_var
44 GetLockSet (const char *lock_set_name
);
46 /// Default constructor. We do not want instances of this class
50 * The last exception raised in one of the test commands. This variable
51 * is checked by all commands in order to determine if an exception has
52 * been raised. This is necessary because sometimes we want to check that
53 * an event caused an exception (done by the CC_Excep_Cmd command class)
54 * as part of the testing.
56 static CORBA::Exception
*excep_
;
58 /// This is the default lock set. The variable is either set by a create
59 /// command without name or by the lookup command.
60 static CosConcurrencyControl::LockSet_var cc_lockset_
;
68 * @brief Defines a class for the start command
70 * This class represents the start command. The start command is used
71 * to start a new process with another script file in order to test the
72 * aspects of the concurrency service that requires several processes
73 * running at the same time.
75 class CC_Start_Cmd
: public CC_Command
79 CC_Start_Cmd (const char *config_file_name
);
82 virtual ~CC_Start_Cmd();
84 /// Start the child process. The current version does not wait for the
85 /// process to terminate.
86 virtual int execute();
89 /// The name of the script file
94 * @class CC_CreateLockSet_Cmd
96 * @brief Defines a class for the create command on the lock set factory
98 * This class represents the create command on the lock set factory.
99 * The lock set is registered in the naming service with the provided
102 class CC_CreateLockSet_Cmd
: public CC_Command
106 CC_CreateLockSet_Cmd (const char *lock_set_name
);
109 virtual ~CC_CreateLockSet_Cmd ();
111 /// Executes the command, i.e. creates the lock set and binds the name
112 /// in the naming service.
113 virtual int execute();
116 /// The name used to bind in the naming service.
121 * @class CC_Lock_Cmd:public
123 * @brief Defines a class for the lock command on the lock set
125 * This class represents the lock command on the lock set. The lock set
126 * is looked up in the naming service.
128 class CC_Lock_Cmd
:public CC_Command
132 CC_Lock_Cmd(const char *lock_set_name
,
133 CosConcurrencyControl::lock_mode mode
);
136 virtual ~CC_Lock_Cmd();
138 /// Executes the command, i.e. looks up the lock set with the requested
139 /// name in the naming server and executes the lock command on that lock set.
140 virtual int execute();
143 /// The name to look up in the naming service.
146 /// The mode of the lock.
147 CosConcurrencyControl::lock_mode mode_
;
151 * @class CC_UnLock_Cmd:public
153 * @brief Defines a class for the unlock command on the lock set
155 * This class represents the unlock command on the lock set. The lock set
156 * is looked up in the naming service.
158 class CC_UnLock_Cmd
:public CC_Command
162 CC_UnLock_Cmd(const char *lock_set_name
,
163 CosConcurrencyControl::lock_mode mode
);
166 virtual ~CC_UnLock_Cmd();
169 * Executes the command, i.e. looks up the lock set with the requested
170 * name in the naming server and executes the unlock command on that
173 virtual int execute();
176 /// The name to look up in the naming service.
179 /// The mode of the lock.
180 CosConcurrencyControl::lock_mode mode_
;
184 * @class CC_TryLock_Cmd:public
186 * @brief Defines a class for the try_lock command on the lock set
188 * This class represents the try_lock command on the lock set. The lock set
189 * is looked up in the naming service.
191 class CC_TryLock_Cmd
:public CC_Command
195 CC_TryLock_Cmd(const char *lock_set_name
,
196 CosConcurrencyControl::lock_mode mode
);
199 virtual ~CC_TryLock_Cmd();
202 * Executes the command, i.e. looks up the lock set with the requested
203 * name in the naming server and executes the try_lock command on that
206 virtual int execute();
209 /// The name to look up in the naming service.
212 /// The mode of the lock.
213 CosConcurrencyControl::lock_mode mode_
;
217 * @class CC_ChangeMode_Cmd:public
219 * @brief Defines a class for the change_mode command on the lock set
221 * This class represents the change_mode command on the lock set.
222 * The lock set is looked up in the naming service.
224 class CC_ChangeMode_Cmd
:public CC_Command
228 CC_ChangeMode_Cmd (const char *lock_set_name
,
229 CosConcurrencyControl::lock_mode held_mode
,
230 CosConcurrencyControl::lock_mode new_mode
);
233 virtual ~CC_ChangeMode_Cmd();
236 * Executes the command, i.e. looks up the lock set with the requested
237 * name in the naming server and executes the change_mode command on that
240 virtual int execute();
243 /// The name to look up in the naming service.
246 /// The mode of the held lock
247 CosConcurrencyControl::lock_mode held_mode_
;
249 /// The new mode of the lock
250 CosConcurrencyControl::lock_mode new_mode_
;
254 * @class CC_Sleep_Cmd:public
256 * @brief Defines a class for the sleep command
258 * This class represents the sleep command. This command is used to make
259 * the script pause for the requested number of second, e.g. to wait for
260 * another process to start.
262 class CC_Sleep_Cmd
:public CC_Command
266 CC_Sleep_Cmd(int seconds
);
269 virtual ~CC_Sleep_Cmd();
271 /// Executes the command.
272 virtual int execute();
275 /// The number of seconds to sleep
280 * @class CC_Repeat_Cmd:public
282 * @brief Defines a class for the repeat command
284 * This class represents the repeat command. This command is used to make
285 * the script repeat the test the requested number of times.
286 * The command is curently NOT implemented.
288 class CC_Repeat_Cmd
:public CC_Command
292 CC_Repeat_Cmd(int times
);
295 virtual ~CC_Repeat_Cmd();
297 /// Executes the command.
298 virtual int execute();
300 /// The number of times the commands should be repeated
305 * @class CC_Wait_Cmd:public
307 * @brief Defines a class for the wait command
309 * This class represents the wait command. This command is used to make
310 * the script wait for the user to press return. It is possible to print
311 * different prompts, e.g. instructions.
313 class CC_Wait_Cmd
:public CC_Command
317 CC_Wait_Cmd (const char *prompt
);
320 virtual ~CC_Wait_Cmd();
322 /// Executes the command.
323 virtual int execute();
326 /// The prompt to print on the screen
331 * @class CC_Excep_Cmd
333 * @brief Defines a class for the excep command
335 * This class represents the excep command. This command is used to make
336 * the script capable of dealing with cases where an exception is raised
337 * as part of the testing.
339 class CC_Excep_Cmd
: public CC_Command
343 CC_Excep_Cmd (const char *excep
);
346 virtual ~CC_Excep_Cmd();
349 * Executes the command. Checks to see if the excep_ class variable is set,
350 * and if that's the case check that it is of the expected type. If not the
353 virtual int execute();
356 /// The string representation of the expected exception
361 * @class CC_Dummy_Cmd:
363 * @brief Defines a class for the dummy command
365 * This class represents the dummy command. This command is used to
366 * put in a command in the chain that does nothing.
368 class CC_Dummy_Cmd
: public CC_Command
375 virtual ~CC_Dummy_Cmd();
377 /// Executes the command, i.e. does nothing.
378 virtual int execute();
384 * @class CC_Print_Cmd:
386 * @brief Defines a class for the print command
388 * This class represents the print command. This command is used to
389 * print a message on stdout
391 class CC_Print_Cmd
: public CC_Command
395 CC_Print_Cmd (const char *message
);
398 virtual ~CC_Print_Cmd();
400 /// Executes the command.
401 virtual int execute();
404 /// Holds the message to print
409 * @class CC_Lookup_Cmd:public
411 * @brief Defines a class for the lookup command.
413 * This class represents the lookup command. The lock set
414 * is looked up in the naming service and the class variable
415 * cc_lockset_ is set accordingly.
417 class CC_Lookup_Cmd
:public CC_Command
421 CC_Lookup_Cmd (const char *lock_set_name
);
424 virtual ~CC_Lookup_Cmd();
426 /// Executes the command, i.e. looks up the lock set with the requested
427 /// name in the naming server and sets the cc_lockset_ variable.
428 virtual int execute();
431 /// The name to look up in the naming service.
436 * @class CC_CommandElem
438 * @brief Defines a class for a command element
440 * This class implements a command element used in the command list
441 * below. The class is a simple tupple holding a pointer to the command
442 * and a pointer to the next element in the list.
448 CC_CommandElem (CC_Command
*cmd
, CC_CommandElem
*next
);
453 /// Returns a pointer to the command in this element
454 CC_Command
*GetCommand();
456 /// Returns the pointer to the next element
457 CC_CommandElem
*GetNext();
459 /// Sets the next pointer
460 void SetNext(CC_CommandElem
*next
);
463 /// Pointer to the next element
464 CC_CommandElem
*next_
;
466 /// Pointer to the command element
471 * @class CC_CommandList
473 * @brief Defines a class for a command list
475 * This class implements a command list used from the script parser
476 * to store the parsed commands The class implements a simple single
488 /// Adds the command to the list
489 int add(CC_Command
*cmd
);
491 /// Executes all the commands in the list from head to tail
494 /// Sets the number of times to repeat the script
495 void setrepeat(int times
);
498 /// The head of the command list
499 CC_CommandElem
*head_
;
501 /// The last inserted element
502 CC_CommandElem
*last_
;
504 /// The number of times the script should be repeated
508 #endif /* _CC_COMMAND_H_ */