diff --git a/ile/src/debug.cpp b/ile/src/debug.cpp index 0ae9aa3..b5f6a85 100644 --- a/ile/src/debug.cpp +++ b/ile/src/debug.cpp @@ -13,6 +13,7 @@ extern "C" void STRDBG() debug_fd = fopen("/tmp/manzan_debug.txt", "a"); #endif } + extern "C" void ENDDBG() { #ifdef DEBUG_ENABLED @@ -22,4 +23,18 @@ extern "C" void ENDDBG() debug_fd = NULL; } #endif +} + +extern "C" void DEBUG(const char *format, ...) +{ +#ifdef DEBUG_ENABLED + if (NULL != debug_fd) + { + va_list args; + va_start(args, format); + vfprintf(debug_fd, format, args); + va_end(args); + fflush(debug_fd); + } +#endif } \ No newline at end of file diff --git a/ile/src/handler.cpp b/ile/src/handler.cpp index 0182e2b..16b2dcd 100644 --- a/ile/src/handler.cpp +++ b/ile/src/handler.cpp @@ -93,7 +93,7 @@ int main(int _argc, char **argv) BUFSTRN(watch_option, argv[1], 10); BUFSTRN(session_id, argv[2], 10); - DEBUG("watch program called. Watch option setting is '%s'\n", watch_option.c_str()); + DEBUG("Watch program called. Watch option setting is '%s'\n", watch_option.c_str()); publisher_info_set *publishers = conf_get_publisher_info(session_id.c_str()); int num_publishers = publishers->num_publishers; if (0 == num_publishers) @@ -128,33 +128,36 @@ int main(int _argc, char **argv) char message_watched[8]; message_watched[7] = 0x00; memcpy(message_watched, msg_event->message_watched, 7); - DEBUG("MESSAGE WATCHED IS '%s'\n",message_watched); + DEBUG("MESSAGE WATCHED IS '%s'\n", message_watched); char qualified_msg_file[21]; qualified_msg_file[20] = 0x00; memcpy(qualified_msg_file, msg_event->message_file_name, 10); - memcpy(qualified_msg_file+10, msg_event->message_file_library, 10); + memcpy(qualified_msg_file + 10, msg_event->message_file_library, 10); DEBUG("MESSAGE FILE AND NAME IS '%s'\n", qualified_msg_file); char *replacement_data = (0 == replacement_data_len) ? (char *)"" : (((char *)msg_event) + replacement_data_offset); - char *replacement_data_aligned = (char *)malloc(1+replacement_data_len); - memset(replacement_data_aligned, 0x00, 1+replacement_data_len); + char *replacement_data_aligned = (char *)malloc(1 + replacement_data_len); + memset(replacement_data_aligned, 0x00, 1 + replacement_data_len); memcpy(replacement_data_aligned, replacement_data, (size_t)replacement_data_len); - size_t msg_info_buf_size = 128+sizeof(RTVM0100) + replacement_data_len; - RTVM0100 *msg_info_buf = (RTVM0100*)malloc(msg_info_buf_size); + size_t msg_info_buf_size = 128 + sizeof(RTVM0100) + replacement_data_len; + RTVM0100 *msg_info_buf = (RTVM0100 *)malloc(msg_info_buf_size); memset(msg_info_buf, 0x00, msg_info_buf_size); - if(' ' == qualified_msg_file[0]) { + if (' ' == qualified_msg_file[0]) + { DEBUG("Message not from message file\n"); strncpy(msg_info_buf->message, replacement_data_aligned, replacement_data_len); - } else { + } + else + { char err_plc[64]; memset(err_plc, 0x00, sizeof(err_plc)); - DEBUG("about to format\n"); + DEBUG("About to format...\n"); QMHRTVM( // 1 Message information Output Char(*) msg_info_buf, // 2 Length of message information Input Binary(4) - msg_info_buf_size-1, + msg_info_buf_size - 1, // 3 Format name Input Char(8) "RTVM0100", // 4 Message identifier Input Char(7) diff --git a/ile/src/manzan.h b/ile/src/manzan.h index 3779281..53b065b 100644 --- a/ile/src/manzan.h +++ b/ile/src/manzan.h @@ -78,23 +78,11 @@ extern "C" { #endif - extern FILE *debug_fd; extern void STRDBG(); extern void ENDDBG(); + extern void DEBUG(const char *format, ...); #define DEBUG_ENABLED 1 -#ifdef DEBUG_ENABLED -#define DEBUG(...) \ - if (NULL != debug_fd) \ - { \ - fprintf(debug_fd, __VA_ARGS__); \ - fflush(debug_fd); \ - } -#else -#define STRDBG() -#define DEBUG(...) -#define ENDDBG() -#endif #ifdef __cplusplus } diff --git a/ile/src/pub_db2.sqlc b/ile/src/pub_db2.sqlc index 400e3f1..009ab82 100644 --- a/ile/src/pub_db2.sqlc +++ b/ile/src/pub_db2.sqlc @@ -12,6 +12,19 @@ memset(dest, 0, sizeof(dest)); \ strncpy(dest, parm ? parm : "", -1 + sizeof(dest)); +void check_sql_error(int sqlcode, const char* sqlstate) +{ + if (sqlcode != 0) + { + DEBUG("SQL Code: %d\n", sqlcode); + DEBUG("SQL State: %s\n", sqlstate); + } + else + { + DEBUG("SQL statement executed succesfully!\n"); + } +} + // TODO: implement this // 1. define Db2 tables // // have autoincrement and autotimestamp columns @@ -36,7 +49,7 @@ extern int db2_publish_message(PUBLISH_MESSAGE_FUNCTION_SIGNATURE) COPY_PARM(msg_session_id, _session_id); COPY_PARM(msg_msg_id, _msgid); COPY_PARM(msg_msg_type, _msg_type); - sprintf(msg_severity,"%d", _msg_severity); + sprintf(msg_severity, "%d", _msg_severity); COPY_PARM(msg_timestamp, _msg_timestamp); COPY_PARM(msg_job, _job); COPY_PARM(msg_sending_usrprf, _sending_usrprf); @@ -48,8 +61,9 @@ extern int db2_publish_message(PUBLISH_MESSAGE_FUNCTION_SIGNATURE) EXEC SQL INSERT INTO MANZANMSG( SESSION_ID, MESSAGE_ID, MESSAGE_TYPE, SEVERITY, JOB, SENDING_USRPRF, SENDING_PROGRAM_NAME, SENDING_MODULE_NAME, SENDING_PROCEDURE_NAME, MESSAGE_TIMESTAMP, MESSAGE) - VALUES(:msg_session_id, :msg_msg_id, :msg_msg_type, :msg_severity, :msg_job, :msg_sending_usrprf, :msg_sending_program_name, :msg_sending_module_name, :msg_sending_procedure_name, :msg_timestamp, :msg_message); - return 0; + VALUES( : msg_session_id, : msg_msg_id, : msg_msg_type, : msg_severity, : msg_job, : msg_sending_usrprf, : msg_sending_program_name, : msg_sending_module_name, : msg_sending_procedure_name, : msg_timestamp, : msg_message); + check_sql_error(sqlca.sqlcode, sqlca.sqlstate); + return 0; } extern int db2_publish_vlog(PUBLISH_VLOG_FUNCTION_SIGNATURE) @@ -87,13 +101,12 @@ int db2_publish_pal(PUBLISH_PAL_FUNCTION_SIGNATURE) COPY_PARM(pal_secondary_code, _secondary_code); COPY_PARM(pal_table_id, _table_identifier); sprintf(pal_sequence, "%d", _sequence); - EXEC SQL - INSERT INTO MANZANPAL (SESSION_ID, SYSTEM_REFERENCE_CODE, DEVICE_NAME, MODEL, SERIAL_NUMBER, RESOURCE_NAME, LOG_ID, PAL_TIMESTAMP, REFERENCE_CODE, SECONDARY_CODE, TABLE_ID, SEQUENCE_NUM) - VALUES(:pal_sessid, :pal_system_reference_code, :pal_device_name, :pal_model, :pal_serial_number, :pal_resource_name, :pal_log_identifier, :pal_timestamp, :pal_reference_code, :pal_secondary_code, :pal_table_id, :pal_sequence); - - return 0; + INSERT INTO MANZANPAL(SESSION_ID, SYSTEM_REFERENCE_CODE, DEVICE_NAME, MODEL, SERIAL_NUMBER, RESOURCE_NAME, LOG_ID, PAL_TIMESTAMP, REFERENCE_CODE, SECONDARY_CODE, TABLE_ID, SEQUENCE_NUM) + VALUES( : pal_sessid, : pal_system_reference_code, : pal_device_name, : pal_model, : pal_serial_number, : pal_resource_name, : pal_log_identifier, : pal_timestamp, : pal_reference_code, : pal_secondary_code, : pal_table_id, : pal_sequence); + check_sql_error(sqlca.sqlcode, sqlca.sqlstate); + return 0; } extern int db2_publish_other(PUBLISH_OTHER_FUNCTION_SIGNATURE) @@ -108,6 +121,7 @@ extern int db2_publish_other(PUBLISH_OTHER_FUNCTION_SIGNATURE) strncpy(oth_type, _event_type, 10); EXEC SQL - INSERT INTO MANZANOTH (SESSION_ID,EVENT) VALUES( :oth_sessid, :oth_type); + INSERT INTO MANZANOTH(SESSION_ID, EVENT) VALUES( : oth_sessid, : oth_type); + check_sql_error(sqlca.sqlcode, sqlca.sqlstate); return 0; } \ No newline at end of file diff --git a/test/e2e/msg/snd2file/Makefile b/test/e2e/msg/snd2file/Makefile index 6c78beb..ed13530 100644 --- a/test/e2e/msg/snd2file/Makefile +++ b/test/e2e/msg/snd2file/Makefile @@ -1,6 +1,6 @@ INPUT_FILE:=/tmp/mzntestinput OUTPUT_FILE:=/tmp/mzntestoutput -TEXT:=ayooooooo +TEXT:=My snd2file message setup: rm -f ${INPUT_FILE} ${OUTPUT_FILE} @@ -11,10 +11,11 @@ cleanup: run: /opt/manzan/bin/manzan --configdir=$(CURDIR) > /tmp/manzan.out 2>&1 & - sleep 12 + sleep 15 echo ${TEXT} >> ${INPUT_FILE} sleep 5 cat /tmp/manzan.out checkresult: - grep -i ${TEXT} ${OUTPUT_FILE} + cat ${OUTPUT_FILE} + grep -i "${TEXT}" ${OUTPUT_FILE} diff --git a/test/e2e/msg/snd2q/Makefile b/test/e2e/msg/snd2q/Makefile index 736769e..8999435 100644 --- a/test/e2e/msg/snd2q/Makefile +++ b/test/e2e/msg/snd2q/Makefile @@ -2,7 +2,7 @@ TESTLIB:=MZNTEST INPUT_MSGQ:=QCPFMSG OUTPUT_FILE:=/tmp/mzntestoutput MESSAGE_ID:=*IMMED -MESSAGE:=My first message! +MESSAGE:=My snd2q message MSGTYPE:=*INFO SEVERITY:=80 @@ -10,7 +10,7 @@ SEVERITY:=80 system "CRTMSGQ ${TESTLIB}/MSGS TEXT('Manzan Testing')" setup: /qsys.lib/${TESTLIB}.lib/msgs.msgq - echo "strwch=WCHMSG((*ALL)) WCHMSGQ((${TESTLIB}/MSGS))" >> data.ini + echo "\nstrwch=WCHMSG((*ALL)) WCHMSGQ((${TESTLIB}/MSGS))" >> data.ini cleanup: system -kKv "ENDWCH SSNID(TESTING)" @@ -19,7 +19,7 @@ cleanup: run: /opt/manzan/bin/manzan --configdir=$(CURDIR) > /tmp/manzan.out 2>&1 & - sleep 12 + sleep 15 system -kKv "SNDMSG TOMSGQ(${TESTLIB}/MSGS) MSG('${MESSAGE}') MSGTYPE(${MSGTYPE})" sleep 5 cat /tmp/manzan.out