r3353 - in trunk/libmutil: include/libmutil source
mikaelsv at minisip.org
mikaelsv at minisip.org
Wed Aug 8 10:42:26 CEST 2007
Author: mikaelsv
Date: 2007-08-08 10:42:26 +0200 (Wed, 08 Aug 2007)
New Revision: 3353
Modified:
trunk/libmutil/include/libmutil/Timestamp.h
trunk/libmutil/source/Timestamp.cxx
Log:
* The Timestamp class has been extended so that logs can be writted to
arbitrary filenames, and not only to the fixed location previously used.
Modified: trunk/libmutil/include/libmutil/Timestamp.h
===================================================================
--- trunk/libmutil/include/libmutil/Timestamp.h 2007-08-08 08:38:19 UTC (rev 3352)
+++ trunk/libmutil/include/libmutil/Timestamp.h 2007-08-08 08:42:26 UTC (rev 3353)
@@ -1,6 +1,6 @@
/*
Copyright (C) 2005, 2004 Erik Eliasson, Johan Bilien
-
+
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
@@ -89,7 +89,8 @@
void save( uint32_t id );
void save(std::string descr);
void print();
-
+ void print(std::string fileName);
+
#if 0
/**
* initialize the file and writes the init_data
@@ -100,17 +101,17 @@
* file before the measurement results.
*/
void init(std::string filename, std::string init_data);
-
+
/**
* start the timer
*/
void start();
-
+
/**
* stop the timer
*/
void stop();
-
+
/**
* compute the elapsed time in seconds and write it to the
* file defined in init().
@@ -121,26 +122,26 @@
#endif
private:
uint32_t index;
-
+
struct timezone * tz;
-
+
struct timeval * values;
int32_t * ids;
-
+
int auto_id;
std::string *strings;
-
-
+
+
///Time that the timer was started
double startTime;
-
+
///Time that the timer was stopped
double stopTime;
-
+
///the name of the file for saving the results
std::string filename;
-
+
};
extern LIBMUTIL_API Timestamp ts;
Modified: trunk/libmutil/source/Timestamp.cxx
===================================================================
--- trunk/libmutil/source/Timestamp.cxx 2007-08-08 08:38:19 UTC (rev 3352)
+++ trunk/libmutil/source/Timestamp.cxx 2007-08-08 08:42:26 UTC (rev 3353)
@@ -1,6 +1,6 @@
/*
Copyright (C) 2005, 2004 Erik Eliasson, Johan Bilien
-
+
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
@@ -106,12 +106,20 @@
#endif
#ifdef WIN32
- void Timestamp::print(){}
+ void Timestamp::print(std::string fileName){}
#else
- void Timestamp::print(){
+ void Timestamp::print() {
+ print(FILE_NAME);
+ }
+#endif
+
+#ifdef WIN32
+ void Timestamp::print(std::string fileName){}
+#else
+ void Timestamp::print(std::string fileName){
uint32_t i;
struct timeval temp;
- ofstream file( FILE_NAME );
+ ofstream file( fileName.c_str() );
file << "Saved timestamps: " << endl;
temp = values[0];
for( i = 0 ; i < index && i < MAX_TIMESTAMPS; i++ ){
@@ -119,13 +127,13 @@
if (ids[i]<0){
string val = strings[-ids[i]];
// cerr << "will write "<<val<< endl;
- file << " " << val << ":\t"
- << values[i].tv_sec << ":\t"
+ file << " " << val << ":\t"
+ << values[i].tv_sec << ":\t"
<< values[i].tv_usec <<"\t"
<< (values[i].tv_sec - temp.tv_sec)*1000000 + values[i].tv_usec - temp.tv_usec <<endl;
}else
- file << " " << id_names[ ids[i] ] << ":\t"
- << values[i].tv_sec << ":\t"
+ file << " " << id_names[ ids[i] ] << ":\t"
+ << values[i].tv_sec << ":\t"
<< values[i].tv_usec <<"\t"
<< (values[i].tv_sec - temp.tv_sec)*1000000 + values[i].tv_usec - temp.tv_usec <<endl;
temp = values[i];
@@ -139,7 +147,7 @@
#else
void Timestamp::init(std::string filename, std::string init_data){
this->filename=filename;
-
+
ofstream file (&filename[0]);
//write init_data in file
file << init_data << endl;
@@ -174,17 +182,17 @@
#else
string Timestamp::writeElapsedTime(std::string descr){
double elapsedTime = stopTime-startTime;
-
+
//convert to string
ostringstream Str;
Str<<elapsedTime;
string s_elapsedTime(Str.str());
-
+
//enter value into file
ofstream file (&this->filename[0], ios::app);
file << descr << ";" << s_elapsedTime <<endl;
file.close();
-
+
return s_elapsedTime;
}
#endif
More information about the Minisip-devel
mailing list