Changeset 24365
- Timestamp:
- 2011-08-04T10:24:33+12:00 (12 years ago)
- Location:
- gs2-extensions/tdb-edit/trunk/src/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
gs2-extensions/tdb-edit/trunk/src/src/tdbdel-src/tdbdel.cpp
r24041 r24365 32 32 #include <iostream> 33 33 #endif 34 35 #include <cstdlib> 34 36 35 37 #include <fcntl.h> -
gs2-extensions/tdb-edit/trunk/src/src/tdbget-src/tdbget.cpp
r24047 r24365 32 32 #include <iostream> 33 33 #endif 34 35 #include <cstdlib> 34 36 35 37 #include <fcntl.h> -
gs2-extensions/tdb-edit/trunk/src/src/tdbkeys-src/tdbkeys.cpp
r24047 r24365 32 32 #include <iostream> 33 33 #endif 34 35 #include <cstdlib> 34 36 35 37 #include <fcntl.h> -
gs2-extensions/tdb-edit/trunk/src/src/tdbset-src/tdbset.cpp
r24047 r24365 32 32 #include <iostream> 33 33 #endif 34 35 #include <cstdlib> 34 36 35 37 #include <fcntl.h> -
gs2-extensions/tdb-edit/trunk/src/src/txt2tdb-src/txt2tdb.cpp
r24045 r24365 33 33 #include <iostream> 34 34 #endif 35 36 #include <cstdlib> 37 38 #include <time.h> 35 39 36 40 #include "tdb.h" … … 46 50 #endif 47 51 52 /** 53 */ 48 54 void 49 55 printUsage (char *program_name) 50 56 { 51 cerr << "usage: " << program_name << " [ options] database-name" << endl << endl;57 cerr << "usage: " << program_name << " [-append] database-name [-debug]" << endl << endl; 52 58 cerr << "options:" << endl; 53 cerr << " -append append to existing database" << endl << endl; 59 cerr << " -append append to existing database" << endl; 60 cerr << " -debug add timing information to database" << endl << endl; 54 61 } 55 62 /** printUsage() **/ 56 63 64 void 65 debugLog(TDB_CONTEXT * tdb, char * msg_content) 66 { 67 // Since this log will be used to track order of events, we need an indicator 68 // of time 69 time_t seconds = time(NULL); 70 // We also need some idea of what thread this is - let's try and use the PID 71 pid_t process_id = getpid(); 72 // Append the message to the entry in the db (fixed key "debuglog") 73 TDB_DATA key_datum; 74 key_datum.dptr = (unsigned char *)"debuglog"; 75 key_datum.dsize = 8; 76 text_t message = "[" + text_t(seconds) + "][" + text_t(process_id) + "] " + msg_content + "\n"; 77 TDB_DATA msg_datum; 78 msg_datum.dptr = (unsigned char *) message.getcstr(); 79 msg_datum.dsize = message.size(); 80 if (tdb_append(tdb, key_datum, msg_datum) != 0) 81 { 82 cerr << "txt2tdb::debugLog() - tdb_append returned an error" << endl; 83 exit (0); 84 } 85 } 86 /** debugLog() **/ 87 88 /** 89 */ 57 90 int 58 91 main (int argc, char *argv[]) 59 92 { 60 93 // sanity check 61 if ( argc != 2 && argc != 3)94 if (2 > argc || argc > 4) 62 95 { 63 96 printUsage (argv[0]); … … 68 101 int append = 0; 69 102 int delkey = 0; 103 int debug = 0; 70 104 if (argc == 3) 71 105 { … … 74 108 append = 1; 75 109 dbname = argv[2]; 110 } 111 else if (strcmp(argv[2], "-debug") == 0) 112 { 113 dbname = argv[1]; 114 debug = 1; 115 } 116 else 117 { 118 cerr << argv[1] << " is not a valid option." << endl << endl; 119 printUsage(argv[0]); 120 exit (0); 121 } 122 } 123 else if (argc == 4) 124 { 125 if (strcmp (argv[1], "-append") == 0 && strcmp (argv[3], "-debug") == 0) 126 { 127 append = 1; 128 dbname = argv[2]; 129 debug = 1; 76 130 } 77 131 else … … 94 148 tdb_flags = TDB_CLEAR_IF_FIRST; 95 149 } 150 // Disable file IO for testing purposes 151 /*tdb_flags = tdb_flags | TDB_INTERNAL;*/ 152 96 153 int tdb_store_flags = TDB_DEFAULT; // used later when storing 97 154 int open_flags = O_RDWR | O_CREAT; … … 99 156 if (!tdb) 100 157 { 101 cerr << " couldn't create " << dbname << endl;158 cerr << "txt2tdb::main() - couldn't create " << dbname << endl; 102 159 exit (0); 160 } 161 162 // If we are debugging, we'll write that we just opened the connection 163 if (debug) 164 { 165 debugLog(tdb, "opened connection to database for read/write"); 103 166 } 104 167 … … 226 289 } 227 290 291 // If we are debugging, we'll write that we are about to close the connection 292 if (debug) 293 { 294 debugLog(tdb, "closing connection to database"); 295 } 296 228 297 // Close the database connection 229 298 if (tdb_close(tdb) < 0)
Note:
See TracChangeset
for help on using the changeset viewer.