INET Framework for OMNeT++/OMNEST
PacketDrillScript Class Reference

#include <PacketDrillUtils.h>

Public Member Functions

 PacketDrillScript (const char *file)
 
 ~PacketDrillScript ()
 
void readScript ()
 
int parseScriptAndSetConfig (PacketDrillConfig *config, const char *script_buffer)
 
char * getBuffer ()
 
int getLength () const
 
const char * getScriptPath ()
 
cQueue * getEventList ()
 
cQueue * getOptionList ()
 
void addEvent (PacketDrillEvent *evt)
 
void addOption (PacketDrillOption *opt)
 

Private Attributes

cQueue * optionList
 
cQueue * eventList
 
char * buffer
 
int length
 
const char * scriptPath
 

Constructor & Destructor Documentation

PacketDrillScript::PacketDrillScript ( const char *  file)
273 {
274  eventList = new cQueue("scriptEventList");
275  optionList = new cQueue("scriptOptionList");
276  buffer = nullptr;
277  assert(scriptFile != nullptr);
278  scriptPath = scriptFile;
279  length = 0;
280 }
cQueue * optionList
Definition: PacketDrillUtils.h:608
int length
Definition: PacketDrillUtils.h:611
char * buffer
Definition: PacketDrillUtils.h:610
cQueue * eventList
Definition: PacketDrillUtils.h:609
const char * scriptPath
Definition: PacketDrillUtils.h:612
PacketDrillScript::~PacketDrillScript ( )
283 {
284  for (cQueue::Iterator iter(*eventList); !iter.end(); iter++)
285  eventList->remove((PacketDrillEvent *) (*iter));
286  delete eventList;
287  for (cQueue::Iterator iter(*optionList); !iter.end(); iter++)
288  optionList->remove((PacketDrillEvent *) (*iter));
289  delete optionList;
290 }
Definition: PacketDrillUtils.h:482
cQueue * optionList
Definition: PacketDrillUtils.h:608
cQueue * eventList
Definition: PacketDrillUtils.h:609

Member Function Documentation

void PacketDrillScript::addEvent ( PacketDrillEvent evt)
inline

Referenced by yyparse().

623 { eventList->insert(evt); };
cQueue * eventList
Definition: PacketDrillUtils.h:609
void PacketDrillScript::addOption ( PacketDrillOption opt)
inline

Referenced by yyparse().

624 { optionList->insert((cObject *)opt); };
cQueue * optionList
Definition: PacketDrillUtils.h:608
char* PacketDrillScript::getBuffer ( )
inline
618 { return buffer; };
char * buffer
Definition: PacketDrillUtils.h:610
cQueue* PacketDrillScript::getEventList ( )
inline
621 { return eventList; };
cQueue * eventList
Definition: PacketDrillUtils.h:609
int PacketDrillScript::getLength ( ) const
inline
619 { return length; };
int length
Definition: PacketDrillUtils.h:611
cQueue* PacketDrillScript::getOptionList ( )
inline

Referenced by parse_and_finalize_config().

622 { return optionList; };
cQueue * optionList
Definition: PacketDrillUtils.h:608
const char* PacketDrillScript::getScriptPath ( )
inline

Referenced by parse_script().

620 { return scriptPath; };
const char * scriptPath
Definition: PacketDrillUtils.h:612
int PacketDrillScript::parseScriptAndSetConfig ( PacketDrillConfig config,
const char *  script_buffer 
)
338 {
339  int res = 0;
340  struct invocation invocation = {
341  .config = config,
342  .script = this,
343  };
344 
345  EV_DETAIL << "parse_and_run_script: " << scriptPath << endl;
346 
347  config->setScriptPath(scriptPath);
348 
349  readScript();
350 
351  res = parse_script(config, this, &invocation);
352 
353  return res;
354 }
PacketDrillConfig * config
Definition: PacketDrillUtils.h:338
void setScriptPath(const char *sPath)
Definition: PacketDrillUtils.h:457
void readScript()
Definition: PacketDrillUtils.cc:292
Definition: PacketDrillUtils.h:337
int parse_script(PacketDrillConfig *config, PacketDrillScript *script, struct invocation *callback_invocation)
Definition: parser.cc:206
const char * scriptPath
Definition: PacketDrillUtils.h:612
void PacketDrillScript::readScript ( )
293 {
294  int size = 0;
295 
296  while (buffer == NULL) {
297  struct stat script_info;
298  int fd = -1;
299 
300  /* Allocate a buffer big enough for the whole file. */
301  if (stat(scriptPath, &script_info) != 0)
302  EV_INFO << "parse error: stat() of script file '" << scriptPath << "': " << strerror(errno) << endl;
303 
304  /* Pick a buffer size larger than the file, so we'll
305  * know if the file grew.
306  */
307  size = fmax((int)script_info.st_size, size) + 1;
308 
309  buffer = (char *)malloc((int)size);
310  assert(buffer != NULL);
311 
312  /* Read the file into our buffer. */
313  fd = open(scriptPath, O_RDONLY);
314  if (fd < 0)
315  EV_INFO << "parse error opening script file '" << scriptPath << "': " << strerror(errno) << endl;
316 
317  length = read(fd, buffer, size);
318  if (length < 0)
319  EV_INFO << "parse error reading script file '" << scriptPath << "': " << strerror(errno) << endl;
320 
321  /* If we filled the buffer, then probably another
322  * process wrote more to the file since our stat call,
323  * so we should try again.
324  */
325  if (length == size) {
326  free(buffer);
327  buffer = NULL;
328  length = 0;
329  }
330 
331  if (close(fd))
332  EV_INFO << "File destriptor was closed\n";
333  }
334  EV_INFO << "Script " << scriptPath << " was read with " << length << " length\n";
335 }
void * malloc(YYSIZE_T)
bool close(double one, double two)
Tests whether two doubles are close enough to be declared equal.
Definition: INETMath.h:135
void free(void *)
int length
Definition: PacketDrillUtils.h:611
char * buffer
Definition: PacketDrillUtils.h:610
const char * scriptPath
Definition: PacketDrillUtils.h:612

Member Data Documentation

char* PacketDrillScript::buffer
private
cQueue* PacketDrillScript::eventList
private
int PacketDrillScript::length
private
cQueue* PacketDrillScript::optionList
private
const char* PacketDrillScript::scriptPath
private

The documentation for this class was generated from the following files: