Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move DEBUG implementation out of header file and add sql code/state check #147

Merged
merged 4 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions ile/src/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ extern "C" void STRDBG()
debug_fd = fopen("/tmp/manzan_debug.txt", "a");
#endif
}

extern "C" void ENDDBG()
{
#ifdef DEBUG_ENABLED
Expand All @@ -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
}
25 changes: 14 additions & 11 deletions ile/src/handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
14 changes: 1 addition & 13 deletions ile/src/manzan.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
32 changes: 23 additions & 9 deletions ile/src/pub_db2.sqlc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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;
}
7 changes: 4 additions & 3 deletions test/e2e/msg/snd2file/Makefile
Original file line number Diff line number Diff line change
@@ -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}
Expand All @@ -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}
6 changes: 3 additions & 3 deletions test/e2e/msg/snd2q/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ TESTLIB:=MZNTEST
INPUT_MSGQ:=QCPFMSG
OUTPUT_FILE:=/tmp/mzntestoutput
MESSAGE_ID:=*IMMED
MESSAGE:=My first message!
MESSAGE:=My snd2q message
MSGTYPE:=*INFO
SEVERITY:=80

/qsys.lib/${TESTLIB}.lib/msgs.msgq:
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)"
Expand All @@ -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
Expand Down