Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

utils.cc

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2003 CTIE, Monash University
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017 */
00018 
00019 #include <string.h>
00020 #include <omnetpp.h>
00021 #include "utils.h"
00022 
00023 char *fgetline (FILE *fp)
00024 {
00025     // alloc buffer and read a line
00026     char *line = new char[MAX_LINE];
00027     if (fgets(line,MAX_LINE,fp)==NULL)
00028         return NULL;
00029 
00030     // chop CR/LF
00031     line[MAX_LINE-1] = '\0';
00032     int len = strlen(line);
00033     while (len>0 && (line[len-1]=='\n' || line[len-1]=='\r'))
00034         line[--len]='\0';
00035 
00036     return line;
00037 }
00038 
00039 //---
00040 
00041 MessageTracer MessageTracer::trc;
00042 unsigned int MessageId::nextId;
00043 unsigned int MessageId::nextTreeId;
00044 
00045 MessageTracer::MessageTracer()
00046 {
00047     f = NULL;
00048     lastId = NULL;
00049 }
00050 
00051 MessageTracer::~MessageTracer()
00052 {
00053     if (f)
00054         fclose(f);
00055 }
00056 
00057 void MessageTracer::open()
00058 {
00059     f = fopen("msgtrace.out","w");
00060 }
00061 
00062 void MessageTracer::created(MessageId *m)
00063 {
00064     if (!f) open();
00065     if (lastId) fprintf(f,"C I:%d T:%d P:%d E:%ld %s\n", lastId->id, lastId->treeId, lastId->parentId,
00066                         simulation.eventNumber(), simulation.contextModule()->fullPath());
00067     lastId = m;
00068 }
00069 
00070 void MessageTracer::cloned(MessageId *m)
00071 {
00072     if (!f) open();
00073     fprintf(f,"L I:%d T:%d P:%d E:%ld %s\n", m->id, m->treeId, m->parentId,
00074             simulation.eventNumber(), simulation.contextModule()->fullPath());
00075 }
00076 
00077 void MessageTracer::assigned(MessageId *m)
00078 {
00079     if (!f) open();
00080     fprintf(f,"A I:%d T:%d P:%d E:%ld %s\n", m->id, m->treeId, m->parentId,
00081             simulation.eventNumber(), simulation.contextModule()->fullPath());
00082     if (m==lastId) lastId = NULL;
00083 }
00084 
00085 void MessageTracer::deleted(MessageId *m)
00086 {
00087     fprintf(f,"D I:%d T:%d P:%d E:%ld %s\n", m->id, m->treeId, m->parentId,
00088             simulation.eventNumber(), simulation.contextModule()->fullPath());
00089 }
00090 
00091 
00092 
00093 

Generated on Sat May 15 20:30:43 2004 for Ethernet by doxygen1.2.17