Skip to content

Commit

Permalink
Add variable server session specific logging
Browse files Browse the repository at this point in the history
  • Loading branch information
jdeans289 committed Apr 21, 2023
1 parent 8c384fb commit 95b5df1
Show file tree
Hide file tree
Showing 23 changed files with 407 additions and 37 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ trickops_logs/
*.gcda
*.dSYM
coverage.info
*.log
69 changes: 69 additions & 0 deletions include/trick/MessageCustomFile.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
PURPOSE:
(Custom log file writable by message_publish.)
ASSUMPTIONS AND LIMITATIONS:
(())
PROGRAMMERS:
(((Jackie Deans) (LinCom) (4/23) (--) (CACI))
*/

#ifndef MESSAGE_CUSTOM_FILE_HH
#define MESSAGE_CUSTOM_FILE_HH

#include <string>
#include <iostream>
#include <fstream>
#include <vector>
#include "trick/MessageFile.hh"

namespace Trick {

/**
* MessageCustomFile writes all messages its level to the given file
*/
class MessageCustomFile : public MessageFile {

public:

/**
@brief The constructor.
*/
MessageCustomFile() ;
// static int openCustomMessageFile(std::string filename, std::string subscriber_name = "");
// static int shutdown_all();

/**
@brief Output message to the file.
*/
virtual void update( unsigned int level , std::string header , std::string message );

/**
* @brief Get the level
*
*/
virtual int get_level();

virtual void set_name(std::string name);
virtual void set_file_name(std::string file_name);


/**
@brief Register this object with the memory manager.
*/
// virtual void register_with_mm();
// virtual void unregister_with_mm();

int this_level;

protected:

static int level_counter;
// static std::vector<MessageCustomFile *>& all_instances();


} ;

}

#endif

54 changes: 54 additions & 0 deletions include/trick/MessageCustomManager.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
PURPOSE:
(Track custom log files.)
ASSUMPTIONS AND LIMITATIONS:
(())
PROGRAMMERS:
(((Jackie Deans) (CACI) (4/23) (--) ())
*/

#ifndef MESSAGE_CUSTOM_MANAGER_HH
#define MESSAGE_CUSTOM_MANAGER_HH

#include <string>
#include <iostream>
#include <fstream>
#include <vector>
#include "trick/MessageCustomFile.hh"
#include "trick/MessageSubscriber.hh"


namespace Trick {

/**
* MessageCustomFile writes all messages its level to the given file
*/
class MessageCustomManager : public MessageSubscriber {

public:

/**
@brief The constructor.
*/
MessageCustomManager() ;
virtual ~MessageCustomManager() ;


// int shutdown_all();
virtual int open_custom_message_file(std::string file_name, std::string subscriber_name, int level = -1);

/**
@brief Output message to the file.
*/
virtual void update( unsigned int level , std::string header , std::string message );

int restart();

protected:
std::vector<MessageCustomFile *> custom_message_files;
} ;

}

#endif

7 changes: 5 additions & 2 deletions include/trick/MessageFile.hh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace Trick {
public:

/** The file name of a file which the messages goes to. \n*/
std::string file_name ; /**< trick_units(--) trick_io(*i) */
std::string file_name ; /**< trick_units(--) trick_io(io) */

/**
@brief The constructor.
Expand All @@ -47,7 +47,7 @@ namespace Trick {
/**
@brief Output message to the file.
*/
virtual void update( unsigned int level , std::string header , std::string message ) ;
virtual void update( unsigned int level , std::string header , std::string message );

/**
@brief Set a file name for a file which the messages received by this subscriber goes to.
Expand All @@ -61,6 +61,9 @@ namespace Trick {
*/
virtual int init() ;

virtual int restart() ;


protected:
/** The output file stream. \n */
std::fstream out_stream ; /**< trick_io(**) */
Expand Down
47 changes: 47 additions & 0 deletions include/trick/MessageHSFile.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
PURPOSE:
(Trick runtime simulation executive parameter definition.)
REFERENCE:
(((Bailey, R.W, and Paddock, E.J.) (Trick Simulation Environment)
(NASA:JSC #37943)
(JSC / Engineering Directorate / Automation and Robotics Division)
(June 1994) (--)))
ASSUMPTIONS AND LIMITATIONS:
((Only 64 levels of nested input data file inclusion.))
PROGRAMMERS:
(((Robert W. Bailey) (LinCom) (4/92) (--) (Realtime))
((Robert W. Bailey) (LinCom) (6/1/91) (Trick-CR-00000) (Initial Release)))
*/

#ifndef MESSAGE_HS_FILE_HH
#define MESSAGE_HS_FILE_HH

#include <string>
#include <iostream>
#include <fstream>
#include "trick/MessageFile.hh"

namespace Trick {

/**
* MessageHSFile writes all messages of levels 0-99 to the send_hs file
*/
class MessageHSFile : public MessageFile {

public:
/**
@brief The constructor.
*/
MessageHSFile() ;

/**
@brief Output message to the file.
*/
virtual void update( unsigned int level , std::string header , std::string message );

} ;

}

#endif

2 changes: 2 additions & 0 deletions include/trick/Message_proto.hh
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@
int message_subscribe( Trick::MessageSubscriber * in_ms ) ;
int message_unsubscribe( Trick::MessageSubscriber * in_ms ) ;

int open_custom_message_file(std::string file_name, std::string subscriber_name, int level = -1);

#endif

17 changes: 15 additions & 2 deletions include/trick/VariableServerSession.hh
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ namespace Trick {
virtual int var_exit();

private:
static int instance_counter;

pthread_mutex_t _copy_mutex; /**< trick_io(**) */

Expand Down Expand Up @@ -447,8 +448,15 @@ namespace Trick {
virtual int get_freeze_frame_offset () const;
virtual bool get_enabled () const;

// Check settings and log message to appropriate places
void log_message(const std::string& msg);
// Check settings and log to appropriate places
void log_received_message(const std::string& msg);
void log_connection_opened ();

bool is_log_open();

void open_session_log();

void write_to_session_log(const std::string& msg);

/** Value set in var_cycle command.\n */
double _update_rate ; /**< trick_io(**) */
Expand Down Expand Up @@ -504,6 +512,9 @@ namespace Trick {
/** Toggle to turn on/off debug info messages.\n */
bool _info_msg ;

/** Message stream number for the log file */
int _log_msg_stream;

/** Toggle to indicate var_pause commanded.\n */
bool _pause_cmd ; /**< trick_io(**) */

Expand All @@ -517,6 +528,8 @@ namespace Trick {
/** Toggle to indicate var_exit commanded.\n */
bool _exit_cmd ; /**< trick_io(**) */

int _instance_num;

};
}

Expand Down
3 changes: 3 additions & 0 deletions include/trick/files_to_ICG.hh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
#include "trick/MessageCout.hh"
#include "trick/MessageThreadedCout.hh"
#include "trick/MessageFile.hh"
#include "trick/MessageHSFile.hh"
#include "trick/MessageCustomFile.hh"
#include "trick/MessageCustomManager.hh"
#include "trick/MessageLCout.hh"
#include "trick/MessagePublisher.hh"
#include "trick/MessageTCDevice.hh"
Expand Down
9 changes: 7 additions & 2 deletions share/trick/sim_objects/default_trick_sys.sm
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ a replacement SimObject will create an uncompilable sim.
##include "trick/MessageThreadedCout.hh"
##include "trick/MessageLCout.hh"
##include "trick/MessageFile.hh"
##include "trick/MessageHSFile.hh"
##include "trick/MessageCustomFile.hh"
##include "trick/MessageCustomManager.hh"
##include "trick/MessageTCDevice.hh"
##include "trick/PlaybackFile.hh"
##include "trick/MemoryManager.hh"
Expand Down Expand Up @@ -258,9 +261,10 @@ class MessageSimObject : public Trick::SimObject {
Trick::MessagePublisher mpublisher ;
Trick::MessageCout mcout ;
Trick::MessageThreadedCout mtcout ;
Trick::MessageFile mfile ;
Trick::MessageHSFile mfile ;
Trick::MessageTCDevice mdevice ;
Trick::PlaybackFile pfile ;
Trick::MessageCustomManager message_file_manager ;

MessageSimObject() {

Expand All @@ -269,6 +273,7 @@ class MessageSimObject : public Trick::SimObject {
{TRK} ("default_data") mpublisher.subscribe(&mfile) ;
{TRK} ("default_data") mpublisher.subscribe(&mdevice) ;
{TRK} ("default_data") mpublisher.subscribe(&pfile) ;
{TRK} ("default_data") mpublisher.subscribe(&message_file_manager) ;
{TRK} ("default_data") mdevice.default_data() ;
{TRK} P1 ("initialization") mpublisher.init() ;
//{TRK} P1 ("initialization") mtcout.init() ;
Expand All @@ -278,9 +283,9 @@ class MessageSimObject : public Trick::SimObject {
{TRK} ("exec_time_tic_changed") mpublisher.init() ;

{TRK} P1 ("restart") mdevice.restart() ;
{TRK} P1 ("restart") message_file_manager.restart() ;
{TRK} ("shutdown") mtcout.shutdown() ;
{TRK} ("shutdown") mdevice.shutdown() ;

}

private:
Expand Down
1 change: 1 addition & 0 deletions test/SIM_test_varserv/RUN_test/unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def main():
trick.real_time_enable()
trick.exec_set_software_frame(0.01)
# trick.set_var_server_info_msg_on()
trick.set_var_server_log_on()

hostname = trick.var_server_get_hostname()

Expand Down
3 changes: 0 additions & 3 deletions test/SIM_test_varserv/models/test_client/test_client.hh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class Socket {

_hostname = hostname;
_port = port;
int tries = 0;

_socket_fd = socket(AF_INET, mode, 0);
if (_socket_fd < 0) {
Expand All @@ -58,7 +57,6 @@ class Socket {
return -1;
}

tries = 0;
int connection_status;

connection_status = connect(_socket_fd, (struct sockaddr *)&serv_addr, sizeof(serv_addr));
Expand All @@ -76,7 +74,6 @@ class Socket {
_multicast_socket = true;
_hostname = hostname;
_port = port;
int tries = 0;

_socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
if (_socket_fd < 0) {
Expand Down
1 change: 1 addition & 0 deletions test/SIM_test_varserv/models/varserv/src/VS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ int VSTest::default_vars() {
blocked_from_input = 500;
blocked_from_output = 1000;

return 0;
}

int VSTest::init() {
Expand Down
2 changes: 1 addition & 1 deletion test_overrides.mk
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ include ${TRICK_HOME}/share/trick/makefiles/Makefile.common
unexport TRICK_PYTHON_PATH

sim_test:
python3 trickops.py --quiet
python3 trickops.py
2 changes: 2 additions & 0 deletions trick_source/sim_services/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ set( SS_SRC
MasterSlave/Slave
Message/MessageCout
Message/MessageFile
Message/MessageHSFile
Message/MessageCustomFile
Message/MessageLCout
Message/MessagePublisher
Message/MessageSubscriber
Expand Down
2 changes: 2 additions & 0 deletions trick_source/sim_services/Message/Makefile_deps
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ object_${TRICK_HOST_CPU}/Message_c_intf.o: Message_c_intf.cpp \
${TRICK_HOME}/include/trick/MessageSubscriber.hh \
${TRICK_HOME}/include/trick/MessageCout.hh \
${TRICK_HOME}/include/trick/MessageFile.hh \
${TRICK_HOME}/include/trick/MessageHSFile.hh \
${TRICK_HOME}/include/trick/MessageCustomFile.hh \
${TRICK_HOME}/include/trick/MessageTCDevice.hh \
${TRICK_HOME}/include/trick/ThreadBase.hh \
${TRICK_HOME}/include/trick/tc.h \
Expand Down
Loading

0 comments on commit 95b5df1

Please sign in to comment.