Functions | |
INT | cm_get_error (INT code, char *string) |
INT | cm_set_msg_print (INT system_mask, INT user_mask, int(*func)(const char *)) |
INT | cm_msg_log (INT message_type, const char *message) |
INT | cm_msg_log1 (INT message_type, const char *message, const char *facility) |
INT | cm_msg (INT message_type, const char *filename, INT line, const char *routine, const char *format,...) |
INT | cm_msg1 (INT message_type, const char *filename, INT line, const char *facility, const char *routine, const char *format,...) |
INT | cm_msg_register (void(*func)(HNDLE, HNDLE, EVENT_HEADER *, void *)) |
INT | cm_msg_retrieve1 (char *filename, INT n_message, char *message, INT buf_size) |
INT | cm_msg_retrieve (INT n_message, char *message, INT buf_size) |
Convert error code to string. Used after cm_connect_experiment to print error string in command line programs or windows programs.
code | Error code as defined in midas.h | |
string | Error string |
Definition at line 313 of file midas.c.
Referenced by cm_connect_experiment(), and main().
00314 { 00315 INT i; 00316 00317 for (i = 0; _error_table[i].code; i++) 00318 if (_error_table[i].code == code) { 00319 strcpy(string, _error_table[i].string); 00320 return CM_SUCCESS; 00321 } 00322 00323 sprintf(string, "Unexpected error #%d", code); 00324 return CM_SUCCESS; 00325 }
INT cm_msg | ( | INT | message_type, | |
const char * | filename, | |||
INT | line, | |||
const char * | routine, | |||
const char * | format, | |||
... | ||||
) |
This routine can be called whenever an internal error occurs or an informative message is produced. Different message types can be enabled or disabled by setting the type bits via cm_set_msg_print().
message_type | (See MIDAS Macros). | |
filename | Name of source file where error occured | |
line | Line number where error occured | |
routine | Routine name. | |
format | message to printout, ... Parameters like for printf() |
Definition at line 622 of file midas.c.
Referenced by add_event(), al_check(), al_reset_alarm(), al_trigger_alarm(), analyze_run(), analyzer_init(), ascii_write(), bk_list(), bm_cleanup(), bm_close_buffer(), bm_copy_from_cache(), bm_flush_cache(), bm_open_buffer(), bm_push_event(), bm_receive_event(), bm_remove_event_request(), bm_request_event(), bm_send_event(), bm_set_cache_size(), bm_skip_event(), bm_update_read_pointer(), bm_validate_client_index(), bm_validate_client_pointers(), bm_wait_for_free_space(), bm_wakeup_producers(), book_ntuples(), bor(), check_polled_events(), close_channels(), cm_check_client(), cm_check_deferred_transition(), cm_cleanup(), cm_connect_experiment1(), cm_deregister_transition(), cm_disconnect_experiment(), cm_get_watchdog_info(), cm_list_experiments(), cm_register_deferred_transition(), cm_register_transition(), cm_set_client_info(), cm_set_transition_sequence(), cm_shutdown(), cm_transition(), cm_transition1(), command_loop(), condition_test(), ModbusTcp::Connect(), SqlODBC::Connect(), create_experim_h(), db_check_record(), db_close_database(), db_copy(), db_copy_xml(), db_create_key(), db_create_link(), db_create_record(), db_delete_key1(), db_enum_key(), db_find_key(), db_get_data(), db_get_data_index(), db_get_event_definition(), db_get_key(), db_get_key_info(), db_get_key_time(), db_get_link(), db_get_link_data(), db_get_lock_cnt(), db_get_record(), db_get_value(), db_load(), db_lock_database(), db_open_database(), db_open_record(), db_paste(), db_paste_node(), db_protect_database(), db_save(), db_save_struct(), db_save_xml(), db_save_xml_key(), db_set_data(), db_set_data_index(), db_set_link_data(), db_set_link_data_index(), db_set_record(), db_set_value(), db_unlock_database(), dm_buffer_create(), dump_write(), el_submit(), eor(), evaluate_src(), SqlODBC::Exec(), find_odb_tag(), frontend_init(), ftp_error(), SqlHistory::hs_define_event(), hs_define_event_odbc(), hs_dump(), SqlHistory::hs_get_tags(), hs_get_tags_odbc(), hs_read_odbc(), SqlHistory::hs_write_event(), init_module_parameters(), initialize_equipment(), interprete(), lazy_copy(), lazy_log_update(), lazy_main(), lazy_maintain_check(), lazy_maintain_free_space(), SqlODBC::ListColumns(), SqlODBC::ListTables(), load_fragment(), log_callback(), log_generate_file_name(), log_odb_dump(), log_write(), logger_init(), lrs2365_set(), ma_open(), ma_read_event(), main(), mana_init(), md_dev_os_write(), md_file_ropen(), md_file_wopen(), mfe_set_error(), midas_log_open(), open_history(), process_event(), ps7106_set(), ModbusTcp::Read(), readout_thread(), ModbusTcp::ReadRegister(), receive_event(), receive_trigger_event(), register_equipment(), SqlODBC::ReportErrors(), rpc_flush_event(), rpc_register_functions(), rpc_send_event(), rpc_server_dispatch(), rpc_set_option(), save_list(), scan_fragment(), send_event(), set_history_path(), show_custom_gif(), show_elog_new(), show_elog_page(), show_form_query(), show_hist_page(), show_start_page(), show_status_page(), source_booking(), source_scan(), source_unbooking(), start_the_run(), stop_the_run(), tape_open(), tr_start(), tr_start_abort(), tr_stop(), update_odb(), ModbusTcp::Write(), write_event_ascii(), write_event_hbook(), write_event_odb(), ModbusTcp::WriteRegister(), and ybk_list().
00623 { 00624 va_list argptr; 00625 char event[1000], type_str[256], str[1000], format_cpy[900], local_message[1000], send_message[1000]; 00626 const char *pc; 00627 EVENT_HEADER *pevent; 00628 INT status; 00629 static BOOL in_routine = FALSE; 00630 00631 /* avoid recursive calls */ 00632 if (in_routine) 00633 return 0; 00634 00635 in_routine = TRUE; 00636 00637 /* strip path */ 00638 pc = filename + strlen(filename); 00639 while (*pc != '\\' && *pc != '/' && pc != filename) 00640 pc--; 00641 if (pc != filename) 00642 pc++; 00643 00644 /* convert type to string */ 00645 type_str[0] = 0; 00646 if (message_type & MT_ERROR) 00647 strlcat(type_str, MT_ERROR_STR, sizeof(type_str)); 00648 if (message_type & MT_INFO) 00649 strlcat(type_str, MT_INFO_STR, sizeof(type_str)); 00650 if (message_type & MT_DEBUG) 00651 strlcat(type_str, MT_DEBUG_STR, sizeof(type_str)); 00652 if (message_type & MT_USER) 00653 strlcat(type_str, MT_USER_STR, sizeof(type_str)); 00654 if (message_type & MT_LOG) 00655 strlcat(type_str, MT_LOG_STR, sizeof(type_str)); 00656 if (message_type & MT_TALK) 00657 strlcat(type_str, MT_TALK_STR, sizeof(type_str)); 00658 00659 /* print client name into string */ 00660 if (message_type == MT_USER) 00661 sprintf(send_message, "[%s] ", routine); 00662 else { 00663 rpc_get_name(str); 00664 if (str[0]) 00665 sprintf(send_message, "[%s,%s] ", str, type_str); 00666 else 00667 send_message[0] = 0; 00668 } 00669 00670 local_message[0] = 0; 00671 00672 /* preceed error messages with file and line info */ 00673 if (message_type == MT_ERROR) { 00674 sprintf(str, "[%s:%d:%s,%s] ", pc, line, routine, type_str); 00675 strlcat(send_message, str, sizeof(send_message)); 00676 strlcat(local_message, str, sizeof(send_message)); 00677 } else if (message_type == MT_USER) 00678 sprintf(local_message, "[%s,%s] ", routine, type_str); 00679 00680 /* limit length of format */ 00681 strlcpy(format_cpy, format, sizeof(format_cpy)); 00682 00683 /* print argument list into message */ 00684 va_start(argptr, format); 00685 vsprintf(str, (char *) format, argptr); 00686 va_end(argptr); 00687 strcat(send_message, str); 00688 strcat(local_message, str); 00689 00690 /* call user function if set via cm_set_msg_print */ 00691 if (_message_print != NULL && (message_type & _message_mask_user) != 0) 00692 _message_print(local_message); 00693 00694 /* return if system mask is not set */ 00695 if ((message_type & _message_mask_system) == 0) { 00696 in_routine = FALSE; 00697 return CM_SUCCESS; 00698 } 00699 00700 /* copy message to event */ 00701 pevent = (EVENT_HEADER *) event; 00702 strlcpy(event + sizeof(EVENT_HEADER), send_message, sizeof(event) - sizeof(EVENT_HEADER)); 00703 00704 /* send event if not of type MLOG */ 00705 if (message_type != MT_LOG) { 00706 /* if no message buffer already opened, do so now */ 00707 if (_msg_buffer == 0) { 00708 status = bm_open_buffer(MESSAGE_BUFFER_NAME, MESSAGE_BUFFER_SIZE, &_msg_buffer); 00709 if (status != BM_SUCCESS && status != BM_CREATED) { 00710 in_routine = FALSE; 00711 return status; 00712 } 00713 } 00714 00715 /* setup the event header and send the message */ 00716 bm_compose_event(pevent, EVENTID_MESSAGE, (WORD) message_type, strlen(event + sizeof(EVENT_HEADER)) + 1, 00717 0); 00718 bm_send_event(_msg_buffer, event, pevent->data_size + sizeof(EVENT_HEADER), SYNC); 00719 } 00720 00721 /* log message */ 00722 cm_msg_log(message_type, send_message); 00723 00724 in_routine = FALSE; 00725 00726 return CM_SUCCESS; 00727 }
INT cm_msg1 | ( | INT | message_type, | |
const char * | filename, | |||
INT | line, | |||
const char * | facility, | |||
const char * | routine, | |||
const char * | format, | |||
... | ||||
) |
This routine is similar to cm_msg(). It differs from cm_msg() only by the logging destination being a file given through the argument list i.e:facility
For internal use only.
message_type | See MIDAS Macros. | |
filename | Name of source file where error occured | |
line | Line number where error occured | |
facility | Logging file name | |
routine | Routine name | |
format | message to printout, ... Parameters like for printf() |
Definition at line 754 of file midas.c.
Referenced by lazy_copy(), and lazy_log_update().
00756 { 00757 va_list argptr; 00758 char event[1000], str[256], local_message[256], send_message[256]; 00759 const char *pc; 00760 EVENT_HEADER *pevent; 00761 INT status; 00762 static BOOL in_routine = FALSE; 00763 00764 /* avoid recursive calles */ 00765 if (in_routine) 00766 return 0; 00767 00768 in_routine = TRUE; 00769 00770 /* strip path */ 00771 pc = filename + strlen(filename); 00772 while (*pc != '\\' && *pc != '/' && pc != filename) 00773 pc--; 00774 if (pc != filename) 00775 pc++; 00776 00777 /* print client name into string */ 00778 if (message_type == MT_USER) 00779 sprintf(send_message, "[%s] ", routine); 00780 else { 00781 rpc_get_name(str); 00782 if (str[0]) 00783 sprintf(send_message, "[%s] ", str); 00784 else 00785 send_message[0] = 0; 00786 } 00787 00788 local_message[0] = 0; 00789 00790 /* preceed error messages with file and line info */ 00791 if (message_type == MT_ERROR) { 00792 sprintf(str, "[%s:%d:%s] ", pc, line, routine); 00793 strcat(send_message, str); 00794 strcat(local_message, str); 00795 } 00796 00797 /* print argument list into message */ 00798 va_start(argptr, format); 00799 vsprintf(str, (char *) format, argptr); 00800 va_end(argptr); 00801 00802 if (facility) 00803 sprintf(local_message + strlen(local_message), "{%s} ", facility); 00804 00805 strcat(send_message, str); 00806 strcat(local_message, str); 00807 00808 /* call user function if set via cm_set_msg_print */ 00809 if (_message_print != NULL && (message_type & _message_mask_user) != 0) 00810 _message_print(local_message); 00811 00812 /* return if system mask is not set */ 00813 if ((message_type & _message_mask_system) == 0) { 00814 in_routine = FALSE; 00815 return CM_SUCCESS; 00816 } 00817 00818 /* copy message to event */ 00819 pevent = (EVENT_HEADER *) event; 00820 strcpy(event + sizeof(EVENT_HEADER), send_message); 00821 00822 /* send event if not of type MLOG */ 00823 if (message_type != MT_LOG) { 00824 /* if no message buffer already opened, do so now */ 00825 if (_msg_buffer == 0) { 00826 status = bm_open_buffer(MESSAGE_BUFFER_NAME, MESSAGE_BUFFER_SIZE, &_msg_buffer); 00827 if (status != BM_SUCCESS && status != BM_CREATED) { 00828 in_routine = FALSE; 00829 return status; 00830 } 00831 } 00832 00833 /* setup the event header and send the message */ 00834 bm_compose_event(pevent, EVENTID_MESSAGE, (WORD) message_type, strlen(event + sizeof(EVENT_HEADER)) + 1, 00835 0); 00836 bm_send_event(_msg_buffer, event, pevent->data_size + sizeof(EVENT_HEADER), SYNC); 00837 } 00838 00839 /* log message */ 00840 cm_msg_log1(message_type, send_message, facility); 00841 00842 in_routine = FALSE; 00843 00844 return CM_SUCCESS; 00845 }
Write message to logging file. Called by cm_msg.
message_type | Message type | |
message | Message string |
Definition at line 375 of file midas.c.
Referenced by cm_msg(), and rpc_server_dispatch().
00376 { 00377 char dir[256]; 00378 char filename[256]; 00379 char path[256]; 00380 char str[256]; 00381 INT status, size, fh, semaphore; 00382 HNDLE hDB, hKey; 00383 00384 if (rpc_is_remote()) 00385 return rpc_call(RPC_CM_MSG_LOG, message_type, message); 00386 00387 if (message_type != MT_DEBUG) { 00388 cm_get_experiment_database(&hDB, NULL); 00389 00390 if (hDB) { 00391 00392 strcpy(filename, "midas.log"); 00393 size = sizeof(filename); 00394 db_get_value(hDB, 0, "/Logger/Message file", filename, &size, TID_STRING, TRUE); 00395 00396 if (strchr(filename, '%')) { 00397 /* replace stings such as midas_%y%m%d.mid with current date */ 00398 time_t now; 00399 struct tm *tms; 00400 00401 tzset(); 00402 time(&now); 00403 tms = localtime(&now); 00404 00405 strftime(str, sizeof(str), filename, tms); 00406 strlcpy(filename, str, sizeof(filename)); 00407 } 00408 00409 if (strchr(filename, DIR_SEPARATOR) == NULL) { 00410 status = db_find_key(hDB, 0, "/Logger/Data dir", &hKey); 00411 if (status == DB_SUCCESS) { 00412 size = sizeof(dir); 00413 memset(dir, 0, size); 00414 db_get_value(hDB, 0, "/Logger/Data dir", dir, &size, TID_STRING, TRUE); 00415 if (dir[0] != 0) 00416 if (dir[strlen(dir) - 1] != DIR_SEPARATOR) 00417 strcat(dir, DIR_SEPARATOR_STR); 00418 00419 strcpy(path, dir); 00420 strcat(path, filename); 00421 } else { 00422 cm_get_path(dir); 00423 if (dir[0] != 0) 00424 if (dir[strlen(dir) - 1] != DIR_SEPARATOR) 00425 strcat(dir, DIR_SEPARATOR_STR); 00426 00427 strcpy(path, dir); 00428 strcat(path, "midas.log"); 00429 } 00430 } else { 00431 strcpy(path, filename); 00432 } 00433 } else 00434 strcpy(path, "midas.log"); 00435 00436 fh = open(path, O_WRONLY | O_CREAT | O_APPEND | O_LARGEFILE, 0644); 00437 if (fh < 0) { 00438 printf("Cannot open message log file %s\n", path); 00439 } else { 00440 00441 cm_get_experiment_semaphore(NULL, NULL, NULL, &semaphore); 00442 status = ss_semaphore_wait_for(semaphore, 5 * 1000); 00443 00444 strcpy(str, ss_asctime()); 00445 write(fh, str, strlen(str)); 00446 write(fh, " ", 1); 00447 write(fh, message, strlen(message)); 00448 write(fh, "\n", 1); 00449 close(fh); 00450 00451 ss_semaphore_release(semaphore); 00452 } 00453 } 00454 00455 return CM_SUCCESS; 00456 }
Write message to logging file. Called by cm_msg().
For internal use only.
message_type | Message type | |
message | Message string | |
facility | Message facility, filename in which messages will be written |
Definition at line 467 of file midas.c.
Referenced by cm_msg1(), and rpc_server_dispatch().
00470 : cm_msg_log1 00471 00472 Purpose: Write message to logging file. Called by cm_msg. 00473 Internal use only 00474 00475 Input: 00476 INT message_type Message type 00477 char *message Message string 00478 char * 00479 00480 Output: 00481 none 00482 00483 Function value: 00484 CM_SUCCESS 00485 00486 \********************************************************************/ 00487 { 00488 char dir[256]; 00489 char filename[256]; 00490 char path[256]; 00491 char str[256]; 00492 FILE *f; 00493 INT status, size; 00494 HNDLE hDB, hKey; 00495 00496 00497 if (rpc_is_remote()) 00498 return rpc_call(RPC_CM_MSG_LOG1, message_type, message, facility); 00499 00500 if (message_type != MT_DEBUG) { 00501 cm_get_experiment_database(&hDB, NULL); 00502 00503 if (hDB) { 00504 strcpy(filename, "midas.log"); 00505 size = sizeof(filename); 00506 db_get_value(hDB, 0, "/Logger/Message file", filename, &size, TID_STRING, TRUE); 00507 00508 if (strchr(filename, '%')) { 00509 /* replace stings such as midas_%y%m%d.mid with current date */ 00510 time_t now; 00511 struct tm *tms; 00512 00513 tzset(); 00514 time(&now); 00515 tms = localtime(&now); 00516 00517 strftime(str, sizeof(str), filename, tms); 00518 strlcpy(filename, str, sizeof(filename)); 00519 } 00520 00521 if (strchr(filename, DIR_SEPARATOR) == NULL) { 00522 00523 status = db_find_key(hDB, 0, "/Logger/Data dir", &hKey); 00524 if (status == DB_SUCCESS) { 00525 size = sizeof(dir); 00526 memset(dir, 0, size); 00527 db_get_value(hDB, 0, "/Logger/Data dir", dir, &size, TID_STRING, TRUE); 00528 if (dir[0] != 0) 00529 if (dir[strlen(dir) - 1] != DIR_SEPARATOR) 00530 strcat(dir, DIR_SEPARATOR_STR); 00531 00532 if (facility[0]) { 00533 strcpy(filename, facility); 00534 strcat(filename, ".log"); 00535 } else { 00536 strcpy(filename, "midas.log"); 00537 size = sizeof(filename); 00538 db_get_value(hDB, 0, "/Logger/Message file", filename, &size, TID_STRING, TRUE); 00539 00540 if (strchr(filename, '%')) { 00541 /* replace stings such as midas_%y%m%d.mid with current date */ 00542 time_t now; 00543 struct tm *tms; 00544 00545 tzset(); 00546 time(&now); 00547 tms = localtime(&now); 00548 00549 strftime(str, sizeof(str), filename, tms); 00550 strlcpy(filename, str, sizeof(filename)); 00551 } 00552 } 00553 00554 strcpy(path, dir); 00555 strcat(path, filename); 00556 } else { 00557 cm_get_path(dir); 00558 if (dir[0] != 0) 00559 if (dir[strlen(dir) - 1] != DIR_SEPARATOR) 00560 strcat(dir, DIR_SEPARATOR_STR); 00561 00562 strcpy(path, dir); 00563 if (facility[0]) { 00564 strcat(path, facility); 00565 strcat(path, ".log"); 00566 } else 00567 strcat(path, "midas.log"); 00568 } 00569 } else { 00570 strcpy(path, filename); 00571 *(strrchr(path, DIR_SEPARATOR) + 1) = 0; 00572 if (facility[0]) { 00573 strcat(path, facility); 00574 strcat(path, ".log"); 00575 } else 00576 strcat(path, "midas.log"); 00577 } 00578 } else { 00579 if (facility[0]) { 00580 strcpy(path, facility); 00581 strcat(path, ".log"); 00582 } else 00583 strcpy(path, "midas.log"); 00584 } 00585 00586 f = fopen(path, "a"); 00587 if (f == NULL) { 00588 printf("Cannot open message log file %s\n", path); 00589 } else { 00590 strcpy(str, ss_asctime()); 00591 fprintf(f, "%s", str); 00592 fprintf(f, " %s\n", message); 00593 fclose(f); 00594 } 00595 } 00596 00597 return CM_SUCCESS; 00598 }
INT cm_msg_register | ( | void(*)(HNDLE, HNDLE, EVENT_HEADER *, void *) | func | ) |
Register a dispatch function for receiving system messages.
void receive_message(HNDLE hBuf, HNDLE id, EVENT_HEADER *header, void *message) { char str[256], *pc, *sp; // print message printf("%s\n", (char *)(message)); printf("evID:%x Mask:%x Serial:%i Size:%d\n" ,header->event_id ,header->trigger_mask ,header->serial_number ,header->data_size); pc = strchr((char *)(message),']')+2; ... // skip none talking message if (header->trigger_mask == MT_TALK || header->trigger_mask == MT_USER) ... } int main(int argc, char *argv[]) { ... // now connect to server status = cm_connect_experiment(host_name, exp_name, "Speaker", NULL); if (status != CM_SUCCESS) return 1; // Register callback for messages cm_msg_register(receive_message); ... }
func | Dispatch function. |
Definition at line 886 of file midas.c.
Referenced by main().
00887 { 00888 INT status, id; 00889 00890 /* if no message buffer already opened, do so now */ 00891 if (_msg_buffer == 0) { 00892 status = bm_open_buffer(MESSAGE_BUFFER_NAME, MESSAGE_BUFFER_SIZE, &_msg_buffer); 00893 if (status != BM_SUCCESS && status != BM_CREATED) 00894 return status; 00895 } 00896 00897 _msg_dispatch = func; 00898 00899 status = bm_request_event(_msg_buffer, EVENTID_ALL, TRIGGER_ALL, GET_NONBLOCKING, &id, func); 00900 00901 return status; 00902 }
Retrieve old messages from log file
n_message | Number of messages to retrieve | |
message | buf_size bytes of messages, separated by characters. The returned number of bytes is normally smaller than the initial buf_size, since only full lines are returned. | |
*buf_size | Size of message buffer to fill |
Definition at line 985 of file midas.c.
Referenced by command_loop(), rpc_server_dispatch(), show_custom_page(), and show_messages_page().
00986 { 00987 char dir[256], str[256]; 00988 char filename[256], filename2[256]; 00989 char path[256], *message2; 00990 INT status, size, n, i; 00991 HNDLE hDB, hKey; 00992 time_t now; 00993 struct tm *tms; 00994 00995 if (rpc_is_remote()) 00996 return rpc_call(RPC_CM_MSG_RETRIEVE, n_message, message, buf_size); 00997 00998 cm_get_experiment_database(&hDB, NULL); 00999 status = 0; 01000 01001 if (hDB) { 01002 strcpy(filename, "midas.log"); 01003 size = sizeof(filename); 01004 db_get_value(hDB, 0, "/Logger/Message file", filename, &size, TID_STRING, TRUE); 01005 01006 strlcpy(filename2, filename, sizeof(filename2)); 01007 01008 if (strchr(filename, '%')) { 01009 /* replace strings such as midas_%y%m%d.mid with current date */ 01010 tzset(); 01011 time(&now); 01012 tms = localtime(&now); 01013 01014 strftime(filename2, sizeof(str), filename, tms); 01015 } 01016 01017 if (strchr(filename2, DIR_SEPARATOR) == NULL) { 01018 status = db_find_key(hDB, 0, "/Logger/Data dir", &hKey); 01019 if (status == DB_SUCCESS) { 01020 size = sizeof(dir); 01021 memset(dir, 0, size); 01022 db_get_value(hDB, 0, "/Logger/Data dir", dir, &size, TID_STRING, TRUE); 01023 if (dir[0] != 0) 01024 if (dir[strlen(dir) - 1] != DIR_SEPARATOR) 01025 strcat(dir, DIR_SEPARATOR_STR); 01026 01027 strcpy(path, dir); 01028 strcat(path, filename2); 01029 } else { 01030 cm_get_path(dir); 01031 if (dir[0] != 0) 01032 if (dir[strlen(dir) - 1] != DIR_SEPARATOR) 01033 strcat(dir, DIR_SEPARATOR_STR); 01034 01035 strcpy(path, dir); 01036 strcat(path, filename2); 01037 } 01038 } else { 01039 strcpy(path, filename2); 01040 } 01041 } else 01042 strcpy(path, "midas.log"); 01043 01044 n = cm_msg_retrieve1(path, n_message, message, buf_size); 01045 01046 while (n < n_message && strchr(filename, '%')) { 01047 now -= 3600 * 24; // go one day back 01048 tms = localtime(&now); 01049 01050 strftime(filename2, sizeof(str), filename, tms); 01051 01052 if (strchr(filename2, DIR_SEPARATOR) == NULL) { 01053 status = db_find_key(hDB, 0, "/Logger/Data dir", &hKey); 01054 if (status == DB_SUCCESS) { 01055 size = sizeof(dir); 01056 memset(dir, 0, size); 01057 db_get_value(hDB, 0, "/Logger/Data dir", dir, &size, TID_STRING, TRUE); 01058 if (dir[0] != 0) 01059 if (dir[strlen(dir) - 1] != DIR_SEPARATOR) 01060 strcat(dir, DIR_SEPARATOR_STR); 01061 01062 strcpy(path, dir); 01063 strcat(path, filename2); 01064 } else { 01065 cm_get_path(dir); 01066 if (dir[0] != 0) 01067 if (dir[strlen(dir) - 1] != DIR_SEPARATOR) 01068 strcat(dir, DIR_SEPARATOR_STR); 01069 01070 strcpy(path, dir); 01071 strcat(path, filename2); 01072 } 01073 } else { 01074 strcpy(path, filename2); 01075 } 01076 01077 message2 = (char *) malloc(buf_size); 01078 01079 i = cm_msg_retrieve1(path, n_message - n, message2, buf_size - strlen(message) - 1); 01080 if (i < 0) 01081 break; 01082 strlcat(message2, "\r\n", buf_size); 01083 01084 memmove(message + strlen(message2), message, strlen(message) + 1); 01085 memcpy(message, message2, strlen(message2)); 01086 free(message2); 01087 n += i; 01088 } 01089 01090 return status; 01091 }
Definition at line 905 of file midas.c.
Referenced by cm_msg_retrieve().
00906 { 00907 FILE *f; 00908 INT offset, i, j; 00909 char *p; 00910 00911 f = fopen(filename, "rb"); 00912 if (f == NULL) { 00913 sprintf(message, "Cannot open message log file %s\n", filename); 00914 return -1; 00915 } 00916 00917 /* position buf_size bytes before the EOF */ 00918 fseek(f, -(buf_size - 1), SEEK_END); 00919 offset = ftell(f); 00920 if (offset != 0) { 00921 /* go to end of line */ 00922 fgets(message, buf_size - 1, f); 00923 offset = ftell(f) - offset; 00924 buf_size -= offset; 00925 } 00926 00927 memset(message, 0, buf_size); 00928 fread(message, 1, buf_size - 1, f); 00929 message[buf_size - 1] = 0; 00930 fclose(f); 00931 00932 p = message + (buf_size - 2); 00933 00934 /* goto end of buffer */ 00935 while (p != message && *p == 0) 00936 p--; 00937 00938 /* strip line break */ 00939 j = 0; 00940 while (p != message && (*p == '\n' || *p == '\r')) { 00941 *(p--) = 0; 00942 j = 1; 00943 } 00944 00945 00946 /* trim buffer so that last n_messages remain */ 00947 for (i = 0; i < n_message; i++) { 00948 while (p != message && *p != '\n') 00949 p--; 00950 00951 while (p != message && (*p == '\n' || *p == '\r')) 00952 p--; 00953 00954 if (p == message) 00955 break; 00956 00957 j++; 00958 } 00959 if (p != message) { 00960 p++; 00961 while (*p == '\n' || *p == '\r') 00962 p++; 00963 } 00964 00965 buf_size = (buf_size - 1) - (p - message); 00966 00967 memmove(message, p, buf_size); 00968 message[buf_size] = 0; 00969 00970 return j; 00971 }
Set message masks. When a message is generated by calling cm_msg(), it can got to two destinatinons. First a user defined callback routine and second to the "SYSMSG" buffer.
A user defined callback receives all messages which satisfy the user_mask.
int message_print(const char *msg) { char str[160]; memset(str, ' ', 159); str[159] = 0; if (msg[0] == '[') msg = strchr(msg, ']')+2; memcpy(str, msg, strlen(msg)); ss_printf(0, 20, str); return 0; } ... cm_set_msg_print(MT_ALL, MT_ALL, message_print); ...
system_mask | Bit masks for MERROR, MINFO etc. to send system messages. | |
user_mask | Bit masks for MERROR, MINFO etc. to send messages to the user callback. | |
func | Function which receives all printout. By setting "puts", messages are just printed to the screen. |
Definition at line 358 of file midas.c.
Referenced by cm_connect_experiment1(), ctrlc_odbedit(), main(), and usage().
00359 { 00360 _message_mask_system = system_mask; 00361 _message_mask_user = user_mask; 00362 _message_print = func; 00363 00364 return BM_SUCCESS; 00365 }