41 if (strcasecmp(
key.
name,
"image") == 0) {
43 cm_msg(
MINFO,
"hs_get_history",
"History channel \'IMAGE\' handled by image facility");
48 size =
sizeof(active);
61 printf(
"hs_get_history: see channel hkey %d, name \'%s\', active %d, type [%s], debug %d\n",
hKey,
key.
name, active,
type.c_str(),
debug);
63 if (strcasecmp(
type.c_str(),
"MIDAS")==0) {
77 cm_msg(
MERROR,
"hs_get_history",
"mlogger ODB setting /Logger/WriteFileHistory is obsolete, please delete it. Use /Logger/History/MIDAS/Active instead");
86 (*mh)->hs_set_debug(
debug);
88 status = (*mh)->hs_connect(path.c_str());
90 cm_msg(
MERROR,
"hs_get_history",
"Cannot connect to MIDAS history, status %d",
status);
95 cm_msg(
MINFO,
"hs_get_history",
"Connected history channel \'%s\' type MIDAS history in \"%s\"",
key.
name, path.c_str());
98 }
else if (strcasecmp(
type.c_str(),
"ODBC")==0) {
107 cm_msg(
MERROR,
"hs_get_history",
"mlogger ODB setting /Logger/ODBC_Debug is obsolete, please delete it. Use /Logger/History/ODBC/Debug instead");
112 cm_msg(
MERROR,
"hs_get_history",
"mhttpd ODB setting /History/ODBC_Debug is obsolete, please delete it. Use /Logger/History/ODBC/Debug instead");
119 cm_msg(
MERROR,
"hs_get_history",
"mlogger ODB setting /Logger/ODBC_DSN is obsolete, please delete it. Use /Logger/History/ODBC/Writer_ODBC_DSN instead");
124 cm_msg(
MERROR,
"hs_get_history",
"mhttpd ODB setting /History/ODBC_DSN is obsolete, please delete it. Use /Logger/History/ODBC/Reader_ODBC_DSN instead");
128 std::string writer_dsn =
"history_writer";
129 std::string reader_dsn =
"history_reader";
147 }
else if (dsn.length() > 1) {
154 (*mh)->hs_set_debug(
debug);
156 status = (*mh)->hs_connect(dsn.c_str());
158 cm_msg(
MERROR,
"hs_get_history",
"Cannot connect to ODBC SQL driver \'%s\', status %d. Check .odbc.ini and MIDAS documentation", dsn.c_str(),
status);
163 cm_msg(
MINFO,
"hs_get_history",
"Connected history channel \'%s\' type ODBC (MySQL), DSN \'%s\'",
key.
name, dsn.c_str());
165 }
else if (strcasecmp(
type.c_str(),
"SQLITE")==0) {
178 (*mh)->hs_set_debug(
debug);
180 status = (*mh)->hs_connect(path.c_str());
182 cm_msg(
MERROR,
"hs_get_history",
"Cannot connect to SQLITE history, status %d, see messages",
status);
187 cm_msg(
MINFO,
"hs_get_history",
"Connected history channel \'%s\' type SQLITE in \'%s\'",
key.
name, path.c_str());
189 }
else if (strcasecmp(
type.c_str(),
"FILE")==0) {
204 (*mh)->hs_set_debug(
debug);
206 status = (*mh)->hs_connect(path.c_str());
208 cm_msg(
MERROR,
"hs_get_history",
"Cannot connect to FILE history, status %d, see messages",
status);
213 cm_msg(
MINFO,
"hs_get_history",
"Connected history channel \'%s\' type FILE in \'%s\'",
key.
name, path.c_str());
215 }
else if (strcasecmp(
type.c_str(),
"MYSQL")==0) {
217 std::string writer_dsn =
"mysql_writer.txt";
218 std::string reader_dsn =
"mysql_reader.txt";
252 (*mh)->hs_set_debug(
debug);
254 status = (*mh)->hs_connect(path.c_str());
256 cm_msg(
MERROR,
"hs_get_history",
"Cannot connect to MYSQL history, status %d",
status);
261 cm_msg(
MINFO,
"hs_get_history",
"Connected history channel \'%s\' type MYSQL at \'%s\'",
key.
name,
264 }
else if (strcasecmp(
type.c_str(),
"PGSQL")==0) {
266 std::string writer_dsn =
"pgsql_writer.txt";
267 std::string reader_dsn =
"pgsql_reader.txt";
297 size =
sizeof(downsample);
306 (*mh)->hs_set_debug(
debug);
309 status = (*mh)->hs_connect(path.c_str());
311 cm_msg(
MERROR,
"hs_get_history",
"Cannot connect to PGSQL history, status %d",
status);
316 cm_msg(
MINFO,
"hs_get_history",
"Connected history channel \'%s\' type PGSQL at \'%s\'",
key.
name,
319 }
else if (strcasecmp(
type.c_str(),
"IMAGE")==0) {
321 cm_msg(
MINFO,
"hs_get_history",
"History channel \'IMAGE\' handled by image facility");
323 cm_msg(
MERROR,
"hs_get_history",
"Logger history channel /Logger/History/%s/Type has invalid value \'%s\', valid values are MIDAS, ODBC, SQLITE, MYSQL, FILE and IMAGE",
key.
name,
type.c_str());
330 mstrlcpy((*mh)->name,
key.
name,
sizeof((*mh)->name));
331 mstrlcpy((*mh)->type,
type.c_str(),
sizeof((*mh)->type));
343 std::string hschanname;
349 cm_msg(
MERROR,
"hs_find_reader_channel",
"Cannot find /Logger/History, db_find_key() status %d",
status);
358 if (hschanname.length() > 0) {
361 cm_msg(
MERROR,
"hs_find_reader_channel",
"Misconfigured history: history channel name in /History/LoggerHistoryChannel is \'%s\', not present in /Logger/History, db_find_key() status %d", hschanname.c_str(),
status);
371 for (
int ichan=0; ; ichan++) {
377 size =
sizeof(active);
385 cm_msg(
MERROR,
"hs_find_reader_channel",
"Cannot find default history: /History/LoggerHistoryChannel is empty and there are no active history channels in /Logger/History");
392 return path +
".LOGGER_HISTORY_EVENTS.TXT";
399 for (
unsigned i=0;
i<pevents->size();
i++)
400 ss += (*pevents)[
i] +
"\n";
404 FILE *
fp = fopen(fname.c_str(),
"w");
406 cm_msg(
MERROR,
"hs_save_event_list",
"Cannot open file \'%s\', errno %d (%s)", fname.c_str(), errno, strerror(errno));
410 const char* s = ss.c_str();
413 int wr =
write(fileno(
fp), s, len);
416 cm_msg(
MERROR,
"hs_save_event_list",
"Cannot write to file \'%s\', errno %d (%s)", fname.c_str(), errno, strerror(errno));
430 FILE *
fp = fopen(fname.c_str(),
"r");
432 cm_msg(
MERROR,
"hs_read_event_list",
"Cannot open file \'%s\', errno %d (%s)", fname.c_str(), errno, strerror(errno));
438 char *s = fgets(buf,
sizeof(buf),
fp);
442 s = strchr(buf,
'\n');
445 s = strchr(buf,
'\r');
448 pevents->push_back(buf);
std::string cm_get_path()
std::string cm_get_history_path(const char *history_channel)
MidasHistoryInterface * MakeMidasHistory()
INT cm_msg(INT message_type, const char *filename, INT line, const char *routine, const char *format,...)
INT db_get_value(HNDLE hDB, HNDLE hKeyRoot, const char *key_name, void *data, INT *buf_size, DWORD type, BOOL create)
INT db_get_key(HNDLE hDB, HNDLE hKey, KEY *key)
INT EXPRT db_get_value_string(HNDLE hdb, HNDLE hKeyRoot, const char *key_name, int index, std::string *s, BOOL create, int create_string_length)
INT db_find_key(HNDLE hDB, HNDLE hKey, const char *key_name, HNDLE *subhKey)
INT db_enum_key(HNDLE hDB, HNDLE hKey, INT idx, HNDLE *subkey_handle)
int hs_read_event_list(std::vector< std::string > *pevents)
int hs_save_event_list(const std::vector< std::string > *pevents)
int hs_find_reader_channel(HNDLE hDB, HNDLE *hKeyOut, int debug_flag)
int hs_get_history(HNDLE hDB, HNDLE hKey, int flags, int debug_flag, MidasHistoryInterface **mh)
static std::string hs_event_list_filename()
MidasHistoryInterface * MakeMidasHistoryODBC()
MidasHistoryInterface * MakeMidasHistorySqlDebug()
MidasHistoryInterface * MakeMidasHistorySqlite()
MidasHistoryInterface * MakeMidasHistoryMysql()
MidasHistoryInterface * MakeMidasHistoryPgsql()
MidasHistoryInterface * MakeMidasHistoryFile()
BOOL debug
debug printouts
#define DIR_SEPARATOR_STR
MidasHistoryInterface * mh
#define write(n, a, f, d)