Merge in variable server priority changes

This commit is contained in:
Deans 2023-06-27 15:11:10 -05:00
commit 1d13f4b055
171 changed files with 12194 additions and 3906 deletions

View File

@ -29,7 +29,7 @@ jobs:
- name: Install GTest
run: |
dnf config-manager --enable ol8_codeready_builder
dnf install -y gtest-devel
dnf install -y gtest-devel gmock-devel
- name: Checkout repository
uses: actions/checkout@master

View File

@ -37,6 +37,7 @@ jobs:
maven
cmake
zip
gdb
install_gtest: echo gtest already installed
conf_pkg: echo package manager already configured
install_cmd: install -y
@ -64,7 +65,7 @@ jobs:
python3-pip
python3-venv
install_gtest: |
apt-get install -y libgtest-dev
apt-get install -y libgtest-dev libgmock-dev
cd /usr/src/gtest
cmake .
make
@ -100,7 +101,9 @@ jobs:
libX11-devel
libXt-devel
swig3
gtest-devel
install_gtest: |
yum install -y http://repo.okay.com.mx/centos/7/x86_64/release/okay-release-1-6.el7.noarch.rpm
yum install -y gtest gtest-devel gmock gmock-devel
#-------- RHEL 8-based Only Dependencies ----------------
- cfg: { arch: rhel, arch_ver: 8 }
pkg_mgr: dnf
@ -113,12 +116,12 @@ jobs:
dnf install -y 'dnf-command(config-manager)'
install_gtest: |
dnf config-manager --enable powertools
dnf install -y gtest-devel
dnf install -y gtest-devel gmock-devel
#-------- OS and Version Specific Dependencies ----------------
- cfg: { os: oraclelinux }
install_gtest: |
dnf config-manager --enable ol8_codeready_builder
dnf install -y gtest-devel
dnf install -y gtest-devel gmock-devel
#-------- Job definition ----------------
runs-on: ubuntu-latest
container: docker://${{matrix.cfg.os}}:${{matrix.cfg.tag}}

4
.gitignore vendored
View File

@ -40,4 +40,6 @@ archive/
trickops_logs/
*.gcda
*.gcno
coverage.info
coverage.info
*.dSYM
*.log

View File

@ -175,7 +175,7 @@ set( IO_SRC
${CMAKE_BINARY_DIR}/temp_src/io_src/io_JITEvent.cpp
${CMAKE_BINARY_DIR}/temp_src/io_src/io_JITInputFile.cpp
${CMAKE_BINARY_DIR}/temp_src/io_src/io_JSONVariableServer.cpp
${CMAKE_BINARY_DIR}/temp_src/io_src/io_JSONVariableServerThread.cpp
${CMAKE_BINARY_DIR}/temp_src/io_src/io_JSONVariableServerSessionThread.cpp
${CMAKE_BINARY_DIR}/temp_src/io_src/io_JobData.cpp
${CMAKE_BINARY_DIR}/temp_src/io_src/io_MM4_Integrator.cpp
${CMAKE_BINARY_DIR}/temp_src/io_src/io_MSConnect.cpp
@ -231,7 +231,7 @@ set( IO_SRC
${CMAKE_BINARY_DIR}/temp_src/io_src/io_VariableServer.cpp
${CMAKE_BINARY_DIR}/temp_src/io_src/io_VariableServerListenThread.cpp
${CMAKE_BINARY_DIR}/temp_src/io_src/io_VariableServerReference.cpp
${CMAKE_BINARY_DIR}/temp_src/io_src/io_VariableServerThread.cpp
${CMAKE_BINARY_DIR}/temp_src/io_src/io_VariableServerSessionThread.cpp
${CMAKE_BINARY_DIR}/temp_src/io_src/io_Zeroconf.cpp
${CMAKE_BINARY_DIR}/temp_src/io_src/io_attributes.cpp
${CMAKE_BINARY_DIR}/temp_src/io_src/io_dllist.cpp

View File

@ -95,6 +95,7 @@ UTILS_DIRS := \
${TRICK_HOME}/trick_source/trick_utils/interpolator \
${TRICK_HOME}/trick_source/trick_utils/trick_adt \
${TRICK_HOME}/trick_source/trick_utils/comm \
${TRICK_HOME}/trick_source/trick_utils/connection_handlers \
${TRICK_HOME}/trick_source/trick_utils/shm \
${TRICK_HOME}/trick_source/trick_utils/math \
${TRICK_HOME}/trick_source/trick_utils/units \
@ -105,6 +106,7 @@ UTILS_OBJS := $(addsuffix /object_$(TRICK_HOST_CPU)/*.o ,$(UTILS_DIRS))
# filter out the directories that make their own libraries
UTILS_OBJS := $(filter-out ${TRICK_HOME}/trick_source/trick_utils/comm/%, $(UTILS_OBJS))
UTILS_OBJS := $(filter-out ${TRICK_HOME}/trick_source/trick_utils/connection_handlers/%, $(UTILS_OBJS))
UTILS_OBJS := $(filter-out ${TRICK_HOME}/trick_source/trick_utils/math/%, $(UTILS_OBJS))
UTILS_OBJS := $(filter-out ${TRICK_HOME}/trick_source/trick_utils/units/%, $(UTILS_OBJS))
UTILS_OBJS := $(filter-out ${TRICK_HOME}/trick_source/trick_utils/var_binary_parser/%, $(UTILS_OBJS))
@ -458,6 +460,7 @@ uninstall:
rm -f ${PREFIX}/$(notdir ${TRICK_LIB_DIR})/liber7_utils.a
rm -f ${PREFIX}/$(notdir ${TRICK_LIB_DIR})/libtrick.a
rm -f ${PREFIX}/$(notdir ${TRICK_LIB_DIR})/libtrick_comm.a
rm -f ${PREFIX}/$(notdir ${TRICK_LIB_DIR})/libtrick_connection_handlers.a
rm -f ${PREFIX}/$(notdir ${TRICK_LIB_DIR})/libtrick_math.a
rm -f ${PREFIX}/$(notdir ${TRICK_LIB_DIR})/libtrick_mm.a
rm -f ${PREFIX}/$(notdir ${TRICK_LIB_DIR})/libtrick_pyip.a

View File

@ -0,0 +1,446 @@
# Variable Server Refactor
The goals of this refactor were as follows:
1. Test the Trick Variable Server
- At the start, the variable server was completely uncovered by CI. This can be seen in the earliest builds uploaded to Coveralls (https://coveralls.io/builds/53258598)
- Identified a need for both unit and sim tests
- Significant refactoring was needed to be able to do any unit tests
2. Create a generic representation for a session that can be used in the webserver as well
- Currently, the webserver implementation is completely separate from the variable server, even through they do they same thing. There is a lot of repeated functionality between the two.
- The current implementation of the variable server made it impossible to reuse any of its code.
3. Clarify and document code.
## Class Structure
### VariableServer.hh
The overarching variable server object. It is instantiated in VariableServerSimObject and is intended to be a singleton.
Responsibilities:
- Initialize a listen thread
- Keep track of all sessions
- Interface with the Trick scheduler through the Trick jobs, and delegate to sessions
- Provide the API for all variable server commands to go through, and delegate to correct session
### VariableServerListenThread.hh
Opens a TCP port and listens for new client connections until shut down. Only 1 exists by default as a member of VariableServer,
but additional listen threads can be created through a call to trick.var_server_create_tcp_socket()
Responsibilities:
- Open a TCP port for listening
- Continuously listen on the port
- Broadcast the port on the multicast channel
- When a client connection comes in, set up the connection, start a thread, and wait for the thread to start the connection
- Delete the thread if the connection fails
### VariableServerSessionThread.hh
Runs asynchronous parts for the single VariableServerSession.
Responsibilities:
- Accept the connection and pass it into the VariableServerSession
- Delete the session and close the connection on shutdown
- Run the parts of VariableServerSession that run asynchronously until user commands shutdown or sim shutdown, including:
- Tell VSSession to read from connection and execute command
- Tell VSSession to copy sim data (if in correct mode)
- Tell VSSession to write data (if in correct mode)
### VariableServerSession.hh
Track information and execute commands for a single client session.
Responsibilities:
- Keep track of the list of variables
- Track desired copy/write mode and timing
- Overrideable behaviors:
- Write out to connection when commanded
- Read in and execute commands from connection when commanded
### VariableReference.hh
Represent a single variable in a session
Responsibilities:
- Copy sim data into internal buffer when commanded
- Write sim data into stream when commanded
- Provide functions to write ASCII and binary data
- Track what units the user has requested
- Survive a checkpoint restart
### TCPClientListener.hh
Represents a listening TCP server
Responsibilities:
- Encapsulate network code
- Provide an interface to start a server, listen for new connections, and create new connections
- Create a TCPConnection when a client connects
### ClientConnection.hh
Responsibilities
Abstract class representing a connection to a client. Inherited classes to handle TCP, UDP, and Multicast connections
- Encapsulate network code
- Provide a generic interface for initializing, starting, shutting down, reading, and writing to network regardless of connection type
## Threading changes
### VariableServerListenThread is required to wait for VariableServerSessionThread to notify it when the connection has been accepted.
This was present in old design, but not implemented safely.
#### Old design:
```
VariableServerSessionThread
+ wait_for_accept()
- bool connection_accepted = false
```
`wait_for_accept` just busy waits on `connection_accepted` with no synch constructs (John Borland would be horrified)
VariableServerListenThread calls `VsThread.wait_for_accept()`
No error handling if connection failed, which can result in hanging listen thread and extra VSThreads bc of other problems in listen thread
#### New Design
```
VariableServerSessionThread
+ enum ConnectionStatus { CONNECTION_PENDING, CONNECTION_SUCCESS, CONNECTION_FAIL };
+ wait_for_accept()
- ConnectionStatus _connection_status = CONNECTION_PENDING
- pthread_mutex_t _connection_status_mutex
- pthread_cond_t _connection_status_cv
VariableServerSessionThread::thread_body
Try to accept connection
if connection fails:
with _connection_status_mutex:
set _connection_status to CONNECTION_FAIL
signal on _connection_status_cv
exit thread
Do some other setup
with _connection_status_mutex:
set _connection_status to CONNECTION_SUCCESS
signal on _connection_status_cv
Run loop
VariableServerSessionThread::wait_for_accept
with _connection_status_mutex:
while _connection_status == CONNECTION_PENDING:
wait on _connection_status_cv
return _connection_status
VariableServerListenThread::thread_body
When we're trying to set up a connection:
Create new VSThread, set up the connection, start the thread
status = VSThread->wait_for_accept()
if status is CONNECTION_FAIL:
make sure the thread has exited and delete it
```
### VariableServerSessionThread and VariableServerListenThread no longer use pthread_cancel
New termination design:
```
Additions to Threadbase
+ test_shutdown(/* optional exit handler args */)
+ thread_shutdown(/* optional exit handler args */)
- bool cancellable = true
- pthread_mutex_t shutdown_mutex
- bool should_shutdown = false
ThreadBase::test_shutdown:
with shutdown_mutex
if should_shutdown:
call thread_shutdown
ThreadBase::thread_shutdown
Call exit handler if one passed
Call pthread_exit(0)
Addition to function of Threadbase::cancel_thread():
with shutdown_mutex: Set should_shutdown to true
if cancellable == true, call pthread_cancel
```
Threads can set cancellable to false in their constructor, which VariableServerSessionThread and VariableServerListenThread do
Instead, they call test_shutdown at points that would be appropriate to shutdown in their loops
Careful design consideration and testing was taken so that if the threads never start, or various error cases are hit, this still goes ok
### VariableServerSessionThread and VariableServerListenThread pause on checkpoint reload
#### Old design:
```
VariableServerSessionThread and VariableServerListenThread
- pthread_mutex_t restart_pause
```
This mutex is acquired by the top of the loops while they do their main processing, and released at the bottom of the loop.
The main thread acquires the mutex in preload_checkpoint jobs and releases in restart jobs.
This created a few bugs:
- a deadlock in VariableServerSessionThread due to a lock inversion with the VariableServer map mutex
- For some reason, holding the lock while blocked on the select syscall by the VariableServerListenThread could cause some really weird bugs, so the lock was acquired after the select call and only if it returned true. Because of this, select could be run while checkpoint restart was happening, which sometimes resulted in false positives, which created extra VariableServerSessionThreads, and the connection status was never checked so they would never shut down and cause all kinds of problems.
#### New design
```
Addition to SysThread
+ void force_thread_to_pause()
+ void unpause_thread()
+ void test_pause()
- pthread_mutex_t _restart_pause_mutex
- bool _thread_should_pause
- pthread_cond_t _thread_wakeup_cv
- bool _thread_has_paused
- pthread_cond_t _thread_has_paused_cv
```
This design still ensures that thread can be paused, and that the main thread will wait until the threads are paused. It uses condvars to solve the deadlock problem and doesn't cause bugs observed in the old design.
The main thread can control the SysThread by calling `thread->force_thead_to_pause()`, which will block until the SysThread has paused, and `thread->unpause_thread()`. The SysThread loops must call `test_pause()` at points that would be appropriate to pause.
SysThread uses a monitor pattern internally to implement this behavior. Pseudocode for the pause managment:
```
// Called from main thread
SysThread::force_thread_to_pause()
with _restart_pause_mutex:
_thread_should_pause = true
while !_thread_has_paused:
wait on _thread_has_paused_cv
// Called from main thread
SysThread::unpause_thread():
with _restart_pause_mutex:
_thread_should_pause = false
signal on _thread_wakeup_cv
// Called from SysThread
SysThread::test_pause():
with _restart_pause_mutex:
if _thread_should_pause:
_thread_has_paused = true
signal on _thread_has_paused_cv
while _thread_should_pause
wait on _thread_wakeup_cv
_thread_has_paused = false
```
## VariableReference
The VariableReference class existed in the old version only to hold buffers for copied values, it had no methods.
In the refactored version, the VariableReference class encapsulates all interaction with the memory manager and sim variables, including copying and formatting the values. VariableReference keeps track of the units that have been requested for this variable in this session. VariableReference provides an interface to write out the value of a variable in either Ascii or binary format.
It still uses REF2 internally, but the encapsulation will make the (hopefully) impending transition to something else easier to manage.
The VariableReference class is covered by unit tests.
```
VariableReference Interface
+ VariableReference(std::string var_name)
+ std::string getName()
+ TRICK_TYPE getType()
+ std::string getBaseUnits()
+ int setRequestedUnits(std::string new_units)
+ int stageValue ()
+ int prepareForWrite ()
+ bool isStaged ()
+ bool isWriteReady ()
+ int writeValueAscii( std::ostream& out )
+ int writeValueBinary( std::ostream& out , bool byteswap = false)
+ ((Other methods to write out information about the binary or ascii formats))
```
## VariableServerSession
The VariableServerSession class is a new class created in this refactor. A lot of the behavior of the old VariableServerSessionThread class is now in this class.
A VariableServerSession represents a single client session. It tracks the list of variables that are being sent, the copy and write mode, output format mode, cycle, pause state, exit command.
The VariableServerSession has methods that should be called from Trick job types to implement correct moding -
```
// Called from different types of Trick jobs.
// Determines whether this session should be copying and/or writing, and performs those actions if so
+ int copy_and_write_freeze(long long curr_frame);
+ int copy_and_write_freeze_scheduled(long long curr_tics);
+ int copy_and_write_scheduled(long long curr_tics);
+ int copy_and_write_top(long long curr_frame);
// Called from VariableServerSessionThread
+ virtual int copy_and_write_async();
```
The VariableServerSession has a method that should be called when it is time to handle a message and act on it. This is called from the VariableServerSessionThread loop.
```
+ virtual int handle_message();
```
The VariableServerSession has the entirety of the documented VariableServer API as methods as well. These are called from the single VariableServer object after looking up the session.
The VariableServerSession class is covered by unit tests.
## VariableServerSessionThread
The VariableServerSessionThread class runs and manages the lifetime and synchronization of a VariableServerSessionThread, sets up and closes the connection for the VariableServerSession, and calls any VariableServerSession methods that are designed to be asynchronous with the main thread. This includes `handle_message` and `copy_and_write_async`. It also creates the cycle of the session.
```
VariableServerSessionThread_loop.cpp
- void thread_body()
VariableServerSessionThread.cpp
+ void preload_checkpoint()
+ void restart()
+ ConnectionStatus wait_for_accept()
```
`thread_body()` runs the main loop of the VST.
`preload_checkpoint()` and `restart()` are called from their respective Trick jobs in the main thread.
## VariableServer
The VariableServer class itself has been the least changed by this refactor.
Its main job is to delegate between the Trick jobs and the various sessions and threads. The VariableServer is a singleton that is declared as part of a SimObject in `default_trick_sys.sm`
```
VariableServerSimObject {
VariableServer vs;
{TRK} ("default_data") vs.default_data() ;
{TRK} P0 ("initialization") trick_ret = vs.init() ;
{TRK} ("preload_checkpoint") vs.suspendPreCheckpointReload();
{TRK} ("restart") vs.restart();
{TRK} ("restart") vs.resumePostCheckpointReload();
{TRK} ("top_of_frame") vs.copy_and_write_top() ;
{TRK} ("automatic_last") vs.copy_and_write_scheduled() ;
{TRK} ("freeze_init") vs.freeze_init() ;
{TRK} ("freeze_automatic") vs.copy_and_write_freeze_scheduled() ;
{TRK} ("freeze") vs.copy_and_write_freeze() ;
{TRK} ("shutdown") vs.shutdown() ;
}
```
In each job:
- default_data: Initialize the listening socket with any port
- initialization: If the user has requested a different port, set that up. Start the listening thead.
- preload_checkpoint: call methods of all VariableServerListenThreads and VariableServerSessionThreads to pause in preparation for checkpoint
- restart: recreate listening threads if necessary, and call restart methods of all VariableServerListenThreads and VariableServerSessionThreads
- top_of_frame, automatic_last, freeze, freeze_automatic: Loop through all VariableServerSessions and call the appropriate copy_data_ variant
- shutdown: cancel all VariableServerListenThreads and VariableServerSessionThreads
The VariableServer implements part of the dataflow for commands that come in through the input processor.
The VariableServer's external API is the entry point of the variable server commands that are passed though the input processor. These commands go to a C-style API, which query the static global singleton VariableServer object. Each of these commands will look up the correct session by pthread_id and call the session's command.
```
Client sends `"trick.var_add("my_variable")\n"`
`VariableServerSessionThread::thread_body` calls `VariableServerSession::handle_mesage`
`VariableServerSession::handle_mesage` reads from the client connection and calls `ip_parse("trick.var_add("my_variable")\n")`
Python interpreter runs (on the variable server thread) back through the SWIG layer to invoke global method `var_add("my_variable")` in var_server_ext.cpp
`var_add()` calls the static global variable server object to look up the current session, mapped to the current pthread_id
`var_add()` calls `session->var_add("my_variable")`
session will add my_variable to its list of variables
Return from `ip_parse`, continue `thread_body` processing
```
Code snippets (some minor modifications for clarity):
```
// var_server_ext.cpp
int var_add(std::string in_name) {
Trick::VariableServerSession * session = get_session();
if (session != NULL ) {
session->var_add(in_name) ;
}
return(0) ;
}
Trick::VariableServerSession * get_session() {
return the_vs->get_session(pthread_self()) ;
}
// VariableServer.cpp
Trick::VariableServerSession * Trick::VariableServer::get_session(pthread_t thread_id) {
Trick::VariableServerSession * ret = NULL ;
pthread_mutex_lock(&map_mutex) ;
auto it = var_server_sessions.find(thread_id) ;
if ( it != var_server_sessions.end() ) {
ret = (*it).second ;
}
pthread_mutex_unlock(&map_mutex) ;
return ret ;
}
// VariableServerSession_commands.cpp
int Trick::VariableServerSession::var_add(std::string in_name) {
VariableReference new_var = new VariableReference(in_name);
_session_variables.push_back(new_var) ;
return(0) ;
}
```
![var_add Sequence Diagram](images/var_add_sequence.png)
Both var_server_ext.cpp and VariableServerSession_commands.cpp have a method for each command in the user facing variable server API.
### Special case listen threads and sessions
The user can request addition TCP, UDP, or multicast servers from the input file. This is handled in the VariableServer class.
```
VariableServer {
+ int create_tcp_socket(const char * address, unsigned short in_port )
+ int create_udp_socket(const char * address, unsigned short in_port )
+ int create_multicast_socket(const char * mcast_address, const char * address, unsigned short in_port )
}
```
Calling `create_tcp_socket` will create an additional listen thread, which will operate in the same way as the default listen thread. The VariableServer will create a TCPClientListener and start the listen thread, just like it does for the default listen thread.
`create_udp_socket` will open a UDP socket. Since it does not require a listener, the VariableServer creates a VariableServerSessionThread and a UDPConnection directly, and starts the thread. The output for this session is sent to whatever host a message is received from.
`create_multicast_socket` will create a UDP socket and add it to a multicast group. It will also create and start a VariableServerSessionThread and MulticastGroup object. The output for this session is broadcast on the multicast address given.
## ClientConnection and TCPClientListener
The purpose of these classes are to abstract away all of the network code and the differences between TCP, UDP, and multicast connections for the purpose of the VariableServerSession.
The VariableServerListenThread uses a TCPClientListener to listen for connections on an open socket, and when one comes in, the TCPClientListener will create a TCPConnection to service the connection.
In the UDP and Multicast case, the connection is created directly in the VariableServer class and passed into the VariableServerSessionThread.
## Class Diagram
![Variable Server UML](images/vs_uml.png)

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 238 KiB

View File

@ -14,9 +14,9 @@ If there are no subscribers, then publishing a message has no effect.
## Message Subscriber
There can be any number of Message Subscribers, whose job is to receive (and usually output) published messages. Trick automatically creates three Message Subscribers:
- `Trick::MessageCout` - outputs messages to the standard output stream
- `Trick::MessageFile` - outputs messages to a file named `send_hs` in the RUN directory
- `Trick::MessageTCDevice` - outputs messages to a socket at port 7200, used by the Simulation Control Panel for its Status Messages display
- `Trick::MessageCout` - outputs messages with level < 100 to the standard output stream
- `Trick::MessageHSFile` - outputs messages with level < 100 to a file named `send_hs` in the RUN directory
- `Trick::MessageTCDevice` - outputs messages with level < 100 to a socket at port 7200, used by the Simulation Control Panel for its Status Messages display
When you publish a message, it will be output by the three subscribers above.
A subscriber can be enabled / disabled at any time during simulation execution to output / ignore messages as desired.
@ -33,16 +33,18 @@ trick_message.mtcout.init()
trick.message_subscribe(trick_message.mtcout)
```
## User accessible routines
## Publish a message
To publish a message:
```cpp
int ::message_publish(int level, const char * format_msg, ...) ;
int ::send_hs(FILE * fp, const char * format_msg, ...) ;
#include "trick/message_proto.h"
#include "trick/message_level.h"
int message_publish(int level, const char * format_msg, ...) ;
```
The level number can be any integer from 0 to 99. Trick has a few predefined levels (`Trick::MessagePublisher::MESSAGE_TYPE`) that it uses for publishing messages.
The level number can be any number greater than or equal to 0. Levels 0-99 are captured by Trick's default message subscribers. Trick has a few predefined levels (`Trick::MessagePublisher::MESSAGE_TYPE`) that it uses for publishing messages.
If the message subscriber's color is enabled (see below), then a particular colored message will be displayed for each of these levels:
- 0 - normal message, default color
- 1 - informational message, green
@ -50,6 +52,31 @@ If the message subscriber's color is enabled (see below), then a particular colo
- 3 - error message, red
- 10 - debug message, cyan
## Open a custom log file
To open a custom message file:
```cpp
#include "trick/Message_proto.hh"
int open_custom_message_file(std::string file_name, std::string subscriber_name, int level = -1);
```
This function opens a new file, adds it to the list of message subscribers, and returns the level that can be used to write to the file.
A user can specify a level >= 0. If `open_custom_message_file` is called without a level argument, the function will assign a unique level to the file that is >= 100. If a user wants the messages written to this file to also be captured by default Trick message subscribers, they should specify a level from 0-99.
Example:
```cpp
// Open the logfile
int my_level = open_custom_message_file("my_log_dir/logfile", "custom_log");
// Write to it by publishing a message with the given level
message_publish(my_level, "This message will be written to my custom logfile");
```
## User accessible routines
To subscribe / unsubscribe Trick's default subscribers (these call `::message_subscribe` / `::message_unsubscribe` mentioned above):
By default these are all subscribed. You can use subscribe/unsubscribe throughout a simulation to turn on/off messages at will.

View File

@ -12,7 +12,7 @@ A trick sim is a multi-threaded process, and all of the threads that are created
| MessageTCDeviceListenThread | `trick_message.mdevice.get_listen_thread()` |
| MessageThreadedCout | `trick_message.mtcout` |
| DRDWriterThread | `trick_data_record.drd.drd_writer_thread` |
| VariableServerThread | `trick_vs.vs.get_vst(pthread_t thread_id)` |
| VariableServerSessionThread | `trick_vs.vs.get_vst(pthread_t thread_id)` |
## ThreadBase Methods

View File

@ -39,7 +39,7 @@ int set_var_server_info_msg_on();
```
These commands are also for toggling information messages from the variable server (i.e., commands received from <i>ALL</i> clients).
The messages only go to a dedicated "varserver_log" file in the RUN directory.
The messages only go to a dedicated `varserver_log` file in the RUN directory.
The variable server log capability is off by default.
```c
@ -47,6 +47,16 @@ int set_var_server_log_off();
int set_var_server_log_on();
```
These commands are also for toggling individual variable server session logs.
Each log records the IP and port number of the client that connected and every message received.
These logs go into a subdirectory under the RUN direcory called `sesssion_logs`, and the files are named `VSSession<num>.log`
The variable server session log capability is off by default.
```c
int set_var_server_session_log_off();
int set_var_server_session_log_on();
```
### Getting and Setting the Variable Server Port Information
To set the variable server port to a fixed number in the input file use var_server_set_port()

View File

@ -0,0 +1,51 @@
/************************************************************************
PURPOSE: (Abstract base class for a connection to a client. Should
be inherited by variable server and web server connections. )
LIBRARY DEPENDENCIES:
() )
**************************************************************************/
#ifndef CLIENT_CONNECTION_HH
#define CLIENT_CONNECTION_HH
#include <string>
namespace Trick {
class ClientConnection {
public:
virtual ~ClientConnection() { }
static const unsigned int MAX_CMD_LEN = 200000 ;
enum ConnectionType { TCP, UDP, MCAST, WS } ;
// Pure virtual methods
virtual int start() = 0;
virtual int write (const std::string& message) = 0;
virtual int write (char * message, int size) = 0;
virtual int read (std::string& message, int max_len = MAX_CMD_LEN) = 0;
virtual int setBlockMode (bool blocking) = 0;
virtual int disconnect () = 0;
virtual bool isInitialized() = 0;
virtual std::string getClientTag () = 0;
virtual int setClientTag (std::string tag) = 0;
virtual int restart() = 0;
virtual std::string getClientHostname() = 0;
virtual int getClientPort() = 0;
protected:
ConnectionType _connection_type;
std::string _client_tag;
};
}
#endif

View File

@ -139,6 +139,7 @@ namespace Trick {
*/
void set_output_dir(std::string output_directory) ;
// TODO: Move elsewhere
// Helper method to create full path
static int create_path(const std::string& dirname);

View File

@ -0,0 +1,60 @@
/*
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() ;
/**
@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() const;
virtual void set_level(int level);
virtual void set_name(std::string name);
virtual void set_file_name(std::string file_name);
protected:
int _this_level;
static int level_counter;
} ;
}
#endif

View File

@ -0,0 +1,53 @@
/*
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() ;
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

View File

@ -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.
@ -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.
@ -61,6 +61,9 @@ namespace Trick {
*/
virtual int init() ;
virtual int restart() ;
protected:
/** The output file stream. \n */
std::fstream out_stream ; /**< trick_io(**) */

View File

@ -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

View File

@ -41,6 +41,7 @@ namespace Trick {
@brief The constructor.
*/
MessagePublisher() ;
virtual ~MessagePublisher();
/**
@brief Initialization job. Sets tics_per_sec and print format.
@ -66,7 +67,7 @@ namespace Trick {
@param message - the text of the message
@return always 0
*/
int publish(int level, std::string message) ;
virtual int publish(int level, std::string message) ;
/**
@brief gets the subscriber from the list

View File

@ -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

View File

@ -0,0 +1,24 @@
#ifndef MOCK_CLIENT_CONNECTION_HH
#define MOCK_CLIENT_CONNECTION_HH
#include "trick/ClientConnection.hh"
#include <gmock/gmock.h>
class MockClientConnection : public Trick::ClientConnection {
public:
MOCK_METHOD0(start, int());
MOCK_METHOD1(write, int(const std::string& message));
MOCK_METHOD2(write, int(char * message, int size));
MOCK_METHOD2(read, int(std::string& message, int max_len));
MOCK_METHOD0(disconnect, int());
MOCK_METHOD1(setBlockMode, int(bool blocking));
MOCK_METHOD0(isInitialized, bool());
MOCK_METHOD0(restart, int());
MOCK_METHOD0(getClientTag, std::string());
MOCK_METHOD1(setClientTag, int(std::string tag));
MOCK_METHOD0(getClientHostname, std::string());
MOCK_METHOD0(getClientPort, int());
};
#endif

View File

@ -0,0 +1,13 @@
#ifndef MOCK_EXECUTIVE_HH
#define MOCK_EXECUTIVE_HH
#include "trick/Executive.hh"
#include <gmock/gmock.h>
class MockExecutive : public Trick::Executive {
public:
MOCK_METHOD0(get_time_tics, long long());
MOCK_METHOD0(get_sim_time, double());
};
#endif

View File

@ -0,0 +1,13 @@
#ifndef MOCK_INPUT_PROCESSOR_HH
#define MOCK_INPUT_PROCESSOR_HH
#include "trick/InputProcessor.hh"
#include <gmock/gmock.h>
class MockInputProcessor : public Trick::InputProcessor {
public:
MOCK_METHOD1(parse, int(std::string in_string));
};
#endif

View File

@ -0,0 +1,13 @@
#ifndef MOCK_MESSAGE_CUSTOM_MANAGER_HH
#define MOCK_MESSAGE_CUSTOM_MANAGER_HH
#include "trick/MessageCustomManager.hh"
#include <gmock/gmock.h>
class MockMessageCustomManager : public Trick::MessageCustomManager {
public:
MOCK_METHOD3(update, void(int level, std::string header, std::string message));
MOCK_METHOD3(open_custom_message_file, int(std::string file_name, std::string subscriber_name, int level));
};
#endif

View File

@ -0,0 +1,12 @@
#ifndef MOCK_MESSAGE_PUBLISHER_HH
#define MOCK_MESSAGE_PUBLISHER_HH
#include "trick/MessagePublisher.hh"
#include <gmock/gmock.h>
class MockMessagePublisher : public Trick::MessagePublisher {
public:
MOCK_METHOD2(publish, int(int level, std::string message));
};
#endif

View File

@ -0,0 +1,18 @@
#ifndef MOCK_MULTICAST_GROUP_HH
#define MOCK_MULTICAST_GROUP_HH
#include "trick/MulticastGroup.hh"
#include <gmock/gmock.h>
class MockMulticastGroup : public Trick::MulticastGroup {
public:
MOCK_METHOD1(broadcast, int(std::string));
MOCK_METHOD2(addAddress, int(std::string, int));
MOCK_METHOD0(restart, int());
MOCK_METHOD0(isInitialized, bool());
MOCK_METHOD0(initialize, int());
MOCK_METHOD0(disconnect, int());
};
#endif

View File

@ -0,0 +1,21 @@
#ifndef MOCK_REALTIME_SYNC_HH
#define MOCK_REALTIME_SYNC_HH
#include "trick/GetTimeOfDayClock.hh"
#include "trick/RealtimeSync.hh"
#include <gmock/gmock.h>
// This sucks but refactoring this is out of the scope for now
Trick::GetTimeOfDayClock& my_static_clock() {
static Trick::GetTimeOfDayClock clock;
return clock;
}
class MockRealtimeSync : public Trick::RealtimeSync {
public:
MockRealtimeSync() : RealtimeSync(&(my_static_clock())) {}
MOCK_METHOD0(is_active, bool());
};
#endif

View File

@ -0,0 +1,24 @@
#ifndef MOCK_CLIENT_LISTENER_HH
#define MOCK_CLIENT_LISTENER_HH
#include "trick/TCPClientListener.hh"
#include <gmock/gmock.h>
class MockTCPClientListener : public Trick::TCPClientListener {
public:
MOCK_METHOD2(initialize, int(std::string, int));
MOCK_METHOD0(initialize, int());
MOCK_METHOD1(setBlockMode, int(bool));
MOCK_METHOD0(checkForNewConnections, bool());
MOCK_METHOD0(setUpNewConnection, Trick::TCPConnection*());
MOCK_METHOD0(disconnect, int());
MOCK_METHOD0(checkSocket, int());
MOCK_METHOD1(validateSourceAddress, bool(std::string));
MOCK_METHOD0(isInitialized, bool());
MOCK_METHOD0(restart, int());
MOCK_METHOD0(getHostname, std::string());
MOCK_METHOD0(getPort, int());
};
#endif

View File

@ -0,0 +1,21 @@
#ifndef MOCK_TCP_CONNECTION_HH
#define MOCK_TCP_CONNECTION_HH
#include "trick/TCPConnection.hh"
#include <gmock/gmock.h>
class MockTCPConnection : public Trick::TCPConnection {
public:
MOCK_METHOD0(start, int());
MOCK_METHOD1(write, int(const std::string& message));
MOCK_METHOD2(write, int(char * message, int size));
MOCK_METHOD2(read, int(std::string& message, int max_len));
MOCK_METHOD0(disconnect, int());
MOCK_METHOD1(setBlockMode, int(bool blocking));
MOCK_METHOD0(isInitialized, bool());
MOCK_METHOD0(restart, int());
MOCK_METHOD0(getClientTag, std::string());
MOCK_METHOD1(setClientTag, int(std::string tag));
};
#endif

View File

@ -0,0 +1,34 @@
#ifndef MOCK_VARIABLE_SERVER_SESSION_HH
#define MOCK_VARIABLE_SERVER_SESSION_HH
#include "trick/VariableServerSession.hh"
#include <gmock/gmock.h>
class MockVariableServerSession : public Trick::VariableServerSession {
public:
MOCK_METHOD0(handle_message, int());
MOCK_METHOD0(write_data, int());
MOCK_METHOD0(get_exit_cmd, bool());
MOCK_METHOD0(get_pause, bool());
MOCK_CONST_METHOD0(get_enabled, bool());
MOCK_CONST_METHOD0(get_write_mode, VS_WRITE_MODE());
MOCK_CONST_METHOD0(get_copy_mode, VS_COPY_MODE());
MOCK_METHOD1(set_log, int(bool on_off));
MOCK_METHOD1(set_session_log, int(bool on_off));
MOCK_METHOD0(copy_sim_data, int());
MOCK_CONST_METHOD0(get_update_rate, double());
MOCK_CONST_METHOD0(get_frame_multiple, int());
MOCK_CONST_METHOD0(get_frame_offset, int());
MOCK_CONST_METHOD0(get_freeze_frame_multiple, int());
MOCK_CONST_METHOD0(get_freeze_frame_offset, int());
MOCK_CONST_METHOD0(get_next_tics, long long ());
MOCK_CONST_METHOD0(get_freeze_next_tics, long long());
MOCK_METHOD0(set_exit_cmd, void());
MOCK_METHOD0(copy_and_write_async, int());
// Accessor for the concrete version
int copy_and_write_async_concrete() { return Trick::VariableServerSession::copy_and_write_async(); }
};
#endif

View File

@ -0,0 +1,55 @@
/*
PURPOSE: ( Encapsulate multicast functionality. )
*/
#ifndef MULTICAST_GROUP_HH
#define MULTICAST_GROUP_HH
#include <string>
#include <vector>
#include <arpa/inet.h>
#include <trick/UDPConnection.hh>
#include <trick/SystemInterface.hh>
namespace Trick {
class MulticastGroup : public UDPConnection {
public:
MulticastGroup();
MulticastGroup (SystemInterface * system_interface);
virtual ~MulticastGroup();
// Multicast specific functions
int initialize_with_receiving(std::string local_addr, std::string mcast_addr, int port);
virtual int initialize();
virtual int broadcast (std::string message);
virtual int addAddress (std::string addr, int port);
// ClientConnection interface
virtual int write (const std::string& message) override;
virtual int write (char * message, int size) override;
virtual int read (std::string& message, int max_len = MAX_CMD_LEN) override;
virtual int disconnect () override;
virtual bool isInitialized() override;
virtual int restart() override;
virtual std::string getClientHostname() override;
virtual int getClientPort() override;
private:
std::vector<struct sockaddr_in> _addresses; /**< trick_io(**) Addresses to multicast to. */
bool _initialized; /**< trick_io(**) Whether this object is ready */
struct sockaddr_in _self_info ; /**< trick_io(**) Save self information so we don't process our own messages */
SystemInterface * _system_interface;
};
}
#endif

View File

@ -256,6 +256,12 @@ namespace Trick {
*/
virtual int start_sleep_timer();
/**
@brief Return whether realtime is currently active
@return True if active, false otherwise
*/
virtual bool is_active();
} ;
} ;

View File

@ -33,12 +33,34 @@ namespace Trick {
**/
class SysThread : public Trick::ThreadBase {
public:
SysThread(std::string in_name, bool self_deleting = false);
SysThread(std::string in_name);
~SysThread();
static int ensureAllShutdown();
protected:
// Called from the main thread
void force_thread_to_pause();
// Called from the main thread
void unpause_thread();
// Called from the sys_thread at a point that would be appropriate to pause
void test_pause();
private:
/** Synchronization to safely pause and restart processing during a checkpoint reload */
pthread_mutex_t _restart_pause_mutex ; /**< trick_io(**) */
// For the main thread to tell the sys_thread to pause
bool _thread_should_pause; /**< trick_io(**) */
// For the main thread to tell the sys_thread to wake up
pthread_cond_t _thread_wakeup_cv; /**< trick_io(**) */
// For the main thread to wait for the sys_thread to pause
pthread_cond_t _thread_has_paused_cv; /**< trick_io(**) */
bool _thread_has_paused; /**< trick_io(**) */
// Had to use Construct On First Use here to avoid the static initialziation fiasco
static pthread_mutex_t& list_mutex();
static pthread_cond_t& list_empty_cv();
@ -47,7 +69,6 @@ namespace Trick {
static bool shutdown_finished;
bool self_deleting;
} ;
}

View File

@ -0,0 +1,57 @@
/*
PURPOSE: (A wrapper for system calls to facilitate testing.)
*/
#ifndef __SYSTEM_INTERFACE__
#define __SYSTEM_INTERFACE__
#include <iostream>
#include <functional>
#include <sys/types.h>
#include <sys/select.h>
#include <sys/socket.h>
#include <unistd.h>
#include <netdb.h>
#include <fcntl.h>
#include <arpa/inet.h>
class SystemInterface {
public:
virtual int socket (int domain, int type, int protocol) { return ::socket ( domain, type, protocol); }
virtual int setsockopt (int socket, int level, int option_name, const void * option_value, socklen_t option_len) { return ::setsockopt ( socket, level, option_name, option_value, option_len); }
virtual int bind (int socket, const struct sockaddr * address, socklen_t address_len) { return ::bind ( socket, address, address_len); }
virtual int getsockname (int socket, struct sockaddr * address, socklen_t * address_len) { return ::getsockname ( socket, address, address_len); }
virtual int listen (int socket, int backlog) { return ::listen ( socket, backlog); }
virtual int select (int nfds, fd_set * readfds, fd_set * writefds, fd_set * errorfds, struct timeval * timeout) { return ::select ( nfds, readfds, writefds, errorfds, timeout); }
virtual int close (int fildes) { return ::close ( fildes); }
virtual int getaddrinfo (const char * hostname, const char * servname, const struct addrinfo * hints, struct addrinfo ** res) { return ::getaddrinfo ( hostname, servname, hints, res); }
virtual int fcntl (int fildes, int cmd, int arg) { return ::fcntl ( fildes, cmd, arg); }
virtual int shutdown (int socket, int how) { return ::shutdown ( socket, how); }
virtual int accept (int socket, struct sockaddr * address, socklen_t * address_len) { return ::accept ( socket, address, address_len); }
virtual ssize_t send (int socket, const void * buffer, size_t length, int flags) { return ::send ( socket, buffer, length, flags); }
virtual ssize_t sendto (int socket, const void * buffer, size_t length, int flags, const struct sockaddr * dest_addr, socklen_t dest_len) { return ::sendto ( socket, buffer, length, flags, dest_addr, dest_len); }
virtual ssize_t recv (int socket, void * buffer, size_t length, int flags) { return ::recv ( socket, buffer, length, flags); }
virtual ssize_t recvfrom (int socket, void * buffer, size_t length, int flags, struct sockaddr * address, socklen_t * address_len) { return ::recvfrom ( socket, buffer, length, flags, address, address_len); }
virtual in_addr_t inet_addr (const char * cp) { return ::inet_addr ( cp); }
};
#endif

View File

@ -0,0 +1,64 @@
#ifndef CLIENT_LISTENER_HH
#define CLIENT_LISTENER_HH
/*
PURPOSE: ( Encapsulate a TCP server. )
*/
#include <string>
#include "trick/SystemInterface.hh"
#include "trick/TCPConnection.hh"
#define LISTENER_ERROR -1
namespace Trick {
class TCPConnection;
class TCPClientListener {
public:
TCPClientListener ();
TCPClientListener (SystemInterface * system_interface);
virtual ~TCPClientListener ();
virtual int initialize(std::string hostname, int port);
virtual int initialize();
virtual int setBlockMode(bool blocking);
virtual int setSocketPriority(unsigned short priority);
virtual bool checkForNewConnections();
virtual TCPConnection * setUpNewConnection ();
virtual int disconnect();
virtual int checkSocket();
virtual bool validateSourceAddress(std::string source_address);
virtual bool isInitialized();
virtual int restart();
virtual std::string getHostname ();
virtual int getPort();
protected:
int _listen_socket;
std::string _hostname;
int _port;
std::string _client_tag;
bool _initialized;
SystemInterface * _system_interface; /* ** */
};
}
#endif

View File

@ -0,0 +1,53 @@
#ifndef TCP_CONNECTION_HH
#define TCP_CONNECTION_HH
/*
PURPOSE: ( Encapsulate a TCP connection. )
*/
#include "trick/ClientConnection.hh"
#include "trick/SystemInterface.hh"
namespace Trick {
class TCPConnection : public ClientConnection {
public:
TCPConnection ();
TCPConnection (int listen_socket);
TCPConnection (SystemInterface * system_interface);
TCPConnection (int listen_socket, SystemInterface * system_interface);
virtual int start() override;
virtual int write (const std::string& message) override;
virtual int write (char * message, int size) override;
virtual int read (std::string& message, int max_len = MAX_CMD_LEN) override;
virtual int disconnect () override;
virtual bool isInitialized() override;
virtual int setBlockMode(bool blocking) override;
virtual int restart() override;
virtual std::string getClientTag () override;
virtual int setClientTag (std::string tag) override;
virtual std::string getClientHostname() override;
virtual int getClientPort() override;
private:
int _socket;
bool _connected;
// This is needed to be able to accept an incoming connection, after being set up by the listener
int _listen_socket;
SystemInterface * _system_interface; /* ** */
};
}
#endif

View File

@ -131,7 +131,7 @@ namespace Trick {
virtual int cancel_thread() ;
/**
* Cancels thread.
* Joins thread.
* @return always 0
*/
virtual int join_thread() ;
@ -153,6 +153,12 @@ namespace Trick {
*/
virtual void dump( std::ostream & oss = std::cout ) ;
virtual void test_shutdown();
virtual void test_shutdown(void (*exit_handler) (void *), void * exit_arg);
virtual void thread_shutdown();
virtual void thread_shutdown(void (*exit_handler) (void *), void * exit_arg);
protected:
/** optional name of thread */
@ -170,6 +176,14 @@ namespace Trick {
/** Set of cpus to use with thread */
unsigned int max_cpu ; /**< trick_io(**) */
/** Track whether the thread has been created */
bool created ; /**< trick_io(**) */
/** Manage thread shutdown */
bool should_shutdown; /**< trick_io(**) */
bool cancellable; /**< trick_io(**) */
pthread_mutex_t shutdown_mutex; /**< trick_io(**) */
#if __linux
#ifndef SWIG
/** Set of cpus to use with thread */

View File

@ -0,0 +1,60 @@
#ifndef UDP_CONNECTION_HH
#define UDP_CONNECTION_HH
/*
PURPOSE: ( Encapsulate a UDP socket. )
*/
#include "trick/ClientConnection.hh"
#include "trick/SystemInterface.hh"
namespace Trick {
class UDPConnection : public ClientConnection {
public:
UDPConnection ();
UDPConnection (SystemInterface * system_interface);
int start() override;
int write (const std::string& message) override;
int write (char * message, int size) override;
int read (std::string& message, int max_len = MAX_CMD_LEN) override;
int disconnect () override;
bool isInitialized() override;
int setBlockMode(bool block_mode) override;
int restart() override;
virtual std::string getClientTag () override;
virtual int setClientTag (std::string tag) override;
// Non-override functions
int initialize(const std::string& hostname, int port);
int getPort();
std::string getHostname();
virtual std::string getClientHostname() override;
virtual int getClientPort() override;
protected:
bool _initialized;
bool _started;
int _socket;
int _port;
std::string _hostname;
struct sockaddr_in _remote_serv_addr;
SystemInterface * _system_interface; /* ** */
};
}
#endif

View File

@ -0,0 +1,94 @@
/*************************************************************************
PURPOSE: (A variable server variable reference. Refactor of VariableReference
based on the VariableServerVariable class previously in the webserver.)
**************************************************************************/
#ifndef VARIABLE_REFERENCE_HH
#define VARIABLE_REFERENCE_HH
#include <time.h>
#include <vector>
#include <iostream>
#include <trick/reference.h>
#define MAX_ARRAY_LENGTH 4096
union cv_converter ;
namespace Trick {
class VariableReference {
public:
friend std::ostream& operator<< (std::ostream& s, const Trick::VariableReference& ref);
VariableReference(std::string var_name);
// Special constructor to deal with time
VariableReference(std::string var_name, double* time);
~VariableReference();
std::string getName() const;
TRICK_TYPE getType() const;
std::string getBaseUnits() const;
int setRequestedUnits(std::string new_units);
// These variables have 2 staging buffers that we can swap between to allow for different copy and write-out modes
// stageValue copies data from the simulation into one of the buffers (stage_buffer)
// prepareForWrite swaps the pointers for stage_buffer and write_buffer
// This way we can have data ready for writing, but also be copying out from the sim at the same time
// stageValue must be called first, and then prepare for write, and then writeValue* can be called.
int stageValue(bool validate_address = false);
int prepareForWrite();
bool isStaged() const;
bool isWriteReady() const;
// Write out the value to the given outstream.
// write_ready must be true
int getSizeAscii() const;
int getSizeBinary() const;
int writeValueAscii( std::ostream& out ) const;
int writeValueBinary( std::ostream& out , bool byteswap = false) const;
int writeNameBinary( std::ostream& out, bool byteswap = false) const;
int writeNameLengthBinary( std::ostream& out, bool byteswap = false) const;
int writeSizeBinary( std::ostream& out, bool byteswap = false) const;
int writeTypeBinary( std::ostream& out, bool byteswap = false) const;
bool validate();
void tagAsInvalid();
// Helper method for byteswapping
static void byteswap_var (char * out, char * in, const VariableReference& ref);
private:
VariableReference();
void byteswap_var(char * out, char * in) const;
// Error refs
static REF2* make_error_ref(std::string in_name);
static REF2* make_do_not_resolve_ref(std::string in_name);
static int _bad_ref_int;
static int _do_not_resolve_bad_ref_int;
REF2 * _var_info;
void * _address; // -- address of data copied to buffer
int _size; // -- size of data copied to buffer
bool _deref; // -- indicates whether variable is pointer that needs to be dereferenced
cv_converter * _conversion_factor ; // ** udunits conversion factor
TRICK_TYPE _trick_type ; // -- Trick type of this variable
bool _staged;
bool _write_ready;
void *_stage_buffer;
void *_write_buffer;
std::string _base_units;
std::string _requested_units;
std::string _name;
};
std::ostream& operator<< (std::ostream& s, const Trick::VariableReference& ref);
}
#endif

View File

@ -16,7 +16,7 @@
#include "trick/reference.h"
#include "trick/JobData.hh"
#include "trick/variable_server_sync_types.h"
#include "trick/VariableServerThread.hh"
#include "trick/VariableServerSessionThread.hh"
#include "trick/VariableServerListenThread.hh"
#include "trick/SysThread.hh"
@ -85,39 +85,55 @@ namespace Trick {
/**
@brief Copies client variable values at the top of the frame.
*/
int copy_data_top() ;
int copy_and_write_top() ;
/**
@brief The function to copy client variable values to their output buffers when in sync mode.
*/
int copy_data_scheduled() ;
int copy_and_write_scheduled() ;
/**
@brief The function to copy client variable values to their output buffers when in sync mode.
*/
int copy_data_freeze_scheduled() ;
int copy_and_write_freeze_scheduled() ;
/**
@brief Copies client variable values at the top of the frame.
*/
int copy_data_freeze() ;
int copy_and_write_freeze() ;
/**
@brief Adds a vst to the map.
*/
void add_vst(pthread_t thread_id, VariableServerThread * in_vst ) ;
void add_vst(pthread_t thread_id, VariableServerSessionThread * in_vst ) ;
/**
@brief Adds a vst to the map.
*/
void add_session(pthread_t thread_id, VariableServerSession * in_session ) ;
/**
@brief Get a vst mapped by thread id
@return the VariableServerThread mapped to the thread id if found, or NULL if not found.
@return the VariableServerSessionThread mapped to the thread id if found, or NULL if not found.
*/
Trick::VariableServerThread * get_vst(pthread_t thread_id) ;
Trick::VariableServerSessionThread * get_vst(pthread_t thread_id) ;
/**
@brief Get a session mapped by thread id
@return the VariableServerSession mapped to the thread id if found, or NULL if not found.
*/
Trick::VariableServerSession * get_session(pthread_t thread_id) ;
/**
@brief Delete a vst in the map
*/
void delete_vst(pthread_t thread_id) ;
/**
@brief Delete a session in the map
*/
void delete_session(pthread_t thread_id) ;
/**
@brief @userdesc Return host name from the listen device.
@par Python Usage:
@ -158,6 +174,11 @@ namespace Trick {
*/
bool get_log() ;
/**
@brief @userdesc Test if the variable server logging is on.
*/
bool get_session_log() ;
/**
@brief @userdesc Command to turn on variable server info messages (e.g., get a message
when a command is received from any client).
@ -197,6 +218,24 @@ namespace Trick {
*/
void set_var_server_log_off() ;
/**
@brief @userdesc Command to turn on variable server session logging for all clients.
Each new session will create a file under RUN_<>/session_logs/ containg the client's IP and port and all messages received.
@par Python Usage:
@code trick.set_var_server_log_on() @endcode
@return always 0
*/
void set_var_server_session_log_on() ;
/**
@brief @userdesc Command to turn off variable server session logging for all clients.
No session log will be creeated.
@par Python Usage:
@code trick.set_var_server_log_off() @endcode
@return always 0
*/
void set_var_server_session_log_off() ;
/**
@brief @userdesc Command to open additional variable server listen port.
@param source_address - the name or numeric IP of the machine to bind listen socket. NULL or empty
@ -250,9 +289,9 @@ namespace Trick {
void set_copy_data_job( Trick::JobData * ) ;
/**
@brief Called from the S_define to set the copy_data_freeze_job ptr.
@brief Called from the S_define to set the copy_and_write_freeze_job ptr.
*/
void set_copy_data_freeze_job( Trick::JobData * ) ;
void set_copy_and_write_freeze_job( Trick::JobData * ) ;
protected:
@ -266,6 +305,9 @@ namespace Trick {
to a varserver_log file in the RUN directory.\n */
bool log ; /**< trick_units(--) */
/** Toggle to turn on/off variable server individual session logs. */
bool session_log ; /**< trick_units(--) */
/** Default listen port thread object */
VariableServerListenThread listen_thread ;
@ -273,16 +315,11 @@ namespace Trick {
Trick::JobData * copy_data_job ; /**< trick_io(**) trick_units(--) */
/** Pointer to freeze_automatic job that copies requested variable values to their output buffers in sync mode.\n */
Trick::JobData * copy_data_freeze_job ; /**< trick_io(**) trick_units(--) */
Trick::JobData * copy_and_write_freeze_job ; /**< trick_io(**) trick_units(--) */
/** Storage for saved thread pause state. The pause state of each thread is saved
to this map by suspendPreCheckpointReload(). resumePostCheckpointReload() restores
the pause state from this map.
*/
std::map<pthread_t, bool> thread_pause_state_store; // ** ignore this
/** Map thread id to the VariableServerThread object.\n */
std::map < pthread_t , VariableServerThread * > var_server_threads ; /**< trick_io(**) */
/** Map thread id to the VariableServerSessionThread object.\n */
std::map < pthread_t , VariableServerSessionThread * > var_server_threads ; /**< trick_io(**) */
std::map < pthread_t , VariableServerSession * > var_server_sessions ; /**< trick_io(**) */
/** Mutex to ensure only one thread manipulates the map of var_server_threads\n */
pthread_mutex_t map_mutex ; /**< trick_io(**) */
@ -295,8 +332,6 @@ namespace Trick {
}
int vs_format_ascii(Trick::VariableReference * var, char *value, size_t value_size);
Trick::VariableServer * var_server_get_var_server() ;
// external calls to be made available from input processor
@ -331,8 +366,6 @@ int var_set_freeze_frame_multiple(unsigned int mult) ;
int var_set_freeze_frame_offset(unsigned int offset) ;
int var_byteswap(bool on_off) ;
int var_signal() ;
int var_multicast(bool on_off) ;
int var_send_list_size() ;

View File

@ -8,19 +8,24 @@
#include <string>
#include <iostream>
#include "trick/tc.h"
#include "trick/TCPClientListener.hh"
#include "trick/SysThread.hh"
#include "trick/MulticastGroup.hh"
namespace Trick {
/**
This class runs the variable server listen loop.
@author Alex Lin
@author Jackie Deans (2023)
*/
class VariableServerListenThread : public Trick::SysThread {
public:
VariableServerListenThread() ;
VariableServerListenThread(TCPClientListener * listener);
virtual ~VariableServerListenThread() ;
const char * get_hostname() ;
@ -28,10 +33,8 @@ namespace Trick {
unsigned short get_port() ;
void set_port(unsigned short in_port) ;
#ifndef __APPLE__
void set_socket_priority(unsigned short in_socket_priority) ;
void apply_socket_priority(TCDevice *listen_device, TCDevice *device);
#endif
void apply_socket_priority();
std::string get_user_tag() ;
const std::string& get_user_tag_ref() ;
@ -46,8 +49,6 @@ namespace Trick {
virtual int init_listen_device() ;
virtual int check_and_move_listen_device() ;
void create_tcp_socket(const char * address, unsigned short in_port ) ;
virtual void * thread_body() ;
int restart() ;
@ -56,37 +57,39 @@ namespace Trick {
void pause_listening() ;
void restart_listening() ;
void set_multicast_group (MulticastGroup * group);
virtual void dump( std::ostream & oss = std::cout ) ;
protected:
void initializeMulticast();
/** Requested variable server source address\n */
std::string source_address ; /**< trick_units(--) */
std::string _requested_source_address ; /**< trick_units(--) */
/** Requested variable server port number.\n */
unsigned short port ; /**< trick_units(--) */
unsigned short _requested_port ; /**< trick_units(--) */
/** User requested specific port number\n */
bool user_port_requested ; /**< trick_units(--) */
bool _user_requested_address ; /**< trick_units(--) */
/** User defined unique tag to easily identify this variable server port.\n */
std::string user_tag; /**< trick_units(--) */
std::string _user_tag; /**< trick_units(--) */
/** Turn on/off broadcasting of variable server port.\n */
bool broadcast ; /**< trick_units(--) */
bool _broadcast ; /**< trick_units(--) */
/** The listen device\n */
TCDevice listen_dev; /**< trick_io(**) */
/** The listen device */
TCPClientListener * _listener; /**< trick_io(**) trick_units(--) */
/** The mutex to stop accepting new connections during restart\n */
pthread_mutex_t restart_pause ; /**< trick_io(**) */
/* Multicast broadcaster */
MulticastGroup * _multicast; /**< trick_io(**) trick_units(--) */
#ifndef __APPLE__
/** Requested variable server socket priority.\n */
unsigned short socket_priority ; /**< trick_units(--) */
unsigned short _socket_priority ; /**< trick_units(--) */
/** User requested specific socket priority\n */
bool user_socket_priority_requested ; /**< trick_units(--) */
#endif
bool _user_socket_priority_requested ; /**< trick_units(--) */
} ;

View File

@ -1,44 +0,0 @@
/*
PURPOSE:
(VariableServerReference)
*/
#ifndef VARIABLESERVERREFERENCE_HH
#define VARIABLESERVERREFERENCE_HH
#include <iostream>
#include "trick/reference.h"
union cv_converter ;
#define MAX_ARRAY_LENGTH 4096
namespace Trick {
/**
This class provides reference information for variables requested from the variable server by the client.
@author Alex Lin
*/
class VariableReference {
public:
VariableReference(REF2 * in_ref) ;
~VariableReference() ;
friend std::ostream& operator<< (std::ostream& s, const Trick::VariableReference& vref);
/** Pointer to trick variable reference structure.\n */
REF2 * ref ;
cv_converter * conversion_factor ; // ** udunits conversion factor
void * buffer_in ;
void * buffer_out ;
void * address ; // -- address of data copied to buffer
int size ; // -- size of data copied to buffer
TRICK_TYPE string_type ; // -- indicate if this is a string or wstring
bool need_deref ; // -- inidicate this is a painter to be dereferenced
} ;
}
#endif

View File

@ -0,0 +1,541 @@
/*************************************************************************
PURPOSE: (Represent the state of a variable server connection.)
**************************************************************************/
#ifndef VSSESSION_HH
#define VSSESSION_HH
#include <vector>
#include <string>
#include "trick/VariableReference.hh"
#include "trick/ClientConnection.hh"
#include "trick/variable_server_sync_types.h"
#include "trick/tc.h"
#include "trick/variable_server_message_types.h"
namespace Trick {
class VariableServerSession {
public:
VariableServerSession();
virtual ~VariableServerSession();
friend std::ostream& operator<< (std::ostream& s, const Trick::VariableServerSession& session);
/**
* @brief Set the connection object
*
* @param connection - a pointer to a ClientConnection that is initialized and ready to go
*/
virtual void set_connection(ClientConnection * connection);
/**
@brief Read a message from the connection and act on it
*/
virtual int handle_message();
/**
@brief Get the pause state of this thread.
*/
virtual bool get_pause() ;
/**
@brief Set the pause state of this thread.
*/
virtual void set_pause(bool on_off) ;
/**
@brief Get the exit command of this session.
*/
virtual bool get_exit_cmd() ;
/**
@brief Command session to exit
*/
virtual void set_exit_cmd() ;
/**
@brief gets the send_stdio flag.
*/
virtual bool get_send_stdio() ;
/**
@brief sets the send_stdio flag.
*/
virtual int set_send_stdio(bool on_off) ;
// Called from different types of Trick jobs.
// Determines whether this session should be copying at that time, and calls internal copy methods if so
int copy_and_write_freeze(long long curr_frame);
int copy_and_write_freeze_scheduled(long long curr_tics);
int copy_and_write_scheduled(long long curr_tics);
int copy_and_write_top(long long curr_frame);
// Called from VariableServerSessionThread
virtual int copy_and_write_async();
/**
@brief Copy given variable values from Trick memory to each variable's output buffer.
cyclical indicated whether it is a normal cyclical copy or a send_once copy
*/
virtual int copy_sim_data(std::vector<VariableReference *>& given_vars, bool cyclical);
virtual int copy_sim_data();
/**
@brief Write data from the given var only to the appropriate format (var_ascii or var_binary) from variable output buffers to socket.
*/
virtual int write_data(std::vector<VariableReference *>& var, VS_MESSAGE_TYPE message_type) ;
virtual int write_data();
int write_stdio(int stream, std::string text);
void disconnect_references();
virtual long long get_next_tics() const;
virtual long long get_freeze_next_tics() const;
int freeze_init();
virtual double get_update_rate() const;
void pause_copy();
void unpause_copy();
virtual VS_WRITE_MODE get_write_mode () const;
virtual VS_COPY_MODE get_copy_mode () const;
/************************************************************************************************/
/* Variable Server Interface */
/************************************************************************************************/
/**
@brief @userdesc Command to add a variable to a list of registered variables for value retrieval.
The variable server will immediately begin returning the variable values to the client at a
frequency according to var_cycle.
@par Python Usage:
@code trick.var_add("<in_name>") @endcode
@param in_name - the variable name to retrieve
@return always 0
*/
virtual int var_add( std::string in_name ) ;
/**
@brief @userdesc Command to add a variable to a list of registered variables for value retrieval,
and also instructs the variable server to return the value in the specified measurement units.
The unit specification will be returned after the variable's value (var_ascii mode only).
Specifying units as "{xx}" will use the unit specification from the variable's model code declaration,
which is essentially a method of querying a variable's unit specification.
The variable server will immediately begin returning the variable values/units to the client at
a frequency according to var_cycle.
@par Python Usage:
@code trick.var_add("<in_name>", "<units_name>") @endcode
@param in_name - the variable name to retrieve
@param units_name - the desired units, specified within curly braces
@return always 0
*/
virtual int var_add( std::string in_name, std::string units_name ) ;
/**
@brief @userdesc Command to remove a variable (previously registered with var_add)
from the list of registered variables for value retrieval.
@par Python Usage:
@code trick.var_remove("<in_name>") @endcode
@param in_name - the variable name to remove
@return always 0
*/
virtual int var_remove( std::string in_name ) ;
/**
@brief @userdesc Command to instruct the variable server to return the value of a variable
in the specified units (var_ascii mode only).
The variable must have been previously registered with the var_add command.
The unit specification will be returned after the variable's value.
@par Python Usage:
@code trick.var_units("<var_name>", "<units_name>") @endcode
@param var_name - the variable name previously registered with var_add
@param units_name - the desired units, specified within curly braces
@return always 0
@note trick.var_add("my_object.my_variable"); trick.var_units("my_object.my_variable","{m}")
is the same as trick.var_add("my_object.my_variable","{m}")
*/
virtual int var_units(std::string var_name , std::string units_name) ;
/**
@brief @userdesc Command to instruct the variable server to send a Boolean value indicating
whether the specified variable exists
(is a Trick processed variable in the current simulation).
- var_binary mode: the message indicator is 1, and the returned value is a binary 0 or 1.
- var_ascii mode: the message indicator is "1" followed by a tab, then an ASCII "0" or "1" returned value.
.
@par Python Usage:
@code trick.var_exists("<in_name>") @endcode
@param in_name - the variable name to query
@return always 0
*/
virtual int var_exists( std::string in_name ) ;
/**
@brief @userdesc Command to immediately send the value of a comma separated list of variables
@par Python Usage:
@code trick.var_send_once("<in_name_list>", <number of variables in list>) @endcode
@param in_name_list - the variables name to retrieve, comma separated
@param num_vars - number of vars in in_name_list
@return always 0
*/
virtual int var_send_once(std::string in_name_list, int num_vars);
/**
@brief @userdesc Command to instruct the variable server to immediately send back the values of
variables that are registered with the var_add command
(typically used when var_pause is in effect). Each var_send command sends back all current values
once instead of cyclically.
@par Python Usage:
@code trick.var_send() @endcode
@return always 0
*/
virtual int var_send() ;
/**
@brief @userdesc Command to remove all variables from the list of variables currently
registered with the var_add command,
so the variable server will no longer send cyclic values until new var_add commands are issued.
@par Python Usage:
@code trick.var_clear() @endcode
@return always 0
*/
virtual int var_clear() ;
/**
@brief @userdesc Turns on validating addresses before they are referenced
@par Python Usage:
@code trick.var_validate_address() @endcode
@return always 0
*/
virtual int var_validate_address(bool on_off) ;
/**
@brief @userdesc Command to instruct the variable server to output debug information.
@par Python Usage:
@code trick.var_debug(<level>) @endcode
@return always 0
@param level - 1,2,or 3, higher number increases amount of info output
*/
virtual int var_debug(int level) ;
/**
@brief @userdesc Command to instruct the variable server to return values in ASCII format (this is the default).
@par Python Usage:
@code trick.var_ascii() @endcode
@return always 0
*/
virtual int var_ascii() ;
/**
@brief @userdesc Command to instruct the variable server to return values in binary format.
@par Python Usage:
@code trick.var_binary() @endcode
@return always 0
*/
virtual int var_binary() ;
/**
@brief @userdesc Command to instruct the variable server to return values in binary format,
but saves space in the returned messages
by omitting the variable names.
@par Python Usage:
@code trick.var_binary_nonames() @endcode
@return always 0
*/
virtual int var_binary_nonames() ;
/**
@brief @userdesc Command to tell the server when to copy data
- VS_COPY_ASYNC = copies data asynchronously. (default)
- VS_COPY_SCHEDULED = copies data as an automatic_last job in main thread
- VS_COPY_TOP_OF_FRAME = copies data at top of frame
@par Python Usage:
@code trick.var_set_copy_mode(<mode>) @endcode
@param mode - One of the above enumerations
@return 0 if successful, -1 if error
*/
virtual int var_set_copy_mode(int mode) ;
/**
@brief @userdesc Command to tell the server when to copy data
- VS_WRITE_ASYNC = writes data asynchronously. (default)
- VS_WRITE_WHEN_COPIED = writes data as soon as it's copied from sim
@par Python Usage:
@code trick.var_set_write_mode(<mode>) @endcode
@param mode - One of the above enumerations
@return 0 if successful, -1 if error
*/
virtual int var_set_write_mode(int mode) ;
/**
@brief @userdesc Command to put the current variable server/client connection in sync mode,
so that values to be sent to the client
are guaranteed to be homogenous, that is from the same execution frame (the default is asynchronous).
- async/async mode: the variable server thread itself copies the client data,
independent of the execution frame so may not be homogenous.
- sync/async mode: a variable server automatic_last job retrieves client requested data.
Data is sent asynchronously on separate thread.
- sync/sync mode: a variable server automatic_last job retrieves client requested data.
Data is sent in same automatic_last job.
.
@par Python Usage:
@code trick.var_sync(<on_off>) @endcode
@param on_off - 0 = fully asynchronous. 1 = sync data gather, async socket write.
2 = sync data gather, sync socket write
@return always 0
*/
virtual int var_sync(int on_off) ;
/**
@brief @userdesc Set the frame multiple
@par Python Usage:
@code trick.var_set_frame_multiple(<mult>) @endcode
@param mult - The requested multiple
@return 0
*/
virtual int var_set_frame_multiple(unsigned int mult) ;
/**
@brief @userdesc Set the frame offset
@par Python Usage:
@code trick.var_set_frame_offset(<offset>) @endcode
@param offset - The requested offset
@return 0
*/
virtual int var_set_frame_offset(unsigned int offset) ;
/**
@brief @userdesc Set the frame multiple
@par Python Usage:
@code trick.var_set_freeze_frame_multiple(<mult>) @endcode
@param mult - The requested multiple
@return 0
*/
virtual int var_set_freeze_frame_multiple(unsigned int mult) ;
/**
@brief @userdesc Set the frame offset
@par Python Usage:
@code trick.var_set_freeze_frame_offset(<offset>) @endcode
@param offset - The requested offset
@return 0
*/
virtual int var_set_freeze_frame_offset(unsigned int offset) ;
/**
@brief @userdesc Command to instruct the variable server to byteswap the return values
(only has an effect in var_binary mode).
The default is no byteswap - it is assumed server and client are same endianness.
If not, the user must issue the var_byteswap command.
@par Python Usage:
@code trick.var_byteswap(<on_off>) @endcode
@param on_off - true (or 1) to byteswap the return data, false (or 0) to return data as is
@return always 0
*/
virtual int var_byteswap(bool on_off) ;
/**
@brief @userdesc Command to toggle variable server logged messages to a playback file.
All messages received from all clients will be saved to file named "playback" in the RUN directory.
@par Python Usage:
@code trick.set_log(<on_off>) @endcode
@return always 0
*/
virtual int set_log(bool on_off) ;
/**
@brief @userdesc Command to toggle variable server session log.
Each session will create a file containing the IP and port of client and all messages.
The file will be created in a session_log/ subdirectory under the RUN directory.
@par Python Usage:
@code trick.set_session_log(<on_off>) @endcode
@return always 0
*/
virtual int set_session_log (bool on_off) ;
/**
@brief @userdesc Command to set info messages.
@return always 0
*/
virtual int set_info_message(bool on) ;
/**
@brief Command to send the number of items in the var_add list.
The variable server sends a message indicator of "3", followed by the total number of variables being sent.
*/
virtual int send_list_size();
/**
@brief Special command to instruct the variable server to send the contents of the S_sie.resource file; used by TV.
The variable server sends a message indicator of "2", followed by a tab, followed by the file contents
which are then sent as sequential ASCII messages with a maximum size of 4096 bytes each.
*/
virtual int send_sie_resource();
/**
@brief Special command to only send the class sie class information
*/
virtual int send_sie_class();
/**
@brief Special command to only send the enumeration sie class information
*/
virtual int send_sie_enum();
/**
@brief Special command to only send the top level objects sie class information
*/
virtual int send_sie_top_level_objects();
/**
@brief Special command to send an arbitrary file through the variable server.
*/
virtual int send_file(std::string file_name);
/**
@brief @userdesc Command to set the frequencty at which the variable server will send values
of variables that have been registered using
the var_add command. If var_cycle is not specified, the default cycle is 0.1 seconds.
@par Python Usage:
@code trick.var_cycle(<in_cycle>) @endcode
@param in_cycle - the desired frequency in seconds
@return always 0
*/
virtual int var_cycle(double in_cycle) ;
/**
@brief @userdesc Command exit this variable server session.
@par Python Usage:
@code trick.var_exit() @endcode
@return always 0
*/
virtual int var_exit();
private:
static int instance_counter;
static std::string log_subdir;
pthread_mutex_t _copy_mutex; /**< trick_io(**) */
ClientConnection * _connection; /**< trick_io(**) */
// Helper method to send a file to connection
virtual int transmit_file(std::string sie_file);
// Helper methods to write out formatted data
virtual int write_binary_data(const std::vector<VariableReference *>& given_vars, VS_MESSAGE_TYPE message_type);
virtual int write_ascii_data(const std::vector<VariableReference *>& given_vars, VS_MESSAGE_TYPE message_type );
virtual VariableReference * find_session_variable(std::string name) const;
std::vector<VariableReference *> _session_variables; /**< trick_io(**) */
// Getters and setters for internal variables
virtual long long get_cycle_tics() const;
virtual void set_freeze_next_tics(long long tics);
virtual void set_next_tics(long long tics);
virtual int get_frame_multiple () const;
virtual int get_frame_offset () const;
virtual int get_freeze_frame_multiple () const;
virtual int get_freeze_frame_offset () const;
virtual bool get_enabled () const;
// Check settings and log to appropriate places
void log_received_message(const std::string& msg);
void log_connection_opened ();
bool is_session_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(**) */
/** The update rate in integer tics.\n */
long long _cycle_tics ; /**< trick_io(**) */
/** The next call time in integer tics of the job to copy client data (sync mode).\n */
long long _next_tics ; /**< trick_io(**) */
/** The next call time in integer tics of the job to copy client data (sync mode).\n */
long long _freeze_next_tics ; /**< trick_io(**) */
/** The simulation time converted to seconds\n */
double _time ; /**< trick_units(s) */
/** Toggle to set variable server copy as top_of_frame, scheduled, async \n */
VS_COPY_MODE _copy_mode ; /**< trick_io(**) */
/** Toggle to set variable server writes as when copied or async.\n */
VS_WRITE_MODE _write_mode ; /**< trick_io(**) */
/** multiples of frame_count to copy data. Only used at top_of_frame\n */
int _frame_multiple ; /**< trick_io(**) */
/** multiples of frame_count to copy data. Only used at top_of_frame\n */
int _frame_offset ; /**< trick_io(**) */
/** multiples of frame_count to copy data. Only used at top_of_frame\n */
int _freeze_frame_multiple ; /**< trick_io(**) */
/** multiples of frame_count to copy data. Only used at top_of_frame\n */
int _freeze_frame_offset ; /**< trick_io(**) */
/** Toggle to tell variable server to byteswap returned values.\n */
bool _byteswap ; /**< trick_io(**) */
/** Toggle to tell variable server return data in binary format.\n */
bool _binary_data ; /**< trick_io(**) */
/** Toggle to tell variable server return data in binary format without the variable names.\n */
bool _binary_data_nonames ; /**< trick_io(**) */
/** Value (1,2,or 3) that causes the variable server to output increasing amounts of debug information.\n */
int _debug ; /**< trick_io(**) */
/** Toggle to enable/disable this variable server thread.\n */
bool _enabled ; /**< trick_io(**) */
/** Toggle to turn on/off variable server logged messages to a playback file.\n */
bool _log ; /**< trick_io(**) */
/** Toggle to turn on/off individual variable server session logs.\n */
bool _session_log; /**< trick_io(**) */
/** Toggle to turn on/off debug info messages.\n */
bool _info_msg ;
/** Message stream number for the session log file */
int _session_log_msg_stream;
/** Toggle to indicate var_pause commanded.\n */
bool _pause_cmd ; /**< trick_io(**) */
/** Save pause state while reloading a checkpoint.\n */
bool _saved_pause_cmd ; /**< trick_io(**) */
bool _send_stdio;
bool _validate_address;
/** Toggle to indicate var_exit commanded.\n */
bool _exit_cmd ; /**< trick_io(**) */
int _instance_num;
};
}
#endif

View File

@ -0,0 +1,106 @@
/*
PURPOSE:
(VariableServerSessionThread)
*/
#ifndef VariableServerSessionThread_HH
#define VariableServerSessionThread_HH
#include <string>
#include <iostream>
#include <pthread.h>
#include "trick/SysThread.hh"
#include "trick/VariableServerSession.hh"
#include "trick/variable_server_sync_types.h"
#include "trick/variable_server_message_types.h"
#include "trick/ClientConnection.hh"
#include "trick/TCPClientListener.hh"
namespace Trick {
class VariableServer ;
/** Flag to indicate the connection has been made */
enum ConnectionStatus { CONNECTION_PENDING, CONNECTION_SUCCESS, CONNECTION_FAIL };
/**
The purpose of this class is to run a VariableServerSession.
- Manages creation and cleanup of the network connection
- Manages thread startup and shutdown
- Invokes parts of the VariableServerSession that run asynchronously (reading from client, copying and writing to client if in applicable mode)
@author Alex Lin
@author Jackie Deans (2023)
*/
class VariableServerSessionThread : public Trick::SysThread {
public:
friend std::ostream& operator<< (std::ostream& s, Trick::VariableServerSessionThread& vst);
/**
@brief Constructor.
*/
VariableServerSessionThread() ;
VariableServerSessionThread(VariableServerSession * session) ;
virtual ~VariableServerSessionThread() ;
/**
@brief static routine called from S_define to set the VariableServer pointer for all threads.
@param in_vs - the master variable server object
*/
static void set_vs_ptr(Trick::VariableServer * in_vs) ;
void set_client_tag(std::string tag);
/**
@brief Set the connection pointer for this thread
*/
void set_connection(ClientConnection * in_connection);
/**
@brief Block until thread has accepted connection
*/
ConnectionStatus wait_for_accept() ;
/**
@brief The main loop of the variable server thread that reads and processes client commands.
@return always 0
*/
virtual void * thread_body() ;
VariableServer * get_vs() ;
void preload_checkpoint() ;
void restart() ;
void cleanup();
protected:
/** The Master variable server object. */
static VariableServer * _vs ;
/** Manages the variable list */
VariableServerSession * _session; /**< trick_io(**) */
/** Connection to the client */
ClientConnection * _connection; /**< trick_io(**) */
/** Value (1,2,or 3) that causes the variable server to output increasing amounts of debug information.\n */
int _debug ; /**< trick_io(**) */
ConnectionStatus _connection_status ; /**< trick_io(**) */
pthread_mutex_t _connection_status_mutex; /**< trick_io(**) */
pthread_cond_t _connection_status_cv; /**< trick_io(**) */
bool _saved_pause_cmd;
} ;
std::ostream& operator<< (std::ostream& s, VariableServerSessionThread& vst);
}
#endif

View File

@ -1,593 +0,0 @@
/*
PURPOSE:
(VariableServerThread)
*/
#ifndef VARIABLESERVERTHREAD_HH
#define VARIABLESERVERTHREAD_HH
#include <vector>
#include <string>
#include <iostream>
#include <pthread.h>
#include "trick/tc.h"
#include "trick/SysThread.hh"
#include "trick/VariableServerReference.hh"
#include "trick/variable_server_sync_types.h"
#include "trick/variable_server_message_types.h"
namespace Trick {
class VariableServer ;
/**
This class provides variable server command processing on a separate thread for each client.
@author Alex Lin
*/
class VariableServerThread : public Trick::SysThread {
public:
enum ConnectionType { TCP, UDP, MCAST } ;
friend std::ostream& operator<< (std::ostream& s, Trick::VariableServerThread& vst);
/**
@brief Constructor.
@param listen_dev - the TCDevice set up in listen()
*/
VariableServerThread(TCDevice * in_listen_dev ) ;
virtual ~VariableServerThread() ;
/**
@brief static routine called from S_define to set the VariableServer pointer for all threads.
@param in_vs - the master variable server object
*/
static void set_vs_ptr(Trick::VariableServer * in_vs) ;
/**
@brief Wait for the connection_accepted flag to be set.
*/
void wait_for_accept() ;
/**
@brief The main loop of the variable server thread that reads and processes client commands.
@return always 0
*/
virtual void * thread_body() ;
/**
@brief @userdesc Command to add a variable to a list of registered variables for value retrieval.
The variable server will immediately begin returning the variable values to the client at a
frequency according to var_cycle.
@par Python Usage:
@code trick.var_add("<in_name>") @endcode
@param in_name - the variable name to retrieve
@return always 0
*/
int var_add( std::string in_name ) ;
/**
@brief @userdesc Command to add a variable to a list of registered variables for value retrieval,
and also instructs the variable server to return the value in the specified measurement units.
The unit specification will be returned after the variable's value (var_ascii mode only).
Specifying units as "{xx}" will use the unit specification from the variable's model code declaration,
which is essentially a method of querying a variable's unit specification.
The variable server will immediately begin returning the variable values/units to the client at
a frequency according to var_cycle.
@par Python Usage:
@code trick.var_add("<in_name>", "<units_name>") @endcode
@param in_name - the variable name to retrieve
@param units_name - the desired units, specified within curly braces
@return always 0
*/
int var_add( std::string in_name, std::string units_name ) ;
/**
@brief @userdesc Command to remove a variable (previously registered with var_add)
from the list of registered variables for value retrieval.
@par Python Usage:
@code trick.var_remove("<in_name>") @endcode
@param in_name - the variable name to remove
@return always 0
*/
int var_remove( std::string in_name ) ;
/**
@brief @userdesc Command to instruct the variable server to return the value of a variable
in the specified units (var_ascii mode only).
The variable must have been previously registered with the var_add command.
The unit specification will be returned after the variable's value.
@par Python Usage:
@code trick.var_units("<var_name>", "<units_name>") @endcode
@param var_name - the variable name previously registered with var_add
@param units_name - the desired units, specified within curly braces
@return always 0
@note trick.var_add("my_object.my_variable"); trick.var_units("my_object.my_variable","{m}")
is the same as trick.var_add("my_object.my_variable","{m}")
*/
int var_units(std::string var_name , std::string units_name) ;
/**
@brief @userdesc Command to instruct the variable server to send a Boolean value indicating
whether the specified variable exists
(is a Trick processed variable in the current simulation).
- var_binary mode: the message indicator is 1, and the returned value is a binary 0 or 1.
- var_ascii mode: the message indicator is "1" followed by a tab, then an ASCII "0" or "1" returned value.
.
@par Python Usage:
@code trick.var_exists("<in_name>") @endcode
@param in_name - the variable name to query
@return always 0
*/
int var_exists( std::string in_name ) ;
/**
@brief @userdesc Command to immediately send the value of a comma separated list of variables
@par Python Usage:
@code trick.var_send_once("<in_name_list>", <number of variables in list>) @endcode
@param in_name_list - the variables name to retrieve, comma separated
@param num_vars - number of vars in in_name_list
@return always 0
*/
int var_send_once(std::string in_name_list, int num_vars);
/**
@brief @userdesc Command to instruct the variable server to immediately send back the values of
variables that are registered with the var_add command
(typically used when var_pause is in effect). Each var_send command sends back all current values
once instead of cyclically.
@par Python Usage:
@code trick.var_send() @endcode
@return always 0
*/
int var_send() ;
/**
@brief @userdesc Command to remove all variables from the list of variables currently
registered with the var_add command,
so the variable server will no longer send cyclic values until new var_add commands are issued.
@par Python Usage:
@code trick.var_clear() @endcode
@return always 0
*/
int var_clear() ;
/**
@brief @userdesc Command to set the frequencty at which the variable server will send values
of variables that have been registered using
the var_add command. If var_cycle is not specified, the default cycle is 0.1 seconds.
@par Python Usage:
@code trick.var_cycle(<in_cycle>) @endcode
@param in_cycle - the desired frequency in seconds
@return always 0
*/
int var_cycle(double in_cycle) ;
/**
@brief Get the pause state of this thread.
*/
bool get_pause() ;
/**
@brief Set the pause state of this thread.
*/
void set_pause(bool on_off) ;
/**
@brief @userdesc Command to terminate the current variable server/client connection.
@par Python Usage:
@code trick.var_exit() @endcode
@return always 0
*/
int var_exit() ;
/**
@brief @userdesc Turns on validating addresses before they are referenced
@par Python Usage:
@code trick.var_validate_address() @endcode
@return always 0
*/
int var_validate_address(bool on_off) ;
/**
@brief @userdesc Command to instruct the variable server to output debug information.
@par Python Usage:
@code trick.var_debug(<level>) @endcode
@return always 0
@param level - 1,2,or 3, higher number increases amount of info output
*/
int var_debug(int level) ;
/**
@brief @userdesc Command to instruct the variable server to return values in ASCII format (this is the default).
@par Python Usage:
@code trick.var_ascii() @endcode
@return always 0
*/
int var_ascii() ;
/**
@brief @userdesc Command to instruct the variable server to return values in binary format.
@par Python Usage:
@code trick.var_binary() @endcode
@return always 0
*/
int var_binary() ;
/**
@brief @userdesc Command to instruct the variable server to return values in binary format,
but saves space in the returned messages
by omitting the variable names.
@par Python Usage:
@code trick.var_binary_nonames() @endcode
@return always 0
*/
int var_binary_nonames() ;
/**
@brief @userdesc Command to tell the server when to copy data
- VS_COPY_ASYNC = copies data asynchronously. (default)
- VS_COPY_SCHEDULED = copies data as an automatic_last job in main thread
- VS_COPY_TOP_OF_FRAME = copies data at top of frame
@par Python Usage:
@code trick.var_set_copy_mode(<mode>) @endcode
@param mode - One of the above enumerations
@return 0 if successful, -1 if error
*/
int var_set_copy_mode(int on_off) ;
/**
@brief @userdesc Command to tell the server when to copy data
- VS_WRITE_ASYNC = writes data asynchronously. (default)
- VS_WRITE_WHEN_COPIED = writes data as soon as it's copied from sim
@par Python Usage:
@code trick.var_set_write_mode(<mode>) @endcode
@param mode - One of the above enumerations
@return 0 if successful, -1 if error
*/
int var_set_write_mode(int on_off) ;
/**
@brief @userdesc Command to put the current variable server/client connection in sync mode,
so that values to be sent to the client
are guaranteed to be homogenous, that is from the same execution frame (the default is asynchronous).
- async/async mode: the variable server thread itself copies the client data,
independent of the execution frame so may not be homogenous.
- sync/async mode: a variable server automatic_last job retrieves client requested data.
Data is sent asynchronously on separate thread.
- sync/sync mode: a variable server automatic_last job retrieves client requested data.
Data is sent in same automatic_last job.
.
@par Python Usage:
@code trick.var_sync(<on_off>) @endcode
@param on_off - 0 = fully asynchronous. 1 = sync data gather, async socket write.
2 = sync data gather, sync socket write
@return always 0
*/
int var_sync(int on_off) ;
/**
@brief @userdesc Set the frame multiple
@par Python Usage:
@code trick.var_set_frame_multiple(<mult>) @endcode
@param mult - The requested multiple
@return 0
*/
int var_set_frame_multiple(unsigned int mult) ;
/**
@brief @userdesc Set the frame offset
@par Python Usage:
@code trick.var_set_frame_offset(<offset>) @endcode
@param offset - The requested offset
@return 0
*/
int var_set_frame_offset(unsigned int offset) ;
/**
@brief @userdesc Set the frame multiple
@par Python Usage:
@code trick.var_set_freeze_frame_multiple(<mult>) @endcode
@param mult - The requested multiple
@return 0
*/
int var_set_freeze_frame_multiple(unsigned int mult) ;
/**
@brief @userdesc Set the frame offset
@par Python Usage:
@code trick.var_set_freeze_frame_offset(<offset>) @endcode
@param offset - The requested offset
@return 0
*/
int var_set_freeze_frame_offset(unsigned int offset) ;
/**
@brief @userdesc Command to instruct the variable server to byteswap the return values
(only has an effect in var_binary mode).
The default is no byteswap - it is assumed server and client are same endianness.
If not, the user must issue the var_byteswap command.
@par Python Usage:
@code trick.var_byteswap(<on_off>) @endcode
@param on_off - true (or 1) to byteswap the return data, false (or 0) to return data as is
@return always 0
*/
int var_byteswap(bool on_off) ;
/**
@brief CURRENTLY NOT IMPLEMENTED
*/
int var_signal() ;
/**
@brief @userdesc Command to turn on variable server logged messages to a playback file.
All messages received from all clients will be saved to file named "playback" in the RUN directory.
@par Python Usage:
@code trick.set_log_on() @endcode
@return always 0
*/
int set_log_on() ;
/**
@brief @userdesc Command to turn off variable server logged messages to a playback file.
@par Python Usage:
@code trick.set_log_off() @endcode
@return always 0
*/
int set_log_off() ;
/**
@brief CURRENTLY NOT IMPLEMENTED\n
Command to instruct the variable server to send values via multicast socket.
*/
int var_multicast(bool on_off) ;
/**
@brief Command to send the number of items in the var_add list.
The variable server sends a message indicator of "3", followed by the total number of variables being sent.
*/
int send_list_size();
/**
@brief Special command to instruct the variable server to send the contents of the S_sie.resource file; used by TV.
The variable server sends a message indicator of "2", followed by a tab, followed by the file contents
which are then sent as sequential ASCII messages with a maximum size of 4096 bytes each.
*/
int send_sie_resource();
/**
@brief Special command to only send the class sie class information
*/
int send_sie_class();
/**
@brief Special command to only send the enumeration sie class information
*/
int send_sie_enum();
/**
@brief Special command to only send the top level objects sie class information
*/
int send_sie_top_level_objects();
/**
@brief Special command to send an arbitrary file through the variable server.
*/
int send_file(std::string file_name);
/**
@brief Copy client variable values from Trick memory to each variable's output buffer.
*/
int copy_sim_data();
/**
@brief Copy given variable values from Trick memory to each variable's output buffer.
cyclical indicated whether it is a normal cyclical copy or a send_once copy
*/
int copy_sim_data(std::vector<VariableReference *> given_vars, bool cyclical);
/**
@brief Write data in the appropriate format (var_ascii or var_binary) from variable output buffers to socket.
*/
int write_data();
/**
@brief Write data from the given var only to the appropriate format (var_ascii or var_binary) from variable output buffers to socket.
*/
int write_data(std::vector<VariableReference *> var) ;
/**
@brief gets the send_stdio flag.
*/
bool get_send_stdio() ;
/**
@brief sets the send_stdio flag.
*/
int set_send_stdio(bool on_off) ;
VariableServer * get_vs() ;
TCDevice & get_connection() ;
/**
@brief Internal function used by input processor to send stdout and stderr to the client.
@return always 0
*/
int write_stdio(int stream , std::string text ) ;
int freeze_init() ;
int copy_data_freeze() ;
int copy_data_freeze_scheduled(long long curr_tics) ;
int copy_data_scheduled(long long curr_tics) ;
int copy_data_top() ;
void preload_checkpoint() ;
void restart() ;
long long get_next_tics() ;
long long get_freeze_next_tics() ;
/**
@brief creates a udp socket with the specified address and port. UDP ports do not go through
the listen and accept states
*/
int create_udp_socket(const char * address, unsigned short in_port) ;
/**
@brief creates a multicast socket with the specified address and port. mcast ports do not go through
the listen and accept states
*/
int create_mcast_socket(const char * mcast_address, const char * address, unsigned short in_port) ;
protected:
/**
@brief Called by send_sie commands to transmit files through the socket.
*/
int transmit_file(std::string file_name);
/**
@brief Called by write_data to write given variables to socket in var_binary format.
*/
int write_binary_data( int Start, char *buf1, const std::vector<VariableReference *>& given_vars, VS_MESSAGE_TYPE message_type);
/**
@brief Called by write_data to write given variables to socket in var_ascii format.
*/
int write_ascii_data(char * dest_buf, size_t dest_buf_size, const std::vector<VariableReference *>& given_vars, VS_MESSAGE_TYPE message_type );
/**
@brief Construct a variable reference from the string in_name and handle error checking
*/
VariableReference* create_var_reference(std::string in_name);
/**
@brief Make a time reference.
*/
REF2* make_time_ref();
/**
@brief Make a "bad-reference" reference.
*/
REF2* make_error_ref(std::string in_name);
/** The Master variable server object. */
static VariableServer * vs ;
/** The listen device from the variable server\n */
TCDevice * listen_dev; /**< trick_io(**) */
/** The trickcomm device used for the connection to the client.\n */
TCDevice connection ; /**< trick_io(**) */
/** The type of connection we have.\n */
ConnectionType conn_type ; /**< trick_io(**) */
/** Value (1,2,or 3) that causes the variable server to output increasing amounts of debug information.\n */
int debug ; /**< trick_io(**) */
/** Toggle to enable/disable this variable server thread.\n */
bool enabled ; /**< trick_io(**) */
/** Toggle to turn on/off variable server logged messages to a playback file.\n */
bool log ; /**< trick_io(**) */
/** Toggle to indicate var_pause commanded.\n */
bool pause_cmd ; /**< trick_io(**) */
/** Save pause state while reloading a checkpoint.\n */
bool saved_pause_cmd ; /**< trick_io(**) */
/** Toggle to indicate var_exit commanded.\n */
bool exit_cmd ; /**< trick_io(**) */
/** Set to true to validate all addresses before copying.\n */
bool validate_address ; /**< trick_io(**) */
/** The mutex to protect variable output buffers when copying variable values to them from Trick memory.\n */
pthread_mutex_t copy_mutex ; /**< trick_io(**) */
/** The mutex pauses all processing during checkpoint restart */
pthread_mutex_t restart_pause ; /**< trick_io(**) */
/** Dummy integer for bad references.\n */
static int bad_ref_int ; /**< trick_io(**) */
/** Dummy integer for bad references. If a variable points here, do not try to re-resolve address\n */
static int do_not_resolve_bad_ref_int ; /**< trick_io(**) */
/** The simulation time converted to seconds\n */
double time ; /**< trick_units(s) */
/** List of client requested variables.\n */
std::vector <VariableReference *> vars; /**< trick_io(**) */
/** Toggle to set variable server copy as top_of_frame, scheduled, async \n */
VS_COPY_MODE copy_mode ; /**< trick_io(**) */
/** Toggle to set variable server writes as when copied or async.\n */
VS_WRITE_MODE write_mode ; /**< trick_io(**) */
/** multiples of frame_count to copy data. Only used at top_of_frame\n */
int frame_multiple ; /**< trick_io(**) */
/** multiples of frame_count to copy data. Only used at top_of_frame\n */
int frame_offset ; /**< trick_io(**) */
/** multiples of frame_count to copy data. Only used at top_of_frame\n */
int freeze_frame_multiple ; /**< trick_io(**) */
/** multiples of frame_count to copy data. Only used at top_of_frame\n */
int freeze_frame_offset ; /**< trick_io(**) */
/** Toggle to tell variable server to byteswap returned values.\n */
bool byteswap ; /**< trick_io(**) */
/** Toggle to tell variable server return data in binary format.\n */
bool binary_data ; /**< trick_io(**) */
/** Toggle to tell variable server return data in binary format without the variable names.\n */
bool binary_data_nonames ; /**< trick_io(**) */
/** Toggle to tell variable server to send data multicast or point to point.\n */
bool multicast ; /**< trick_io(**) */
/** Flag to indicate the connection has been made\n */
bool connection_accepted ; /**< trick_io(**) */
/** Value set in var_cycle command.\n */
double update_rate ; /**< trick_io(**) */
/** The update rate in integer tics.\n */
long long cycle_tics ; /**< trick_io(**) */
/** The next call time in integer tics of the job to copy client data (sync mode).\n */
long long next_tics ; /**< trick_io(**) */
/** The next call time in integer tics of the job to copy client data (sync mode).\n */
long long freeze_next_tics ; /**< trick_io(**) */
/** Indicate whether variable data has been written into buffer_in.\n */
bool var_data_staged; /**< trick_io(**) */
/** number of packets copied to client \n */
unsigned int packets_copied ; /**< trick_io(**) */
/** Toggle to indicate sending python stdout and stderr to client\n */
bool send_stdio ; /**< trick_io(**) */
/** Holding area for the incoming message\n */
char *incoming_msg; /**< trick_io(**) */
/** Message with '\r' characters removed\n */
char *stripped_msg; /**< trick_io(**) */
/** Maximum size of incoming message\n */
static const unsigned int MAX_CMD_LEN = 200000 ;
} ;
}
#endif

View File

@ -45,5 +45,8 @@ void set_output_dir(const char* output_directory);
std::string & command_line_args_get_input_file_ref(void) ;
#endif
void create_path(const char* directory);
#endif

View File

@ -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"

View File

@ -48,8 +48,6 @@ PROGRAMMERS:
#define TC_READWRITE_TIMEOUT -2
#define TC_BROKEN_PIPE -3
#define TC_COULD_NOT_SET_SOCKET_PRIORITY 16
/* Set default for blocking timeout limit high */
#define MAX_BLOCKIO_TIMEOUT_LIMIT 1.0e20

View File

@ -111,12 +111,6 @@ int tc_error(TCDevice * device, int on_off);
/* copy a device */
int tc_dev_copy(TCDevice * dest, TCDevice * src);
#ifndef __APPLE__
/* set priority of socket for a device */
#define tc_set_socket_priority(listen_device, device, priority) tc_set_socket_priority_(listen_device, device, priority, __FILE__, __LINE__)
int tc_set_socket_priority_(TCDevice * listen_device, TCDevice * device, int priority, const char *file, int line) ;
#endif
void *trick_bswap_buffer(void *out, void *in, ATTRIBUTES * attr, int tofrom) ;
void *trick_bswap_single_parameter(void *out, void *in, ATTRIBUTES * attr, int tofrom) ;
#ifdef __cplusplus

View File

@ -112,7 +112,6 @@ class ParsedBinaryMessage {
void combine (const ParsedBinaryMessage& message);
int parse (const std::vector<unsigned char>& bytes);
int parse (char * raw_bytes);
int getMessageType() const;
unsigned int getMessageSize() const;
@ -139,4 +138,4 @@ class ParsedBinaryMessage {
const static size_t variable_name_length_size;
const static size_t variable_type_size;
const static size_t variable_size_size;
};
};

View File

@ -1,68 +0,0 @@
/*
PURPOSE:
(Allows clients to get and set Trick parameters)
PROGRAMMERS:
(((Keith Vetter) (LinCom) (September 2001) (--)))
*/
#ifndef VARIABLE_SERVER_H
#define VARIABLE_SERVER_H
#include <pthread.h>
#include "trick/reference.h"
#include "trick/tc.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
REF2 ref;
double scale_factor;
double bias;
} VARIABLE_NODE;
typedef struct {
int socket ; /* ** multicast socket file descriptor */
struct sockaddr_in addr ; /* ** multicast socket info */
} MCAST_INFO;
typedef struct VARIABLE_SERVER_struct {
int enabled ;
int debug; /* ** Variable_server debugging */
int synchronous ;
double update_rate;
double next;
int binary_data;
int no_handshake;
int num_vars;
int clear_cmd;
int send_cmd;
int pause_cmd;
int exists_cmd;
int exit_cmd;
VARIABLE_NODE *vars;
int multicast_on ; /* -- flag to switch between TCdevice and multcast socket */
TCDevice * connection ;
MCAST_INFO mcast_info ;
char local_byteorder ;
pthread_t thread_id ;
} VARIABLE_SERVER;
//void *var_server(void *); /* Server thread */
//void *var_serve_init(void *); /* Initialize server */
//void exit_var_server(void *); /* Exit handler for var init server */
//void exit_var_serv_threads( void ); /* Exit handler for var init server */
int vs_mcast_init(MCAST_INFO * M, char * address , int port ) ;
//int vs_write_data(VARIABLE_SERVER * V) ;
//int vs_write_error(VARIABLE_SERVER * V, char * incoming_str , char * error_str ) ;
//int vs_format_ascii(REF2 * ref, double scale_factor, double bias, char *value) ;
#ifdef __cplusplus
}
#endif
#endif

View File

@ -66,7 +66,7 @@ export TRICK_PYTHON_PATH := $(TRICK_PYTHON_PATH)
export TRICK_GTE_EXT := $(TRICK_GTE_EXT)
export TRICK_HOST_CPU := $(shell TRICK_FORCE_32BIT=$(TRICK_FORCE_32BIT) $(TRICK_HOME)/bin/trick-gte TRICK_HOST_CPU)
export TRICK_EXEC_LINK_LIBS := ${PTHREAD_LIBS} $(PYTHON_LIB) $(UDUNITS_LDFLAGS) $(PLATFORM_LIBS) -lm -ldl
export TRICK_LIBS := ${RPATH} -L${TRICK_LIB_DIR} -ltrick -ltrick_pyip -ltrick_comm -ltrick_math -ltrick_units -ltrick_mm
export TRICK_LIBS := ${RPATH} -L${TRICK_LIB_DIR} -ltrick -ltrick_pyip -ltrick_comm -ltrick_math -ltrick_units -ltrick_mm -ltrick_connection_handlers
export TRICK_SYSTEM_LDFLAGS := $(TRICK_SYSTEM_LDFLAGS)
export TRICK_SYSTEM_ICG_EXCLUDE := $(TRICK_SYSTEM_ICG_EXCLUDE)
export TRICK_SWIG_FLAGS := $(TRICK_SWIG_FLAGS)

View File

@ -110,7 +110,7 @@ class TestVariableServer(unittest.TestCase):
def test_set_period(self):
self.variable_server.set_period(10)
# We would like to verify that VariableServerThread::update_rate
# We would like to verify that VariableServerSessionThread::update_rate
# was modified, but variable server threads are not registered
# with the memory manager, so we can't.
@ -137,38 +137,38 @@ class TestVariableServer(unittest.TestCase):
def test_pause(self):
self.variable_server.pause(True)
self.variable_server.pause(False)
# We would like to verify that VariableServerThread::pause_cmd
# We would like to verify that VariableServerSessionThread::pause_cmd
# was modified, but variable server threads are not registered
# with the memory manager, so we can't.
def test_set_debug(self):
self.variable_server.set_debug(3)
# We would like to verify that VariableServerThread::debug
# We would like to verify that VariableServerSessionThread::debug
# was modified, but variable server threads are not registered
# with the memory manager, so we can't.
def test_set_tag(self):
self.variable_server.set_tag('test')
# We would like to verify that
# VariableServerThread::connection.client_tag was modified, but
# VariableServerSessionThread::connection.client_tag was modified, but
# variable server threads are not registered with the memory
# manager, so we can't.
def test_set_copy_mode(self):
self.variable_server.set_copy_mode()
# We would like to verify that VariableServerThread::copy_mode
# We would like to verify that VariableServerSessionThread::copy_mode
# was modified, but variable server threads are not registered
# with the memory manager, so we can't.
def test_send_on_copy(self):
self.variable_server.send_on_copy()
# We would like to verify that VariableServerThread::write_mode
# We would like to verify that VariableServerSessionThread::write_mode
# was modified, but variable server threads are not registered
# with the memory manager, so we can't.
def test_validate_addresses(self):
self.variable_server.validate_addresses()
# We would like to verify that VariableServerThread::validate_addresses
# We would like to verify that VariableServerSessionThread::validate_addresses
# was modified, but variable server threads are not registered
# with the memory manager, so we can't.

View File

@ -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"
@ -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() {
@ -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() ;
@ -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:
@ -456,22 +461,22 @@ class VariableServerSimObject : public Trick::SimObject {
{TRK} ("preload_checkpoint") vs.suspendPreCheckpointReload();
{TRK} ("restart") vs.restart();
{TRK} ("restart") vs.resumePostCheckpointReload();
{TRK} ("top_of_frame") vs.copy_data_top() ;
{TRK} ("automatic_last") vs.copy_data_scheduled() ;
{TRK} ("top_of_frame") vs.copy_and_write_top() ;
{TRK} ("automatic_last") vs.copy_and_write_scheduled() ;
{TRK} ("freeze_init") vs.freeze_init() ;
{TRK} ("freeze_automatic") vs.copy_data_freeze_scheduled() ;
{TRK} ("freeze") vs.copy_data_freeze() ;
{TRK} ("freeze_automatic") vs.copy_and_write_freeze_scheduled() ;
{TRK} ("freeze") vs.copy_and_write_freeze() ;
{TRK} ("shutdown") vs.shutdown() ;
// Set the static VariableServer pointer in the VariableServerThread class.
Trick::VariableServerThread::set_vs_ptr(&vs) ;
// Set the static VariableServer pointer in the VariableServerSessionThread class.
Trick::VariableServerSessionThread::set_vs_ptr(&vs) ;
// get the process_event job and set it in the event processor.
vs.set_copy_data_job(get_job("vs.copy_data_scheduled")) ;
vs.set_copy_data_freeze_job(get_job("vs.copy_data_freeze_scheduled")) ;
vs.set_copy_data_job(get_job("vs.copy_and_write_scheduled")) ;
vs.set_copy_and_write_freeze_job(get_job("vs.copy_and_write_freeze_scheduled")) ;
}
private:

View File

@ -205,7 +205,7 @@ class Job(object):
for getting status information. More specific types of Jobs should inherit from
this base clasee.
"""
enums = ['NOT_STARTED', 'RUNNING', 'SUCCESS', 'FAILED']
enums = ['NOT_STARTED', 'RUNNING', 'SUCCESS', 'FAILED', 'TIMEOUT']
Status = collections.namedtuple('Status', enums)(*(range(len(enums))))
_success_progress_bar = create_progress_bar(1, 'Success')
@ -220,7 +220,9 @@ class Job(object):
Job.Status.NOT_STARTED: ('NOT RUN', 'DARK_YELLOW'),
Job.Status.SUCCESS: ('OK', 'DARK_GREEN'),
Job.Status.FAILED: ('FAIL:' + str(self._expected_exit_status) + '/' +
str(self._exit_status), 'DARK_RED') }[self.get_status()]
str(self._exit_status), 'DARK_RED'),
Job.Status.TIMEOUT: ('TIMEOUT after ' + str(self._timeout) + ' seconds', 'YELLOW')
}[self.get_status()]
return printer.colorstr(text, color)
def __init__(self, name, command, log_file, expected_exit_status=0):
@ -245,6 +247,7 @@ class Job(object):
self._stop_time = None
self._exit_status = None
self._expected_exit_status = expected_exit_status
self._timeout = None
def start(self):
"""
@ -275,6 +278,8 @@ class Job(object):
This job completed with an exit status of zero.
Status.FAILED
This job completed with a non-zero exit status.
Status.TIMEOUT
This job ran longer than the allotted time given by execute_job
"""
if self._process is None:
return self.Status.NOT_STARTED
@ -283,6 +288,9 @@ class Job(object):
if self._exit_status is None:
return self.Status.RUNNING
if self._timeout is not None:
return self.Status.TIMEOUT
if self._stop_time is None:
self._stop_time = time.time()
@ -368,6 +376,17 @@ class Job(object):
"""
return self._done_string()
def _timeout_string(self):
"""
Get a string to display when this Job has failed.
Returns
-------
str
A string to be displayed when in the FAILED state.
"""
return self._done_string()
def _done_string(self):
"""
This class uses the same string for SUCCESS and FAILED, but
@ -408,7 +427,7 @@ class Job(object):
by sending them the SIGKILL signal.
"""
try:
os.killpg(os.getpgid(self._process.pid), signal.SIGKILL)
os.killpg(os.getpgid(self._process.pid), signal.SIGABRT)
self._process.wait()
except:
pass
@ -573,7 +592,7 @@ class WorkflowCommon:
else:
return 'unknown'
def execute_jobs(self, jobs, max_concurrent=None, header=None):
def execute_jobs(self, jobs, max_concurrent=None, header=None, job_timeout=None):
"""
Run jobs, blocking until all have returned.
@ -694,6 +713,15 @@ class WorkflowCommon:
for i in range(min(len(waitingJobs), available_cpus)):
waitingJobs[i].start()
if job_timeout is not None:
# Check if any jobs have timed out
runningJobs = [job for job in jobs if job.get_status() is job.Status.RUNNING]
for runningJob in runningJobs:
if time.time() - runningJob._start_time > job_timeout:
runningJob._timeout = job_timeout
runningJob._stop_time = time.time()
runningJob.die()
# display the status if enabled
if stdscr:
status_pad.erase()
@ -802,8 +830,8 @@ class WorkflowCommon:
text, color = {
job.Status.NOT_STARTED: ('was not run', 'GREY40'),
job.Status.SUCCESS: ('succeeded', 'DARK_GREEN'),
job.Status.FAILED: ('failed', 'DARK_RED')
}[job.get_status()]
job.Status.FAILED: ('failed', 'DARK_RED'),
job.Status.TIMEOUT: ('timed out', 'YELLOW') }[job.get_status()]
text = job.name + ' ' + text

1
test/.gitignore vendored
View File

@ -27,3 +27,4 @@ build
S_sie.json
*.ckpnt
MonteCarlo_Meta_data_output
*.xml

View File

@ -0,0 +1,24 @@
import trick
from trick.unit_test import *
def main():
trick.var_server_set_port(40000)
trick.var_ascii()
trick.real_time_enable()
trick.exec_set_software_frame(0.01)
trick.exec_set_terminate_time(1000.0)
trick.var_server_set_source_address('localhost')
varServerPort = trick.var_server_get_port()
test_output = ( os.getenv("TRICK_HOME") + "/trick_test/SIM_test_varserv.xml" )
command = 'os.system("./models/test_client/test_client_err1 ' + str(varServerPort) + ' --gtest_output=xml:' + test_output + ' &")'
# Start the test client after everything has been initialized (hopefully)
trick.add_read(1.0, command)
if __name__ == "__main__":
main()

View File

@ -0,0 +1,24 @@
import trick
from trick.unit_test import *
def main():
trick.var_server_set_port(40000)
trick.var_ascii()
trick.real_time_enable()
trick.exec_set_software_frame(0.01)
trick.exec_set_terminate_time(1000.0)
trick.var_server_set_source_address('localhost')
varServerPort = trick.var_server_get_port()
test_output = ( os.getenv("TRICK_HOME") + "/trick_test/SIM_test_varserv.xml" )
command = 'os.system("./models/test_client/test_client_err2 ' + str(varServerPort) + ' --gtest_output=xml:' + test_output + ' &")'
# Start the test client after everything has been initialized (hopefully)
trick.add_read(1.0, command)
if __name__ == "__main__":
main()

View File

@ -5,7 +5,7 @@ from trick.unit_test import *
def main():
trick.var_server_set_port(4000)
trick.var_server_set_port(40000)
trick.var_ascii()
trick.real_time_enable()
trick.exec_set_software_frame(0.01)

View File

@ -1,5 +1,4 @@
import trick
import socket
from trick.unit_test import *
@ -10,12 +9,17 @@ 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()
trick.var_server_create_tcp_socket('localhost', 49000)
trick.var_server_create_udp_socket('', 48000)
trick.var_server_create_multicast_socket('224.10.10.10','', 47000)
hostname = trick.var_server_get_hostname()
trick.exec_set_terminate_time(1000.0)
trick.var_server_set_socket_priority(7)
trick.var_server_create_tcp_socket(hostname, 49000)
trick.var_server_create_udp_socket(hostname, 48000)
trick.var_server_create_multicast_socket('224.10.10.10',hostname, 47000)
trick.exec_set_terminate_time(100.0)
varServerPort = trick.var_server_get_port()
test_output = ( os.getenv("TRICK_HOME") + "/trick_test/SIM_test_varserv.xml" )

View File

@ -2,7 +2,7 @@
TRICK_CFLAGS += -I./models
TRICK_CXXFLAGS += -I./models
all: test_client
all: test_client test_client_err1 test_client_err2
clean: clean_test_client
TEST_CLIENT_LIBS += -L${GTEST_HOME}/lib64 -L${GTEST_HOME}/lib -lgtest -lgtest_main -lpthread -L${TRICK_LIB_DIR} -ltrick_var_binary_parser
@ -10,6 +10,12 @@ TEST_CLIENT_LIBS += -L${GTEST_HOME}/lib64 -L${GTEST_HOME}/lib -lgtest -lgtest_ma
test_client: models/test_client/test_client.cpp
cd models/test_client; $(TRICK_CXX) test_client.cpp -o test_client $(TRICK_CXXFLAGS) $(TRICK_SYSTEM_CXXFLAGS) $(TRICK_TEST_FLAGS) -Wno-write-strings -Wno-sign-compare -I$(TRICK_HOME)/include $(TEST_CLIENT_LIBS)
test_client_err1: models/test_client/test_client_err1.cpp
cd models/test_client; $(TRICK_CXX) test_client_err1.cpp -o test_client_err1 $(TRICK_CXXFLAGS) $(TRICK_SYSTEM_CXXFLAGS) $(TRICK_TEST_FLAGS) -Wno-write-strings -Wno-sign-compare -I$(TRICK_HOME)/include $(TEST_CLIENT_LIBS)
test_client_err2: models/test_client/test_client_err2.cpp
cd models/test_client; $(TRICK_CXX) test_client_err2.cpp -o test_client_err2 $(TRICK_CXXFLAGS) $(TRICK_SYSTEM_CXXFLAGS) $(TRICK_TEST_FLAGS) -Wno-write-strings -Wno-sign-compare -I$(TRICK_HOME)/include $(TEST_CLIENT_LIBS)
clean_test_client:
rm -f models/test_client/test_client
rm -f models/test_client/test_client models/test_client/test_client_err1 models/test_client/test_client_err2

View File

@ -0,0 +1 @@
hi hello world

View File

@ -1 +1,3 @@
test_client
test_client
test_client_err1
test_client_err2

View File

@ -1,240 +1,7 @@
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/select.h>
#include <sys/time.h>
#include <netinet/in.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <string>
#include <sstream>
#include <iostream>
#include <functional>
#include <cmath>
#include <ctype.h>
#include <pwd.h>
#include <netdb.h>
#include <gtest/gtest.h>
#include "test_client.hh"
#include "trick/var_binary_parser.hh"
#include <math.h>
#define DOUBLE_TOL 1e-5
#define SOCKET_BUF_SIZE 204800
// Pretend that gtest was kind enough to provide an EXPECT_FEQ operator with a tolerance
#define EXPECT_FEQ(a,b) EXPECT_LE(fabs(a - b), DOUBLE_TOL)
class Socket {
public:
int max_retries = 10;
Socket() : _initialized(false) {}
int init(std::string hostname, int port, int mode = SOCK_STREAM) {
_multicast_socket = false;
_hostname = hostname;
_port = port;
int tries = 0;
while ((_socket_fd = socket(AF_INET, mode, 0)) < 0 && tries < max_retries) tries++;
if (_socket_fd < 0) {
std::cout << "Socket connection failed" << std::endl;
return -1;
}
int value = 1;
if (setsockopt(_socket_fd, SOL_SOCKET, SO_REUSEADDR, (char *) &value, (socklen_t) sizeof(value)) < 0) {
std::cout << "init_multicast: Socket option failed" << std::endl;
return -1;
}
if (setsockopt(_socket_fd, SOL_SOCKET, SO_REUSEPORT, (char *) &value, sizeof(value)) < 0) {
perror("setsockopt: reuseport");
}
struct sockaddr_in serv_addr;
serv_addr.sin_family = AF_INET;
serv_addr.sin_port = htons(port); // convert to weird network byte format
serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
tries = 0;
int connection_status;
while ((connection_status = connect(_socket_fd, (struct sockaddr *)&serv_addr, sizeof(serv_addr))) < 0 && tries < max_retries) tries++;
if (connection_status < 0) {
std::cout << "Connection failed" << std::endl;
return -1;
}
_initialized = true;
return 0;
}
#ifndef __APPLE__
int init_multicast (std::string hostname, int port) {
_multicast_socket = true;
_hostname = hostname;
_port = port;
int tries = 0;
_socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
if (_socket_fd < 0) {
std::cout << "init_multicast: Socket open failed" << std::endl;
return -1;
}
int value = 1;
if (setsockopt(_socket_fd, SOL_SOCKET, SO_REUSEADDR, (char *) &value, (socklen_t) sizeof(value)) < 0) {
std::cout << "init_multicast: Socket option failed" << std::endl;
return -1;
}
if (setsockopt(_socket_fd, SOL_SOCKET, SO_REUSEPORT, (char *) &value, sizeof(value)) < 0) {
perror("setsockopt: reuseport");
}
struct ip_mreq mreq;
// Use setsockopt() to request that the kernel join a multicast group
mreq.imr_multiaddr.s_addr = inet_addr(_hostname.c_str());
mreq.imr_interface.s_addr = htonl(INADDR_ANY);
if (setsockopt(_socket_fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *) &mreq, (socklen_t) sizeof(mreq)) < 0) {
std::cout << "init_multicast: setsockopt: ip_add_membership failed" << std::endl;
return -1;
}
struct sockaddr_in sockin ;
// Set up local interface
// We must bind to the multicast address
sockin.sin_family = AF_INET;
sockin.sin_addr.s_addr = inet_addr(_hostname.c_str());
sockin.sin_port = htons(_port);
if ( bind(_socket_fd, (struct sockaddr *) &sockin, (socklen_t) sizeof(sockin)) < 0 ) {
std::cout << "init_multicast: bind failed" << std::endl;
return -1;
}
char loopch = 1;
if(setsockopt(_socket_fd, IPPROTO_IP, IP_MULTICAST_LOOP, (char *)&loopch, sizeof(loopch)) < 0)
{
perror("Setting IP_MULTICAST_LOOP error");
return -1;
}
_initialized = true;
return 0;
}
#endif
int send (std::string message) {
// weird syntax I've never used before - since the send syscall that i'm trying to use is overloaded in this class,
// I have to append :: to the front of it so that the compiler knows to look in the global namespace
int success = ::send(_socket_fd, message.c_str(), message.size(), 0);
if (success < message.size()) {
std::cout << "init_multicast: Failed to send message" << std::endl;
}
return success;
}
int operator<< (std::string message) {
return send(message);
}
std::string receive () {
char buffer[SOCKET_BUF_SIZE];
int numBytes = recv(_socket_fd, buffer, SOCKET_BUF_SIZE, 0);
if (numBytes < 0) {
} else if (numBytes < SOCKET_BUF_SIZE) {
buffer[numBytes] = '\0';
}
return std::string(buffer);
}
void operator>> (std::string& ret) {
ret = receive();
}
std::vector<unsigned char> receive_bytes() {
unsigned char buffer[SOCKET_BUF_SIZE];
int numBytes = recv(_socket_fd, buffer, SOCKET_BUF_SIZE, 0);
if (numBytes < 0) {
std::cout << "init_multicast: Failed to read from socket" << std::endl;
}
std::vector<unsigned char> bytes;
for (int i = 0; i < numBytes; i++) {
bytes.push_back(buffer[i]);
}
return bytes;
}
bool check_for_message_availible(long timeout_sec = 2) {
fd_set read_fd_set;
struct timeval timeout = { .tv_sec = timeout_sec, .tv_usec = 0 };
FD_ZERO(&read_fd_set);
FD_SET(_socket_fd, &read_fd_set);
// I have one question for the designers of the interface for this syscall: why
select(_socket_fd+1, &read_fd_set, NULL, NULL, &timeout);
return FD_ISSET(_socket_fd, &read_fd_set);
}
void clear_buffered_data() {
// Poll the socket
if (check_for_message_availible(0)) {
// Receive into the void if there is a message
receive();
}
// otherwise no worries
}
void close() {
::close(_socket_fd);
}
private:
int _port;
std::string _hostname;
int _socket_fd;
bool _initialized;
bool _multicast_socket;
};
class VariableServerTest : public ::testing::Test {
protected:
VariableServerTest() {
socket_status = socket.init("localhost", 40000);
if (socket_status == 0) {
std::stringstream request;
request << "trick.var_set_client_tag(\"VSTest";
request << numSession++;
request << "\") \n";
socket << request.str();
}
}
~VariableServerTest() {
socket << "trick.var_exit()\n";
socket.close();
}
Socket socket;
int socket_status;
static int numSession;
};
class VariableServerUDPTest : public ::testing::Test {
protected:
@ -285,12 +52,16 @@ class VariableServerTestAltListener : public ::testing::Test {
static int numSession;
};
int VariableServerTest::numSession = 0;
int VariableServerUDPTest::numSession = 0;
int VariableServerTestAltListener::numSession = 0;
#ifndef __APPLE__
class VariableServerTestMulticast : public ::testing::Test {
protected:
VariableServerTestMulticast() {
socket_status = socket.init("", 47000, SOCK_DGRAM);
multicast_listener.init_multicast("224.10.10.10", 47000);
socket_status = multicast_listener.init_multicast("224.10.10.10", 47000);
if (socket_status == 0) {
std::stringstream request;
@ -316,11 +87,6 @@ class VariableServerTestMulticast : public ::testing::Test {
int VariableServerTestMulticast::numSession = 0;
#endif
int VariableServerTest::numSession = 0;
int VariableServerUDPTest::numSession = 0;
int VariableServerTestAltListener::numSession = 0;
/**********************************************************/
/* Helpful constants and functions */
/**********************************************************/
@ -640,7 +406,7 @@ TEST_F (VariableServerTestAltListener, RestartAndSet) {
load_checkpoint(socket, "RUN_test/reload_file.ckpnt");
socket >> reply;
expected = std::string("0\t-1234\t-123456\n");
expected = std::string("0\t-1234\t-123456 {m}\n");
EXPECT_EQ(reply, expected);
}
@ -797,6 +563,18 @@ TEST_F (VariableServerTest, Units) {
EXPECT_EQ(strcmp_IgnoringWhiteSpace(reply, expected), 0);
}
TEST_F (VariableServerTest, dump_info) {
if (socket_status != 0) {
FAIL();
}
socket << "trick.var_add(\"vsx.vst.c\")\n";
std::string command = "trick.var_server_list_connections()\n";
socket << command;
sleep(1);
}
TEST_F (VariableServerTest, SendOnce) {
if (socket_status != 0) {
FAIL();
@ -903,6 +681,153 @@ TEST_F (VariableServerTest, ListSize) {
}
TEST_F (VariableServerTest, bitfields) {
if (socket_status != 0) {
FAIL();
}
socket << "trick.var_send_once(\"vsx.vst.my_bitfield.var1,vsx.vst.my_bitfield.var2,vsx.vst.my_bitfield.var3,vsx.vst.my_bitfield.var4\", 4)\n";
std::string reply_str;
socket >> reply_str;
EXPECT_EQ(strcmp_IgnoringWhiteSpace(reply_str, "5 3 -128 0 2112"), 0);
socket << "trick.var_binary()\ntrick.var_send_once(\"vsx.vst.my_bitfield.var1,vsx.vst.my_bitfield.var2,vsx.vst.my_bitfield.var3,vsx.vst.my_bitfield.var4\", 4)\n";
std::vector<unsigned char> reply = socket.receive_bytes();
ParsedBinaryMessage message;
try {
message.parse(reply);
} catch (const MalformedMessageException& ex) {
FAIL() << "Parser threw an exception: " << ex.what();
}
for (int i = 0; i < message.getNumVars(); i++) {
EXPECT_TRUE(message.variables[i].getType() == 12 || message.variables[i].getType() == 13);
}
}
TEST_F (VariableServerTest, transmit_file) {
if (socket_status != 0) {
FAIL();
}
socket << "trick.send_file(\"file_to_send.txt\")\n";
std::stringstream file_contents;
while (socket.check_for_message_availible()) {
socket >> file_contents;
}
std::ifstream actual_file("file_to_send.txt");
std::string expected_contents;
getline(actual_file, expected_contents);
std::string expected_header = "2\t" + std::to_string(expected_contents.size());
std::string test_line;
std::getline(file_contents, test_line);
EXPECT_EQ(test_line, expected_header);
std::getline(file_contents, test_line);
EXPECT_EQ(test_line, expected_contents);
}
TEST_F (VariableServerTest, SendSieResource) {
if (socket_status != 0) {
FAIL();
}
socket << "trick.send_sie_resource()\n";
std::stringstream received_file;
while (socket.check_for_message_availible()) {
socket >> received_file;
}
std::string first_line;
std::getline(received_file, first_line);
// We're not gonna bother comparing the contents
// Just check to see that the message type is correct
ASSERT_EQ(first_line.at(0), '2');
}
TEST_F (VariableServerTest, SendSieClass) {
if (socket_status != 0) {
FAIL();
}
socket << "trick.send_sie_class()\n";
std::stringstream received_file;
std::string file_temp;
while (socket.check_for_message_availible()) {
socket >> file_temp;
received_file << file_temp;
}
std::string first_line;
std::getline(received_file, first_line);
// We're not gonna bother comparing the contents
// Just check to see that the message type is correct
ASSERT_EQ(first_line.at(0), '2');
}
TEST_F (VariableServerTest, SendSieEnum) {
if (socket_status != 0) {
FAIL();
}
socket << "trick.send_sie_enum()\n";
std::stringstream received_file;
std::string file_temp;
while (socket.check_for_message_availible()) {
socket >> file_temp;
received_file << file_temp;
}
std::string first_line;
std::getline(received_file, first_line);
// We're not gonna bother comparing the contents
// Just check to see that the message type is correct
ASSERT_EQ(first_line.at(0), '2');
}
TEST_F (VariableServerTest, SendSieClassTopLevelObjects) {
if (socket_status != 0) {
FAIL();
}
socket << "trick.send_sie_top_level_objects()\n";
std::stringstream received_file;
std::string file_temp;
while (socket.check_for_message_availible()) {
socket >> file_temp;
received_file << file_temp;
}
std::string first_line;
std::getline(received_file, first_line);
// We're not gonna bother comparing the contents
// Just check to see that the message type is correct
ASSERT_EQ(first_line.at(0), '2');
}
TEST_F (VariableServerTest, RestartAndSet) {
if (socket_status != 0) {
FAIL();
@ -932,7 +857,7 @@ TEST_F (VariableServerTest, RestartAndSet) {
load_checkpoint(socket, "RUN_test/reload_file.ckpnt");
socket >> reply;
expected = std::string("0\t-1234\t-123456\n");
expected = std::string("0\t-1234\t-123456 {m}\n");
EXPECT_EQ(reply, expected);
}
@ -979,6 +904,7 @@ TEST_F (VariableServerTest, Cycle) {
socket << command;
// Give it a cycle to update
socket.receive();
socket.receive();
double sim_time = parse_message_for_sim_time(socket.receive());
compare_cycle(num_cycles, sim_time);
};
@ -1042,7 +968,7 @@ TEST_F (VariableServerTest, Multicast) {
FAIL() << "Multicast Socket failed to initialize.";
}
int max_multicast_tries = 100;
int max_multicast_tries = 10000;
int tries = 0;
bool found = false;
@ -1156,7 +1082,28 @@ TEST_F (VariableServerTest, Freeze) {
// Sim mode should be MODE_FREEZE == 1
ASSERT_EQ(mode, MODE_FREEZE);
// Not sure what else to test in copy mode VS_COPY_ASYNC
// Set to back to run mode
socket << "trick.exec_run()\n";
// The mode takes a little bit of time to change
wait_for_mode_change(MODE_RUN);
// Sim mode should be MODE_RUN
ASSERT_EQ(mode, MODE_RUN);
// Test VS_COPY_SCHEDULED - should see 1 message per frame
socket << "trick.var_set_copy_mode(1)\n";
// Change back to freeze mode
// Set to Freeze mode
socket << "trick.exec_freeze()\n";
// The mode takes a little bit of time to change
wait_for_mode_change(MODE_FREEZE);
// Sim mode should be MODE_FREEZE == 1
ASSERT_EQ(mode, MODE_FREEZE);
// Test VS_COPY_SCHEDULED - should see 1 message per frame
socket << "trick.var_set_copy_mode(1)\n";
@ -1243,24 +1190,26 @@ TEST_F (VariableServerTest, CopyAndWriteModes) {
socket.clear_buffered_data();
// Copy mode 1 (VS_COPY_SCHEDULED) write mode 0 (VS_WRITE_ASYNC)
command = "trick.var_clear()\n" + test_vars_command + "trick.var_set_copy_mode(1)\ntrick.var_add(\"vsx.vst.c\")\ntrick.var_add(\"vsx.vst.d\")\ntrick.var_unpause()\n";
command = "trick.var_clear()\n" + test_vars_command + "trick.var_sync(1)\ntrick.var_add(\"vsx.vst.c\")\ntrick.var_add(\"vsx.vst.d\")\ntrick.var_unpause()\n";
socket << command;
// With copy mode VS_COPY_SCHEDULED and write mode VS_WRITE_ASYNC, the first reply will be all 0 since the main time to copy has not occurred yet.
// Is this what we want? Maybe we should have more strict communication on whether the data has been staged so the first message isn't incorrect
// spin();
spin(socket);
expected = "-1234 1234";
parse_message(socket.receive());
EXPECT_EQ(strcmp_IgnoringWhiteSpace(vars, expected), 0) << "Received: " << vars << " Expected: " << expected;
// Test that we see a difference of exactly expected_cycle (with a tolerance for floating point issues)
int prev_frame = 0;
double prev_time = 0;
for (int i = 0; i < num_tests; i++) {
prev_time = sim_time;
parse_message(socket.receive());
EXPECT_FEQ(sim_time - prev_time, expected_cycle);
EXPECT_LT(fmod(sim_time - prev_time, expected_cycle), DOUBLE_TOL);
EXPECT_EQ(strcmp_IgnoringWhiteSpace(vars, expected), 0) << "Received: " << vars << " Expected: " << expected;
}
@ -1273,6 +1222,8 @@ TEST_F (VariableServerTest, CopyAndWriteModes) {
command = "trick.var_clear()\n" + test_vars_command + "trick.var_set_write_mode(1)\ntrick.var_add(\"vsx.vst.e\")\ntrick.var_add(\"vsx.vst.f\")\ntrick.var_unpause()\n";
socket << command;
spin(socket);
parse_message(socket.receive());
expected = "-123456 123456";
EXPECT_EQ(strcmp_IgnoringWhiteSpace(vars, expected), 0) << "Received: " << vars << " Expected: " << expected;
@ -1283,7 +1234,7 @@ TEST_F (VariableServerTest, CopyAndWriteModes) {
for (int i = 0; i < num_tests; i++) {
prev_time = sim_time;
parse_message(socket.receive());
EXPECT_FEQ(sim_time - prev_time, expected_cycle);
EXPECT_LT(fmod(sim_time - prev_time, expected_cycle), DOUBLE_TOL);
EXPECT_EQ(strcmp_IgnoringWhiteSpace(vars, expected), 0) << "Received: " << vars << " Expected: " << expected;
}
@ -1300,7 +1251,7 @@ TEST_F (VariableServerTest, CopyAndWriteModes) {
socket << command;
// Same issue as copy mode 1 write mode 0
// spin();
spin(socket);
parse_message(socket.receive());
expected = "-1234567 123456789";
EXPECT_EQ(strcmp_IgnoringWhiteSpace(vars, expected), 0) << "Received: " << vars << " Expected: " << expected;
@ -1326,6 +1277,8 @@ TEST_F (VariableServerTest, CopyAndWriteModes) {
command = "trick.var_clear()\n" + test_vars_command + "trick.var_set_copy_mode(2)\ntrick.var_set_write_mode(1)\ntrick.var_set_frame_multiple(" + std::to_string(frame_multiple) + ")\ntrick.var_set_frame_offset(" + std::to_string(frame_offset) + ")\ntrick.var_add(\"vsx.vst.i\")\ntrick.var_add(\"vsx.vst.j\")\ntrick.var_unpause()\n";
socket << command;
spin(socket);
expected = "1234.5677 -1234.56789";
parse_message(socket.receive());
EXPECT_EQ(strcmp_IgnoringWhiteSpace(vars, expected), 0) << "Received: " << vars << " Expected: " << expected;
@ -1345,6 +1298,27 @@ TEST_F (VariableServerTest, CopyAndWriteModes) {
socket.clear_buffered_data();
}
TEST_F (VariableServerTest, var_set) {
if (socket_status != 0) {
FAIL();
}
std::string reply;
std::string expected;
socket << "trick.var_add(\"vsx.vst.c\")\ntrick.var_add(\"vsx.vst.blocked_from_output\")\ntrick.var_add(\"vsx.vst.blocked_from_input\")\n";
socket >> reply;
expected = std::string("0\t-1234\t0\t500\n");
EXPECT_EQ(reply, expected);
socket << "trick.var_set(\"vsx.vst.blocked_from_input\", 0)\n";
socket << "trick.var_set(\"vsx.vst.blocked_from_output\", 0)\n";
}
bool getCompleteBinaryMessage(ParsedBinaryMessage& message, Socket& socket, bool print = false) {
static const int max_retries = 5;
@ -1412,84 +1386,6 @@ TEST_F (VariableServerTest, send_stdio) {
}
#ifndef __APPLE__
TEST_F (VariableServerTest, MulticastAfterRestart) {
if (socket_status != 0) {
FAIL();
}
socket << "trick.var_server_set_user_tag(\"VSTestServer\")\n";
Socket multicast_socket;
if (multicast_socket.init_multicast("224.3.14.15", 9265) != 0) {
FAIL() << "Multicast Socket failed to initialize.";
}
int max_multicast_tries = 100;
int tries = 0;
bool found = false;
char expected_hostname[80];
gethostname(expected_hostname, 80);
int expected_port = 40000;
// get expected username
struct passwd *passp = getpwuid(getuid()) ;
char * expected_username;
if ( passp == NULL ) {
expected_username = strdup("unknown") ;
} else {
expected_username = strdup(passp->pw_name) ;
}
// Don't care about PID, just check that it's > 0
char * expected_sim_dir = "trick/test/SIM_test_varserv"; // Compare against the end of the string for this one
// Don't care about cmdline name
char * expected_input_file = "RUN_test/unit_test.py";
// Don't care about trick_version
char * expected_tag = "VSTestServer";
// Variables to be populated by the multicast message
char actual_hostname[80];
unsigned short actual_port = 0;
char actual_username[80];
int actual_pid = 0;
char actual_sim_dir[80];
char actual_cmdline_name[80];
char actual_input_file[80];
char actual_trick_version[80];
char actual_tag[80];
unsigned short actual_duplicate_port = 0;
while (!found && tries++ < max_multicast_tries) {
std::string broadcast_data = multicast_socket.receive();
sscanf(broadcast_data.c_str(), "%s\t%hu\t%s\t%d\t%s\t%s\t%s\t%s\t%s\t%hu\n" , actual_hostname, &actual_port ,
actual_username , &actual_pid , actual_sim_dir , actual_cmdline_name ,
actual_input_file , actual_trick_version , actual_tag, &actual_duplicate_port) ;
if (strcmp(actual_hostname, expected_hostname) == 0 && strcmp(expected_tag, actual_tag) == 0) {
found = true;
EXPECT_STREQ(actual_hostname, expected_hostname);
EXPECT_EQ(actual_port, expected_port);
EXPECT_STREQ(actual_username, expected_username);
EXPECT_GT(actual_pid, 0);
std::string expected_sim_dir_str(expected_sim_dir);
std::string actual_sim_dir_str(actual_sim_dir);
std::string end_of_actual = actual_sim_dir_str.substr(actual_sim_dir_str.length() - expected_sim_dir_str.length(), actual_sim_dir_str.length());
EXPECT_EQ(expected_sim_dir_str, end_of_actual);
EXPECT_STREQ(actual_input_file, expected_input_file);
EXPECT_STREQ(actual_tag, expected_tag);
EXPECT_EQ(actual_duplicate_port, expected_port);
}
}
if (!found)
FAIL() << "Multicast message never received";
}
#endif
TEST_F (VariableServerTest, Binary) {
if (socket_status != 0) {
FAIL();
@ -1666,4 +1562,4 @@ int main(int argc, char **argv) {
socket << "trick.stop() \n";
return result;
}
}

View File

@ -0,0 +1,235 @@
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/select.h>
#include <sys/time.h>
#include <netinet/in.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <string>
#include <sstream>
#include <iostream>
#include <functional>
#include <cmath>
#include <ctype.h>
#include <pwd.h>
#include <fstream>
#include <gtest/gtest.h>
#define DOUBLE_TOL 1e-5
#define SOCKET_BUF_SIZE 204800
// Pretend that gtest was kind enough to provide an EXPECT_FEQ operator with a tolerance
#define EXPECT_FEQ(a,b) EXPECT_LE(fabs(a - b), DOUBLE_TOL)
class Socket {
public:
int max_retries = 10;
Socket() : _initialized(false) {}
int init(std::string hostname, int port, int mode = SOCK_STREAM) {
_multicast_socket = false;
_hostname = hostname;
_port = port;
_socket_fd = socket(AF_INET, mode, 0);
if (_socket_fd < 0) {
std::cout << "Socket connection failed" << std::endl;
return -1;
}
int value = 1;
if (setsockopt(_socket_fd, SOL_SOCKET, SO_REUSEADDR, (char *) &value, (socklen_t) sizeof(value)) < 0) {
std::cout << "init_multicast: Socket option failed" << std::endl;
return -1;
}
struct sockaddr_in serv_addr;
serv_addr.sin_family = AF_INET;
serv_addr.sin_port = htons(port); // convert to weird network byte format
if(inet_pton(AF_INET, "127.0.0.1", &serv_addr.sin_addr)<=0) {
std::cout << "Invalid address/ Address not supported" << std::endl;
return -1;
}
int connection_status;
connection_status = connect(_socket_fd, (struct sockaddr *)&serv_addr, sizeof(serv_addr));
if (connection_status < 0) {
std::cout << "Connection failed" << std::endl;
return -1;
}
_initialized = true;
return 0;
}
#ifndef __APPLE__
int init_multicast (std::string hostname, int port) {
_multicast_socket = true;
_hostname = hostname;
_port = port;
_socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
if (_socket_fd < 0) {
std::cout << "init_multicast: Socket open failed" << std::endl;
return -1;
}
int value = 1;
if (setsockopt(_socket_fd, SOL_SOCKET, SO_REUSEADDR, (char *) &value, (socklen_t) sizeof(value)) < 0) {
std::cout << "init_multicast: Socket option failed" << std::endl;
return -1;
}
if (setsockopt(_socket_fd, SOL_SOCKET, SO_REUSEPORT, (char *) &value, sizeof(value)) < 0) {
perror("setsockopt: reuseport");
}
struct ip_mreq mreq;
// Use setsockopt() to request that the kernel join a multicast group
mreq.imr_multiaddr.s_addr = inet_addr(_hostname.c_str());
mreq.imr_interface.s_addr = htonl(INADDR_ANY);
if (setsockopt(_socket_fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *) &mreq, (socklen_t) sizeof(mreq)) < 0) {
std::cout << "init_multicast: setsockopt: ip_add_membership failed" << std::endl;
return -1;
}
struct sockaddr_in sockin ;
// Set up local interface
// We must bind to the multicast address
sockin.sin_family = AF_INET;
sockin.sin_addr.s_addr = inet_addr(_hostname.c_str());
sockin.sin_port = htons(_port);
if ( bind(_socket_fd, (struct sockaddr *) &sockin, (socklen_t) sizeof(sockin)) < 0 ) {
std::cout << "init_multicast: bind failed" << std::endl;
return -1;
}
char loopch = 1;
if(setsockopt(_socket_fd, IPPROTO_IP, IP_MULTICAST_LOOP, (char *)&loopch, sizeof(loopch)) < 0)
{
perror("Setting IP_MULTICAST_LOOP error");
return -1;
}
_initialized = true;
return 0;
}
#endif
int send (std::string message) {
// weird syntax I've never used before - since the send syscall that i'm trying to use is overloaded in this class,
// I have to append :: to the front of it so that the compiler knows to look in the global namespace
int success = ::send(_socket_fd, message.c_str(), message.size(), 0);
if (success < message.size()) {
std::cout << "init_multicast: Failed to send message" << std::endl;
}
return success;
}
int operator<< (std::string message) {
return send(message);
}
std::string receive () {
char buffer[SOCKET_BUF_SIZE];
int numBytes = recv(_socket_fd, buffer, SOCKET_BUF_SIZE, 0);
if (numBytes < 0) {
} else if (numBytes < SOCKET_BUF_SIZE) {
buffer[numBytes] = '\0';
}
return std::string(buffer);
}
void operator>> (std::string& ret) {
ret = receive();
}
void operator>> (std::ostream& stream) {
stream << receive();
}
std::vector<unsigned char> receive_bytes() {
unsigned char buffer[SOCKET_BUF_SIZE];
int numBytes = recv(_socket_fd, buffer, SOCKET_BUF_SIZE, 0);
if (numBytes < 0) {
std::cout << "init_multicast: Failed to read from socket" << std::endl;
}
std::vector<unsigned char> bytes;
for (int i = 0; i < numBytes; i++) {
bytes.push_back(buffer[i]);
}
return bytes;
}
bool check_for_message_availible(long timeout_sec = 2) {
fd_set read_fd_set;
struct timeval timeout = { .tv_sec = timeout_sec, .tv_usec = 0 };
FD_ZERO(&read_fd_set);
FD_SET(_socket_fd, &read_fd_set);
// I have one question for the designers of the interface for this syscall: why
select(_socket_fd+1, &read_fd_set, NULL, NULL, &timeout);
return FD_ISSET(_socket_fd, &read_fd_set);
}
void clear_buffered_data() {
// Poll the socket
if (check_for_message_availible(0)) {
// Receive into the void if there is a message
receive();
}
// otherwise no worries
}
void close() {
::close(_socket_fd);
}
private:
int _port;
std::string _hostname;
int _socket_fd;
bool _initialized;
bool _multicast_socket;
};
class VariableServerTest : public ::testing::Test {
protected:
VariableServerTest() {
socket_status = socket.init("localhost", 40000);
if (socket_status == 0) {
std::stringstream request;
request << "trick.var_set_client_tag(\"VSTest";
request << numSession++;
request << "\") \n";
socket << request.str();
}
}
~VariableServerTest() {
socket << "trick.var_exit()\n";
socket.close();
}
Socket socket;
int socket_status;
static int numSession;
};

View File

@ -0,0 +1,13 @@
#include "test_client.hh"
int VariableServerTest::numSession = 0;
TEST_F (VariableServerTest, SendExecutiveException) {
if (socket_status != 0) {
FAIL();
}
std::string command = "trick.exec_terminate_with_return(1, \"" + std::string(__FILE__) + "\", " + std::to_string(__LINE__) + ", \"Error termination for testing\")\n";
socket << command;
}

View File

@ -0,0 +1,13 @@
#include "test_client.hh"
int VariableServerTest::numSession = 0;
TEST_F (VariableServerTest, SendStdException) {
if (socket_status != 0) {
FAIL();
}
std::string command = "vsx.vst.throw_exception()\n";
socket << command;
}

View File

@ -13,13 +13,21 @@ PROGRAMMERS: ( (Lindsay Landry) (L3) (9-12-2013) ) ( (Jackie Dea
#ifndef VS_HH
#define VS_HH
typedef struct {
unsigned char var1 :3;
short var2 :8;
int var3 :9;
unsigned int var4 :12;
} bitfield;
class VSTest {
public:
char a;
unsigned char b;
short c;
unsigned short d;
int e; /* m xy-position */
int e; /* m xy-position */
unsigned int f;
long g;
unsigned long h;
@ -31,10 +39,15 @@ class VSTest {
int n[5];
std::string o;
char * p;
wchar_t * q; /**< trick_chkpnt_io(**) */
wchar_t * q; /**< trick_chkpnt_io(**) */
bitfield my_bitfield;
int large_arr[4000];
int blocked_from_input; /** trick_io(*o) */
int blocked_from_output; /** trick_io(*i) */
int status;
VSTest();
@ -48,6 +61,8 @@ class VSTest {
int success();
int fail();
void throw_exception();
const char *status_messages[3] = {
"Variable Server Test Success",
"Variable Server Test Failure",

View File

@ -8,9 +8,11 @@ PROGRAMMERS: ( (Lindsay Landry) (L3) (9-12-2013)
(Jackie Deans) (CACI) (11-30-2022) )
*******************************************************************************/
#include <iostream>
#include <stdexcept>
#include <limits>
#include "../include/VS.hh"
#include "trick/exec_proto.h"
#include <limits>
VSTest::VSTest() {}
VSTest::~VSTest() {}
@ -40,6 +42,19 @@ int VSTest::default_vars() {
for (int i = 0; i < 4000; i++) {
large_arr[i] = i;
}
/* Mixed Types */
// 3,-128,0,2112
my_bitfield.var1 = (1 << (3 - 1)) - 1;
my_bitfield.var2 = -(1 << (8 - 1));
my_bitfield.var3 = 0;
my_bitfield.var4 = (1 << (12 - 1)) + (1 << 12/2);;
blocked_from_input = 500;
blocked_from_output = 1000;
return 0;
}
int VSTest::init() {
@ -57,8 +72,18 @@ int VSTest::success() {
return 0;
}
void VSTest::throw_exception() {
throw std::logic_error("Pretend an error has occured for testing");
}
int VSTest::shutdown() {
std::cout << "Shutting down with status: " << status << " Message: " << status_messages[status] << std::endl;
// Check that the blocked_from_input variable hasnt changed
if (blocked_from_input != 500 || blocked_from_output != 0) {
status = 1;
}
exec_terminate_with_return( status , __FILE__ , __LINE__ , status_messages[status] ) ;
return(0);

View File

@ -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

View File

@ -312,11 +312,16 @@ SIM_test_varserv:
path: test/SIM_test_varserv
build_args: "-t"
binary: "T_main_{cpu}_test.exe"
labels:
- retries_allowed
runs:
RUN_test/unit_test.py:
phase: 1
returns: 0
RUN_test/err1_test.py:
phase: 2
returns: 10
RUN_test/err2_test.py:
phase: 3
returns: 10
SIM_amoeba:
path: trick_sims/Cannon/SIM_amoeba
build_args: "-t"

View File

@ -6,5 +6,10 @@ trick.itimer_enable()
trick.exec_set_enable_freeze(True)
# trick.exec_set_freeze_command(True)
# Print stack trace if signal is caught. default True
trick.exec_set_stack_trace(False)
# Attach a debugger to the process if a signal is caught. default False
trick.exec_set_attach_debugger(False)
simControlPanel = trick.SimControlPanel()
trick.add_external_application(simControlPanel)

View File

@ -146,17 +146,3 @@ else :
print('===================================')
print('PoolTableDisplay needs to be built.')
print('===================================')
# PoolTableDisplay_path = "models/graphics/java/dist/PoolTableDisplay.jar"
# if (os.path.isfile(PoolTableDisplay_path)) :
# PoolTableDisplay_cmd = "java -jar " \
# + PoolTableDisplay_path \
# + " " + str(varServerPort) + " &" ;
# print(PoolTableDisplay_cmd)
# os.system( PoolTableDisplay_cmd);
# else :
# print('=================================================================================================')
# print('PoolTableDisplay needs to be built. Please \"cd\" into ../models/graphics/java and type \"make\".')
# print('=================================================================================================')

View File

@ -492,7 +492,7 @@ std::vector<std::string> split (std::string& str, const char delim) {
std::stringstream ss(str);
std::string s;
std::vector<std::string> ret;
while (std::getline(ss, s, delim)) {
while (ss >> s) {
ret.push_back(s);
}
return ret;
@ -526,9 +526,11 @@ template <typename T>
T getVar(Socket& socket, std::string varName) {
std::string requestString = "trick.var_send_once(\"" + varName + "\")\n";
std::string reply;
// std::cout << "Request: " << requestString << std::endl;
socket << requestString;
socket >> reply;
// std::cout << "Reply: " << reply << std::endl;
return stringConvert<T>(split(reply, '\t')[1]);
}
@ -554,10 +556,13 @@ std::vector<T> getVarList(Socket& socket, std::string varName, int num) {
}
std::string requestString = "trick.var_send_once(\"" + totalRequest + "\", " + std::to_string(num) + ")\n";
// std::cout << "Request: " << requestString << std::endl;
std::string reply;
socket << requestString;
socket >> reply;
// std::cout << "Reply: " << reply << std::endl;
return trickResponseConvert<T>(reply);
}
@ -604,6 +609,13 @@ int main(int argc, char *argv[])
std::vector<double> tablePoints = fold(table_x, table_y);
Table table;
// std::cout << "TablePoints: ";
for (auto point : tablePoints ) {
// std::cout << point << " ";
}
// std::cout << "\ttableShape: " << tableShape << std::endl;
table.addShape(tablePoints, Eigen::Vector3d(0.2, 0.6, 0.2), true, tableShape, layer_TABLE);
// Make the rail - translate each point on the table out from center by railWidth
@ -697,7 +709,7 @@ int main(int argc, char *argv[])
std::string cueRequest = "";
std::string templateString = "dyn.table.applyCueForce(%.3f, %.3f) \n";
char buf[128];
char buf[2048];
snprintf(buf, sizeof(buf), templateString.c_str(), mouseX, mouseY);
cueRequest += std::string(buf);
socket << cueRequest;
@ -716,7 +728,10 @@ int main(int argc, char *argv[])
view->callback_pre_draw = [&](igl::opengl::glfw::Viewer& viewer) -> bool {
// Look for new data and redraw
// std::cout << "Waiting vars" << std::endl;
socket >> reply;
// std::cout << "Got vars: " << reply << std::endl;
std::vector<double> replyData = trickResponseConvert<double>(reply);
if (replyData.size() <= 1) {
@ -804,7 +819,7 @@ int main(int argc, char *argv[])
std::string positionRequest = "";
char * templateString = "trick.var_add(\"dyn.table.balls[%d][0].pos._x\")\ntrick.var_add(\"dyn.table.balls[%d][0].pos._y\")\ntrick.var_add(\"dyn.table.balls[%d][0].inPlay\")\n";
for (int i = 0; i < numBalls; i++) {
char buf[128];
char buf[2048];
snprintf(buf, sizeof(buf), templateString, i, i, i);
positionRequest += std::string(buf);
}

View File

@ -1572,6 +1572,7 @@ public class SimControlApplication extends TrickApplication implements PropertyC
@Override
protected void finished() {
try {
System.out.println("Finished with health status socket channel");
if (healthStatusSocketChannel != null) {
healthStatusSocketChannel.close() ;
}
@ -1606,7 +1607,11 @@ public class SimControlApplication extends TrickApplication implements PropertyC
if (statusSimcom != null) {
results = statusSimcom.get().split("\t");
String resultsStr = statusSimcom.get();
if (resultsStr == null)
break;
results = resultsStr.split("\t");
ii = 1 ;
// whenever there is data in statusSimcom socket, do something

View File

@ -295,7 +295,7 @@ public class SimControlActionController {
simcom.put("trick.debug_pause_off()\n" ) ;
}
} catch (IOException e) {
System.out.println("Put failed!");
System.out.println("Put failed! Exception: " + e.getMessage());
}
}

View File

@ -123,13 +123,15 @@ set( SS_SRC
JITInputFile/JITInputFile
JITInputFile/jit_input_file_c_intf
JSONVariableServer/JSONVariableServer
JSONVariableServer/JSONVariableServerThread
JSONVariableServer/JSONVariableServerSessionThread
MasterSlave/MSSharedMem
MasterSlave/MSSocket
MasterSlave/Master
MasterSlave/Slave
Message/MessageCout
Message/MessageFile
Message/MessageHSFile
Message/MessageCustomFile
Message/MessageLCout
Message/MessagePublisher
Message/MessageSubscriber
@ -190,32 +192,31 @@ set( SS_SRC
VariableServer/VariableReference
VariableServer/VariableServer
VariableServer/VariableServerListenThread
VariableServer/VariableServerThread
VariableServer/VariableServerThread_commands
VariableServer/VariableServerThread_connect
VariableServer/VariableServerThread_copy_data
VariableServer/VariableServerThread_copy_sim_data
VariableServer/VariableServerThread_create_socket
VariableServer/VariableServerThread_freeze_init
VariableServer/VariableServerThread_loop
VariableServer/VariableServerThread_restart
VariableServer/VariableServerThread_write_data
VariableServer/VariableServerThread_write_stdio
VariableServer/VariableServer_copy_data_freeze
VariableServer/VariableServer_copy_data_freeze_scheduled
VariableServer/VariableServer_copy_data_scheduled
VariableServer/VariableServer_copy_data_top
VariableServer/VariableServerSessionThread
VariableServer/VariableServerSessionThread_commands
VariableServer/VariableServerSessionThread_connect
VariableServer/VariableServerSessionThread_copy_data
VariableServer/VariableServerSessionThread_copy_sim_data
VariableServer/VariableServerSessionThread_create_socket
VariableServer/VariableServerSessionThread_freeze_init
VariableServer/VariableServerSessionThread_loop
VariableServer/VariableServerSessionThread_restart
VariableServer/VariableServerSessionThread_write_data
VariableServer/VariableServerSessionThread_write_stdio
VariableServer/VariableServer_copy_and_write_freeze
VariableServer/VariableServer_copy_and_write_freeze_scheduled
VariableServer/VariableServer_copy_and_write_scheduled
VariableServer/VariableServer_copy_and_write_top
VariableServer/VariableServer_default_data
VariableServer/VariableServer_freeze_init
VariableServer/VariableServer_get_next_freeze_call_time
VariableServer/VariableServer_get_next_sync_call_time
VariableServer/VariableServer_get_var_server_port
VariableServer/VariableServer_open_additional_servers
VariableServer/VariableServer_init
VariableServer/VariableServer_restart
VariableServer/VariableServer_shutdown
VariableServer/exit_var_thread
VariableServer/var_server_ext
VariableServer/vs_format_ascii
Zeroconf/Zeroconf
mains/master
)

View File

@ -114,3 +114,6 @@ std::string & command_line_args_get_input_file_ref(void) {
return(the_cmd_args->get_input_file_ref()) ;
}
void create_path(const char* directory) {
Trick::CommandLineArguments::create_path(directory);
}

View File

@ -133,8 +133,8 @@ object_${TRICK_HOST_CPU}/MTV.o: MTV.cpp ${TRICK_HOME}/include/trick/MTV.hh \
${TRICK_HOME}/include/trick/trick_byteswap.h \
${TRICK_HOME}/include/trick/trick_error_hndlr.h \
${TRICK_HOME}/include/trick/variable_server_sync_types.h \
${TRICK_HOME}/include/trick/VariableServerThread.hh \
${TRICK_HOME}/include/trick/VariableServerSessionThread.hh \
${TRICK_HOME}/include/trick/ThreadBase.hh \
${TRICK_HOME}/include/trick/VariableServerReference.hh \
${TRICK_HOME}/include/trick/VariableReference.hh \
${TRICK_HOME}/include/trick/VariableServerListenThread.hh \
${TRICK_HOME}/include/trick/EventManager_c_intf.hh

View File

@ -1,3 +1,5 @@
include $(dir $(lastword $(MAKEFILE_LIST)))../../../share/trick/makefiles/Makefile.common
include ${TRICK_HOME}/share/trick/makefiles/Makefile.tricklib
-include Makefile_deps
TRICK_CXXFLAGS += -std=c++11

View File

@ -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 \

View File

@ -0,0 +1,51 @@
#include <iostream>
#include <unistd.h>
#include "trick/MessageCustomFile.hh"
#include "trick/Message_proto.hh"
int Trick::MessageCustomFile::level_counter = 200;
/**
@details
-# Initializes everything
*/
Trick::MessageCustomFile::MessageCustomFile() : _this_level(level_counter++) {
}
/**
@details
-# If enabled and level is this file's level
-# Write the header and message to the file stream
-# Flush the stream
*/
void Trick::MessageCustomFile::update( unsigned int level , std::string header, std::string message ) {
if ( enabled && level == _this_level ) {
out_stream << header << message ;
out_stream.flush() ;
}
}
int Trick::MessageCustomFile::get_level() const {
return _this_level;
}
void Trick::MessageCustomFile::set_level(int level) {
if (level >= 0)
_this_level = level;
}
void Trick::MessageCustomFile::set_name(std::string name) {
if (name == "") {
name = "CustomLog" + std::to_string(_this_level);
}
this->name = name;
}
void Trick::MessageCustomFile::set_file_name(std::string file_name) {
this->file_name = file_name;
}

View File

@ -0,0 +1,59 @@
#include "trick/MessageCustomManager.hh"
#include "trick/Message_proto.hh"
#include "trick/memorymanager_c_intf.h"
Trick::MessageCustomManager * the_message_custom_manager ;
int open_custom_message_file(std::string file_name, std::string subscriber_name, int level) {
if (the_message_custom_manager == NULL) {
std::cout << "Problem: custom_message_manager not yet instantiated" << std::endl;
return -1;
}
return the_message_custom_manager->open_custom_message_file(file_name, subscriber_name, level);
}
/**
@brief The constructor.
*/
Trick::MessageCustomManager::MessageCustomManager() {
the_message_custom_manager = this;
}
Trick::MessageCustomManager::~MessageCustomManager() {
the_message_custom_manager = NULL;
for (Trick::MessageCustomFile * message_file : _custom_message_files) {
TMM_delete_var_a(message_file);
}
}
int Trick::MessageCustomManager::open_custom_message_file(std::string file_name, std::string subscriber_name, int level) {
Trick::MessageCustomFile * new_message_file = (Trick::MessageCustomFile *) TMM_declare_var_s("Trick::MessageCustomFile");
new_message_file->set_level(level);
new_message_file->set_file_name(file_name);
new_message_file->set_name(subscriber_name);
new_message_file->init();
_custom_message_files.push_back(new_message_file);
return new_message_file->get_level();
}
/**
@brief Output message to the file.
*/
void Trick::MessageCustomManager::update( unsigned int level , std::string header , std::string message ) {
for (auto message_file : _custom_message_files) {
message_file->update(level, header, message);
}
}
int Trick::MessageCustomManager::restart( ) {
for (auto message_file : _custom_message_files) {
message_file->restart();
}
return 0;
}

View File

@ -1,21 +1,22 @@
#include <iostream>
#include <unistd.h>
#include <string>
#include "trick/MessageFile.hh"
#include "trick/command_line_protos.h"
#include "trick/message_proto.h"
#include "trick/message_type.h"
/**
@details
-# Initializes everything
*/
Trick::MessageFile::MessageFile() {
enabled = 1 ;
color = 0 ;
file_name = "send_hs" ;
name = "file" ;
}
/**
@ -29,18 +30,6 @@ int Trick::MessageFile::set_file_name(std::string in_name) {
}
/**
@details
-# Deletes the current output file
-# Opens a new file with the name "file_name"
*/
int Trick::MessageFile::init() {
unlink((std::string(command_line_args_get_output_dir()) + "/" + file_name).c_str()) ;
out_stream.open((std::string(command_line_args_get_output_dir()) + "/" + file_name).c_str() , std::fstream::out | std::fstream::app ) ;
return(0) ;
}
/**
@details
-# If enabled and level < 100
@ -56,6 +45,34 @@ void Trick::MessageFile::update( unsigned int level , std::string header, std::s
}
/**
@details
-# Deletes the current output file
-# Opens a new file with the name "file_name"
*/
int Trick::MessageFile::init() {
unlink((std::string(command_line_args_get_output_dir()) + "/" + file_name).c_str()) ;
// Create the directory if we need to
int pos = file_name.find_last_of("/");
if (pos != std::string::npos) {
std::string dir = std::string(command_line_args_get_output_dir()) + "/" + file_name.substr(0, pos);
create_path(dir.c_str());
}
out_stream.open((std::string(command_line_args_get_output_dir()) + "/" + file_name).c_str() , std::fstream::out | std::fstream::app ) ;
if (!out_stream.is_open()) {
message_publish(MSG_ERROR, "Failed to open message file %s\n",file_name.c_str());
}
return(0) ;
}
int Trick::MessageFile::restart() {
out_stream.open((std::string(command_line_args_get_output_dir()) + "/" + file_name).c_str() , std::fstream::out | std::fstream::app ) ;
return(0) ;
}
/**
@details
-# Close the file stream

View File

@ -0,0 +1,32 @@
#include <iostream>
#include <unistd.h>
#include "trick/MessageHSFile.hh"
#include "trick/command_line_protos.h"
/**
@details
-# Initializes everything
*/
Trick::MessageHSFile::MessageHSFile() {
name = "file";
file_name = "send_hs";
}
/**
@details
-# If enabled and level < 100
-# Write the header and message to the file stream
-# Flush the stream
*/
void Trick::MessageHSFile::update( unsigned int level , std::string header, std::string message ) {
if ( enabled && level < 100 ) {
out_stream << header << message ;
out_stream.flush() ;
}
}

View File

@ -25,6 +25,10 @@ Trick::MessagePublisher::MessagePublisher() {
}
Trick::MessagePublisher::~MessagePublisher() {
the_message_publisher = NULL;
}
void Trick::MessagePublisher::set_print_format() {
num_digits = (int)round(log10((double)tics_per_sec)) ;
snprintf(print_format, sizeof(print_format), "|L %%3d|%%s|%%s|%%s|T %%d|%%lld.%%0%dlld| ", num_digits) ;

View File

@ -6,6 +6,7 @@
#include "trick/MessagePublisher.hh"
#include "trick/MessageCout.hh"
#include "trick/MessageFile.hh"
#include "trick/MessageCustomFile.hh"
#include "trick/MessageTCDevice.hh"
#include "trick/message_proto.h"

View File

@ -6,6 +6,7 @@
#include "trick/message_type.h"
#include "trick/tc_proto.h"
#include "trick/exec_proto.h"
#include "trick/SysThread.hh"
/** @par Detailed Design: */
void Trick::MonteCarlo::master_shutdown() {
@ -41,6 +42,8 @@ void Trick::MonteCarlo::master_shutdown() {
except_return = -2 ;
}
SysThread::ensureAllShutdown();
exit(except_return);
}

View File

@ -1,5 +1,7 @@
#include "trick/MonteCarlo.hh"
#include "trick/SysThread.hh"
/** @par Detailed Design: */
void Trick::MonteCarlo::slave_shutdown() {
@ -8,6 +10,8 @@ void Trick::MonteCarlo::slave_shutdown() {
/** <li> Run the shutdown jobs and exit. */
run_queue(&slave_shutdown_queue, "in slave_shutdown queue") ;
SysThread::ensureAllShutdown();
exit(0);
}
@ -15,6 +19,9 @@ void Trick::MonteCarlo::slave_shutdown() {
void Trick::MonteCarlo::slave_die() {
/** <ul><li> Kill any active child process executing a run and exit immediately. */
slave_kill_run();
SysThread::ensureAllShutdown();
exit(1);
}

View File

@ -9,7 +9,7 @@ include $(dir $(lastword $(MAKEFILE_LIST)))../../../../share/trick/makefiles/Mak
# Flags passed to the preprocessor.
TRICK_CXXFLAGS += -I$(GTEST_HOME)/include -I$(TRICK_HOME)/include -g -Wall -Wextra ${TRICK_TEST_FLAGS}
TRICK_LIBS = -L${TRICK_LIB_DIR} -ltrick -ltrick_pyip -ltrick_comm -ltrick_math -ltrick_mm -ltrick_units
TRICK_LIBS = -L${TRICK_LIB_DIR} -ltrick -ltrick_pyip -ltrick_comm -ltrick_math -ltrick_mm -ltrick_units -ltrick_var_binary_parser -ltrick_connection_handlers -ltrick_comm
TRICK_EXEC_LINK_LIBS += -L${GTEST_HOME}/lib64 -L${GTEST_HOME}/lib -lgtest -lgtest_main
# All tests produced by this Makefile. Remember to add new tests you

View File

@ -502,3 +502,6 @@ int Trick::RealtimeSync::shutdown() {
return(0) ;
}
bool Trick::RealtimeSync::is_active() {
return active;
}

View File

@ -59,7 +59,7 @@ extern "C" int real_time_restart(long long ref_time ) {
*/
extern "C" int is_real_time() {
if ( the_rts != NULL ) {
return((int)(the_rts->active)) ;
return((int)(the_rts->is_active())) ;
}
return(0) ;
}

View File

@ -9,6 +9,7 @@
#endif
#include <signal.h>
#include <algorithm>
#include <time.h>
#include "trick/SysThread.hh"
@ -30,7 +31,13 @@ std::vector<Trick::SysThread *>& Trick::SysThread::all_sys_threads() {
return all_sys_threads;
}
Trick::SysThread::SysThread(std::string in_name, bool sd) : self_deleting(sd), ThreadBase(in_name) {
Trick::SysThread::SysThread(std::string in_name) : ThreadBase(in_name) {
pthread_mutex_init(&_restart_pause_mutex, NULL);
pthread_cond_init(&_thread_has_paused_cv, NULL);
pthread_cond_init(&_thread_wakeup_cv, NULL);
_thread_has_paused = true;
_thread_should_pause = false;
pthread_mutex_lock(&(list_mutex()));
all_sys_threads().push_back(this);
pthread_mutex_unlock(&(list_mutex()));
@ -41,9 +48,6 @@ Trick::SysThread::~SysThread() {
pthread_mutex_lock(&(list_mutex()));
if (!shutdown_finished) {
all_sys_threads().erase(std::remove(all_sys_threads().begin(), all_sys_threads().end(), this), all_sys_threads().end());
if (all_sys_threads().size() == 0) {
pthread_cond_signal(&(list_empty_cv()));
}
}
pthread_mutex_unlock(&(list_mutex()));
}
@ -51,27 +55,58 @@ Trick::SysThread::~SysThread() {
int Trick::SysThread::ensureAllShutdown() {
pthread_mutex_lock(&(list_mutex()));
// Cancel all threads
for (SysThread * thread : all_sys_threads()) {
thread->cancel_thread();
}
auto it = all_sys_threads().begin();
while (it != all_sys_threads().end()){
SysThread * thread = *it;
if (!(thread->self_deleting)) {
thread->join_thread();
it = all_sys_threads().erase(it);
} else {
++it;
}
}
while (all_sys_threads().size() != 0) {
pthread_cond_wait(&(list_empty_cv()), &(list_mutex()));
// Join all threads
for (SysThread * thread : all_sys_threads()) {
thread->join_thread();
}
// Success!
shutdown_finished = true;
pthread_mutex_unlock(&(list_mutex()));
return 0;
}
// To be called from main thread
void Trick::SysThread::force_thread_to_pause() {
pthread_mutex_lock(&_restart_pause_mutex);
// Tell thread to pause, and wait for it to signal that it has
_thread_should_pause = true;
while (!_thread_has_paused) {
pthread_cond_wait(&_thread_has_paused_cv, &_restart_pause_mutex);
}
pthread_mutex_unlock(&_restart_pause_mutex);
}
// To be called from main thread
void Trick::SysThread::unpause_thread() {
pthread_mutex_lock(&_restart_pause_mutex);
// Tell thread to wake up
_thread_should_pause = false;
pthread_cond_signal(&_thread_wakeup_cv);
pthread_mutex_unlock(&_restart_pause_mutex);
}
// To be called from this thread
void Trick::SysThread::test_pause() {
pthread_mutex_lock(&_restart_pause_mutex) ;
if (_thread_should_pause) {
// Tell main thread that we're pausing
_thread_has_paused = true;
pthread_cond_signal(&_thread_has_paused_cv);
// Wait until we're told to wake up
while (_thread_should_pause) {
pthread_cond_wait(&_thread_wakeup_cv, &_restart_pause_mutex);
}
}
_thread_has_paused = false;
pthread_mutex_unlock(&_restart_pause_mutex) ;
}

View File

@ -17,8 +17,12 @@ Trick::ThreadBase::ThreadBase(std::string in_name) :
name(in_name) ,
pthread_id(0) ,
pid(0) ,
rt_priority(0)
rt_priority(0),
created(false),
should_shutdown(false),
cancellable(true)
{
pthread_mutex_init(&shutdown_mutex, NULL);
#if __linux
max_cpu = sysconf( _SC_NPROCESSORS_ONLN ) ;
#ifdef CPU_ALLOC
@ -274,11 +278,17 @@ int Trick::ThreadBase::execute_priority() {
int Trick::ThreadBase::create_thread() {
if (created) {
message_publish(MSG_ERROR, "create_thread called on thread %s (%p) which has already been started.\n", name.c_str(), this);
return 0;
}
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
pthread_create(&pthread_id, &attr, Trick::ThreadBase::thread_helper , (void *)this);
created = true;
#if __linux
#ifdef __GNUC__
@ -294,19 +304,56 @@ int Trick::ThreadBase::create_thread() {
}
int Trick::ThreadBase::cancel_thread() {
pthread_mutex_lock(&shutdown_mutex);
should_shutdown = true;
pthread_mutex_unlock(&shutdown_mutex);
if ( pthread_id != 0 ) {
pthread_cancel(pthread_id) ;
if (cancellable)
pthread_cancel(pthread_id) ;
}
return(0) ;
}
int Trick::ThreadBase::join_thread() {
if ( pthread_id != 0 ) {
pthread_join(pthread_id, NULL) ;
if ((errno = pthread_join(pthread_id, NULL)) != 0) {
std::string msg = "Thread " + name + " had an error in join";
perror(msg.c_str());
} else {
pthread_id = 0;
}
}
return(0) ;
}
void Trick::ThreadBase::test_shutdown() {
test_shutdown (NULL, NULL);
}
void Trick::ThreadBase::test_shutdown(void (*exit_handler) (void *), void * exit_arg) {
pthread_mutex_lock(&shutdown_mutex);
if (should_shutdown) {
pthread_mutex_unlock(&shutdown_mutex);
thread_shutdown(exit_handler, exit_arg);
}
pthread_mutex_unlock(&shutdown_mutex);
}
void Trick::ThreadBase::thread_shutdown() {
thread_shutdown (NULL, NULL);
}
void Trick::ThreadBase::thread_shutdown(void (*exit_handler) (void *), void * exit_arg) {
if (exit_handler != NULL) {
exit_handler(exit_arg);
}
pthread_exit(0);
}
void * Trick::ThreadBase::thread_helper( void * context ) {
sigset_t sigs;

View File

@ -1,4 +1,4 @@
object_${TRICK_HOST_CPU}/VariableServerThread_loop.o: VariableServerThread_loop.cpp \
object_${TRICK_HOST_CPU}/VariableServerSessionThread_loop.o: VariableServerSessionThread_loop.cpp \
${TRICK_HOME}/include/trick/VariableServer.hh \
${TRICK_HOME}/include/trick/tc.h \
${TRICK_HOME}/include/trick/trick_error_hndlr.h \
@ -10,9 +10,10 @@ object_${TRICK_HOST_CPU}/VariableServerThread_loop.o: VariableServerThread_loop.
${TRICK_HOME}/include/trick/JobData.hh \
${TRICK_HOME}/include/trick/InstrumentBase.hh \
${TRICK_HOME}/include/trick/variable_server_sync_types.h \
${TRICK_HOME}/include/trick/VariableServerThread.hh \
${TRICK_HOME}/include/trick/VariableServerSessionThread.hh \
${TRICK_HOME}/include/trick/ThreadBase.hh \
${TRICK_HOME}/include/trick/VariableServerReference.hh \
${TRICK_HOME}/include/trick/VariableReference.hh \
${TRICK_HOME}/include/trick/VariableServerSession.hh \
${TRICK_HOME}/include/trick/VariableServerListenThread.hh \
${TRICK_HOME}/include/trick/input_processor_proto.h \
${TRICK_HOME}/include/trick/tc_proto.h \
@ -24,8 +25,8 @@ object_${TRICK_HOST_CPU}/VariableServerThread_loop.o: VariableServerThread_loop.
${TRICK_HOME}/include/trick/ExecutiveException.hh \
${TRICK_HOME}/include/trick/exec_proto.h \
${TRICK_HOME}/include/trick/sim_mode.h
object_${TRICK_HOST_CPU}/VariableServer_copy_data_scheduled.o: \
VariableServer_copy_data_scheduled.cpp \
object_${TRICK_HOST_CPU}/VariableServer_copy_and_write_scheduled.o: \
VariableServer_copy_and_write_scheduled.cpp \
${TRICK_HOME}/include/trick/VariableServer.hh \
${TRICK_HOME}/include/trick/tc.h \
${TRICK_HOME}/include/trick/trick_error_hndlr.h \
@ -37,9 +38,10 @@ object_${TRICK_HOST_CPU}/VariableServer_copy_data_scheduled.o: \
${TRICK_HOME}/include/trick/JobData.hh \
${TRICK_HOME}/include/trick/InstrumentBase.hh \
${TRICK_HOME}/include/trick/variable_server_sync_types.h \
${TRICK_HOME}/include/trick/VariableServerThread.hh \
${TRICK_HOME}/include/trick/VariableServerSessionThread.hh \
${TRICK_HOME}/include/trick/ThreadBase.hh \
${TRICK_HOME}/include/trick/VariableServerReference.hh \
${TRICK_HOME}/include/trick/VariableReference.hh \
${TRICK_HOME}/include/trick/VariableServerSession.hh \
${TRICK_HOME}/include/trick/VariableServerListenThread.hh \
${TRICK_HOME}/include/trick/TrickConstant.hh
object_${TRICK_HOST_CPU}/VariableServer_shutdown.o: VariableServer_shutdown.cpp \
@ -54,12 +56,13 @@ object_${TRICK_HOST_CPU}/VariableServer_shutdown.o: VariableServer_shutdown.cpp
${TRICK_HOME}/include/trick/JobData.hh \
${TRICK_HOME}/include/trick/InstrumentBase.hh \
${TRICK_HOME}/include/trick/variable_server_sync_types.h \
${TRICK_HOME}/include/trick/VariableServerThread.hh \
${TRICK_HOME}/include/trick/VariableServerSessionThread.hh \
${TRICK_HOME}/include/trick/ThreadBase.hh \
${TRICK_HOME}/include/trick/VariableServerReference.hh \
${TRICK_HOME}/include/trick/VariableReference.hh \
${TRICK_HOME}/include/trick/VariableServerSession.hh \
${TRICK_HOME}/include/trick/VariableServerListenThread.hh
object_${TRICK_HOST_CPU}/VariableServer_copy_data_freeze_scheduled.o: \
VariableServer_copy_data_freeze_scheduled.cpp \
object_${TRICK_HOST_CPU}/VariableServer_copy_and_write_freeze_scheduled.o: \
VariableServer_copy_and_write_freeze_scheduled.cpp \
${TRICK_HOME}/include/trick/VariableServer.hh \
${TRICK_HOME}/include/trick/tc.h \
${TRICK_HOME}/include/trick/trick_error_hndlr.h \
@ -71,12 +74,13 @@ object_${TRICK_HOST_CPU}/VariableServer_copy_data_freeze_scheduled.o: \
${TRICK_HOME}/include/trick/JobData.hh \
${TRICK_HOME}/include/trick/InstrumentBase.hh \
${TRICK_HOME}/include/trick/variable_server_sync_types.h \
${TRICK_HOME}/include/trick/VariableServerThread.hh \
${TRICK_HOME}/include/trick/VariableServerSessionThread.hh \
${TRICK_HOME}/include/trick/ThreadBase.hh \
${TRICK_HOME}/include/trick/VariableServerReference.hh \
${TRICK_HOME}/include/trick/VariableReference.hh \
${TRICK_HOME}/include/trick/VariableServerSession.hh \
${TRICK_HOME}/include/trick/VariableServerListenThread.hh \
${TRICK_HOME}/include/trick/TrickConstant.hh
object_${TRICK_HOST_CPU}/VariableReference.o: VariableReference.cpp \
object_${TRICK_HOST_CPU}/VariableReference.o: \
${TRICK_HOME}/include/trick/VariableServer.hh \
${TRICK_HOME}/include/trick/tc.h \
${TRICK_HOME}/include/trick/trick_error_hndlr.h \
@ -88,9 +92,10 @@ object_${TRICK_HOST_CPU}/VariableReference.o: VariableReference.cpp \
${TRICK_HOME}/include/trick/JobData.hh \
${TRICK_HOME}/include/trick/InstrumentBase.hh \
${TRICK_HOME}/include/trick/variable_server_sync_types.h \
${TRICK_HOME}/include/trick/VariableServerThread.hh \
${TRICK_HOME}/include/trick/VariableServerSessionThread.hh \
${TRICK_HOME}/include/trick/ThreadBase.hh \
${TRICK_HOME}/include/trick/VariableServerReference.hh \
${TRICK_HOME}/include/trick/VariableReference.hh \
${TRICK_HOME}/include/trick/VariableServerSession.hh \
${TRICK_HOME}/include/trick/VariableServerListenThread.hh \
${TRICK_HOME}/include/trick/memorymanager_c_intf.h \
${TRICK_HOME}/include/trick/var.h \
@ -111,12 +116,13 @@ object_${TRICK_HOST_CPU}/VariableServer_get_next_freeze_call_time.o: \
${TRICK_HOME}/include/trick/JobData.hh \
${TRICK_HOME}/include/trick/InstrumentBase.hh \
${TRICK_HOME}/include/trick/variable_server_sync_types.h \
${TRICK_HOME}/include/trick/VariableServerThread.hh \
${TRICK_HOME}/include/trick/VariableServerSessionThread.hh \
${TRICK_HOME}/include/trick/ThreadBase.hh \
${TRICK_HOME}/include/trick/VariableServerReference.hh \
${TRICK_HOME}/include/trick/VariableReference.hh \
${TRICK_HOME}/include/trick/VariableServerSession.hh \
${TRICK_HOME}/include/trick/VariableServerListenThread.hh \
${TRICK_HOME}/include/trick/TrickConstant.hh
object_${TRICK_HOST_CPU}/VariableServerThread_write_stdio.o: VariableServerThread_write_stdio.cpp \
object_${TRICK_HOST_CPU}/VariableServerSessionThread_write_stdio.o: VariableServerSessionThread_write_stdio.cpp \
${TRICK_HOME}/include/trick/VariableServer.hh \
${TRICK_HOME}/include/trick/tc.h \
${TRICK_HOME}/include/trick/trick_error_hndlr.h \
@ -128,9 +134,10 @@ object_${TRICK_HOST_CPU}/VariableServerThread_write_stdio.o: VariableServerThrea
${TRICK_HOME}/include/trick/JobData.hh \
${TRICK_HOME}/include/trick/InstrumentBase.hh \
${TRICK_HOME}/include/trick/variable_server_sync_types.h \
${TRICK_HOME}/include/trick/VariableServerThread.hh \
${TRICK_HOME}/include/trick/VariableServerSessionThread.hh \
${TRICK_HOME}/include/trick/ThreadBase.hh \
${TRICK_HOME}/include/trick/VariableServerReference.hh \
${TRICK_HOME}/include/trick/VariableReference.hh \
${TRICK_HOME}/include/trick/VariableServerSession.hh \
${TRICK_HOME}/include/trick/VariableServerListenThread.hh \
${TRICK_HOME}/include/trick/variable_server_message_types.h \
${TRICK_HOME}/include/trick/tc_proto.h
@ -147,9 +154,10 @@ object_${TRICK_HOST_CPU}/VariableServer_get_next_sync_call_time.o: \
${TRICK_HOME}/include/trick/JobData.hh \
${TRICK_HOME}/include/trick/InstrumentBase.hh \
${TRICK_HOME}/include/trick/variable_server_sync_types.h \
${TRICK_HOME}/include/trick/VariableServerThread.hh \
${TRICK_HOME}/include/trick/VariableServerSessionThread.hh \
${TRICK_HOME}/include/trick/ThreadBase.hh \
${TRICK_HOME}/include/trick/VariableServerReference.hh \
${TRICK_HOME}/include/trick/VariableReference.hh \
${TRICK_HOME}/include/trick/VariableServerSession.hh \
${TRICK_HOME}/include/trick/VariableServerListenThread.hh \
${TRICK_HOME}/include/trick/TrickConstant.hh
object_${TRICK_HOST_CPU}/VariableServer_restart.o: VariableServer_restart.cpp \
@ -164,9 +172,10 @@ object_${TRICK_HOST_CPU}/VariableServer_restart.o: VariableServer_restart.cpp \
${TRICK_HOME}/include/trick/JobData.hh \
${TRICK_HOME}/include/trick/InstrumentBase.hh \
${TRICK_HOME}/include/trick/variable_server_sync_types.h \
${TRICK_HOME}/include/trick/VariableServerThread.hh \
${TRICK_HOME}/include/trick/VariableServerSessionThread.hh \
${TRICK_HOME}/include/trick/ThreadBase.hh \
${TRICK_HOME}/include/trick/VariableServerReference.hh \
${TRICK_HOME}/include/trick/VariableReference.hh \
${TRICK_HOME}/include/trick/VariableServerSession.hh \
${TRICK_HOME}/include/trick/VariableServerListenThread.hh \
${TRICK_HOME}/include/trick/message_proto.h \
${TRICK_HOME}/include/trick/message_type.h \
@ -183,9 +192,10 @@ object_${TRICK_HOST_CPU}/var_server_ext.o: var_server_ext.cpp \
${TRICK_HOME}/include/trick/JobData.hh \
${TRICK_HOME}/include/trick/InstrumentBase.hh \
${TRICK_HOME}/include/trick/variable_server_sync_types.h \
${TRICK_HOME}/include/trick/VariableServerThread.hh \
${TRICK_HOME}/include/trick/VariableServerSessionThread.hh \
${TRICK_HOME}/include/trick/ThreadBase.hh \
${TRICK_HOME}/include/trick/VariableServerReference.hh \
${TRICK_HOME}/include/trick/VariableReference.hh \
${TRICK_HOME}/include/trick/VariableServerSession.hh \
${TRICK_HOME}/include/trick/VariableServerListenThread.hh \
${TRICK_HOME}/include/trick/exec_proto.h \
${TRICK_HOME}/include/trick/sim_mode.h \
@ -194,13 +204,14 @@ object_${TRICK_HOST_CPU}/var_server_ext.o: var_server_ext.cpp \
${TRICK_HOME}/include/trick/memorymanager_c_intf.h \
${TRICK_HOME}/include/trick/var.h \
${TRICK_HOME}/include/trick/io_alloc.h
object_${TRICK_HOST_CPU}/VariableServerThread_create_socket.o: \
VariableServerThread_create_socket.cpp \
${TRICK_HOME}/include/trick/VariableServerThread.hh \
object_${TRICK_HOST_CPU}/VariableServerSessionThread_create_socket.o: \
VariableServerSessionThread_create_socket.cpp \
${TRICK_HOME}/include/trick/VariableServerSessionThread.hh \
${TRICK_HOME}/include/trick/tc.h \
${TRICK_HOME}/include/trick/trick_error_hndlr.h \
${TRICK_HOME}/include/trick/ThreadBase.hh \
${TRICK_HOME}/include/trick/VariableServerReference.hh \
${TRICK_HOME}/include/trick/VariableReference.hh \
${TRICK_HOME}/include/trick/VariableServerSession.hh \
${TRICK_HOME}/include/trick/reference.h \
${TRICK_HOME}/include/trick/attributes.h \
${TRICK_HOME}/include/trick/parameter_types.h \
@ -215,8 +226,9 @@ object_${TRICK_HOST_CPU}/VariableServerListenThread.o: VariableServerListenThrea
${TRICK_HOME}/include/trick/tc.h \
${TRICK_HOME}/include/trick/trick_error_hndlr.h \
${TRICK_HOME}/include/trick/ThreadBase.hh \
${TRICK_HOME}/include/trick/VariableServerThread.hh \
${TRICK_HOME}/include/trick/VariableServerReference.hh \
${TRICK_HOME}/include/trick/VariableServerSessionThread.hh \
${TRICK_HOME}/include/trick/VariableReference.hh \
${TRICK_HOME}/include/trick/VariableServerSession.hh \
${TRICK_HOME}/include/trick/reference.h \
${TRICK_HOME}/include/trick/attributes.h \
${TRICK_HOME}/include/trick/parameter_types.h \
@ -229,7 +241,7 @@ object_${TRICK_HOST_CPU}/VariableServerListenThread.o: VariableServerListenThrea
${TRICK_HOME}/include/trick/command_line_protos.h \
${TRICK_HOME}/include/trick/message_proto.h \
${TRICK_HOME}/include/trick/message_type.h
object_${TRICK_HOST_CPU}/VariableServerThread_write_data.o: VariableServerThread_write_data.cpp \
object_${TRICK_HOST_CPU}/VariableServerSessionThread_write_data.o: VariableServerSessionThread_write_data.cpp \
${TRICK_HOME}/include/trick/VariableServer.hh \
${TRICK_HOME}/include/trick/tc.h \
${TRICK_HOME}/include/trick/trick_error_hndlr.h \
@ -241,9 +253,10 @@ object_${TRICK_HOST_CPU}/VariableServerThread_write_data.o: VariableServerThread
${TRICK_HOME}/include/trick/JobData.hh \
${TRICK_HOME}/include/trick/InstrumentBase.hh \
${TRICK_HOME}/include/trick/variable_server_sync_types.h \
${TRICK_HOME}/include/trick/VariableServerThread.hh \
${TRICK_HOME}/include/trick/VariableServerSessionThread.hh \
${TRICK_HOME}/include/trick/ThreadBase.hh \
${TRICK_HOME}/include/trick/VariableServerReference.hh \
${TRICK_HOME}/include/trick/VariableReference.hh \
${TRICK_HOME}/include/trick/VariableServerSession.hh \
${TRICK_HOME}/include/trick/VariableServerListenThread.hh \
${TRICK_HOME}/include/trick/variable_server_message_types.h \
${TRICK_HOME}/include/trick/bitfield_proto.h \
@ -263,9 +276,10 @@ object_${TRICK_HOST_CPU}/VariableServer_init.o: VariableServer_init.cpp \
${TRICK_HOME}/include/trick/JobData.hh \
${TRICK_HOME}/include/trick/InstrumentBase.hh \
${TRICK_HOME}/include/trick/variable_server_sync_types.h \
${TRICK_HOME}/include/trick/VariableServerThread.hh \
${TRICK_HOME}/include/trick/VariableServerSessionThread.hh \
${TRICK_HOME}/include/trick/ThreadBase.hh \
${TRICK_HOME}/include/trick/VariableServerReference.hh \
${TRICK_HOME}/include/trick/VariableReference.hh \
${TRICK_HOME}/include/trick/VariableServerSession.hh \
${TRICK_HOME}/include/trick/VariableServerListenThread.hh \
${TRICK_HOME}/include/trick/exec_proto.hh \
${TRICK_HOME}/include/trick/Executive.hh \
@ -277,7 +291,7 @@ object_${TRICK_HOST_CPU}/VariableServer_init.o: VariableServer_init.cpp \
${TRICK_HOME}/include/trick/Threads.hh \
${TRICK_HOME}/include/trick/ThreadTrigger.hh \
${TRICK_HOME}/include/trick/sim_mode.h
object_${TRICK_HOST_CPU}/VariableServer_copy_data_freeze.o: VariableServer_copy_data_freeze.cpp \
object_${TRICK_HOST_CPU}/VariableServer_copy_and_write_freeze.o: VariableServer_copy_and_write_freeze.cpp \
${TRICK_HOME}/include/trick/VariableServer.hh \
${TRICK_HOME}/include/trick/tc.h \
${TRICK_HOME}/include/trick/trick_error_hndlr.h \
@ -289,9 +303,10 @@ object_${TRICK_HOST_CPU}/VariableServer_copy_data_freeze.o: VariableServer_copy_
${TRICK_HOME}/include/trick/JobData.hh \
${TRICK_HOME}/include/trick/InstrumentBase.hh \
${TRICK_HOME}/include/trick/variable_server_sync_types.h \
${TRICK_HOME}/include/trick/VariableServerThread.hh \
${TRICK_HOME}/include/trick/VariableServerSessionThread.hh \
${TRICK_HOME}/include/trick/ThreadBase.hh \
${TRICK_HOME}/include/trick/VariableServerReference.hh \
${TRICK_HOME}/include/trick/VariableReference.hh \
${TRICK_HOME}/include/trick/VariableServerSession.hh \
${TRICK_HOME}/include/trick/VariableServerListenThread.hh
object_${TRICK_HOST_CPU}/VariableServer_default_data.o: VariableServer_default_data.cpp \
${TRICK_HOME}/include/trick/VariableServer.hh \
@ -305,9 +320,10 @@ object_${TRICK_HOST_CPU}/VariableServer_default_data.o: VariableServer_default_d
${TRICK_HOME}/include/trick/JobData.hh \
${TRICK_HOME}/include/trick/InstrumentBase.hh \
${TRICK_HOME}/include/trick/variable_server_sync_types.h \
${TRICK_HOME}/include/trick/VariableServerThread.hh \
${TRICK_HOME}/include/trick/VariableServerSessionThread.hh \
${TRICK_HOME}/include/trick/ThreadBase.hh \
${TRICK_HOME}/include/trick/VariableServerReference.hh \
${TRICK_HOME}/include/trick/VariableReference.hh \
${TRICK_HOME}/include/trick/VariableServerSession.hh \
${TRICK_HOME}/include/trick/VariableServerListenThread.hh
object_${TRICK_HOST_CPU}/VariableServer_freeze_init.o: VariableServer_freeze_init.cpp \
${TRICK_HOME}/include/trick/VariableServer.hh \
@ -321,9 +337,10 @@ object_${TRICK_HOST_CPU}/VariableServer_freeze_init.o: VariableServer_freeze_ini
${TRICK_HOME}/include/trick/JobData.hh \
${TRICK_HOME}/include/trick/InstrumentBase.hh \
${TRICK_HOME}/include/trick/variable_server_sync_types.h \
${TRICK_HOME}/include/trick/VariableServerThread.hh \
${TRICK_HOME}/include/trick/VariableServerSessionThread.hh \
${TRICK_HOME}/include/trick/ThreadBase.hh \
${TRICK_HOME}/include/trick/VariableServerReference.hh \
${TRICK_HOME}/include/trick/VariableReference.hh \
${TRICK_HOME}/include/trick/VariableServerSession.hh \
${TRICK_HOME}/include/trick/VariableServerListenThread.hh \
${TRICK_HOME}/include/trick/variable_server_proto.h \
${TRICK_HOME}/include/trick/TrickConstant.hh
@ -339,43 +356,26 @@ object_${TRICK_HOST_CPU}/VariableServer.o: VariableServer.cpp \
${TRICK_HOME}/include/trick/JobData.hh \
${TRICK_HOME}/include/trick/InstrumentBase.hh \
${TRICK_HOME}/include/trick/variable_server_sync_types.h \
${TRICK_HOME}/include/trick/VariableServerThread.hh \
${TRICK_HOME}/include/trick/VariableServerSessionThread.hh \
${TRICK_HOME}/include/trick/ThreadBase.hh \
${TRICK_HOME}/include/trick/VariableServerReference.hh \
${TRICK_HOME}/include/trick/VariableReference.hh \
${TRICK_HOME}/include/trick/VariableServerSession.hh \
${TRICK_HOME}/include/trick/VariableServerListenThread.hh \
${TRICK_HOME}/include/trick/tc_proto.h
object_${TRICK_HOST_CPU}/vs_format_ascii.o: vs_format_ascii.cpp \
${TRICK_HOME}/include/trick/parameter_types.h \
${TRICK_HOME}/include/trick/attributes.h \
${TRICK_HOME}/include/trick/bitfield_proto.h \
${TRICK_HOME}/include/trick/wcs_ext.h \
${TRICK_HOME}/include/trick/VariableServer.hh \
${TRICK_HOME}/include/trick/tc.h \
${TRICK_HOME}/include/trick/trick_error_hndlr.h \
${TRICK_HOME}/include/trick/reference.h \
${TRICK_HOME}/include/trick/value.h \
${TRICK_HOME}/include/trick/dllist.h \
${TRICK_HOME}/include/trick/JobData.hh \
${TRICK_HOME}/include/trick/InstrumentBase.hh \
${TRICK_HOME}/include/trick/variable_server_sync_types.h \
${TRICK_HOME}/include/trick/VariableServerThread.hh \
${TRICK_HOME}/include/trick/ThreadBase.hh \
${TRICK_HOME}/include/trick/VariableServerReference.hh \
${TRICK_HOME}/include/trick/VariableServerListenThread.hh \
${TRICK_HOME}/include/trick/TrickConstant.hh
object_${TRICK_HOST_CPU}/VariableServerThread_restart.o: VariableServerThread_restart.cpp \
${TRICK_HOME}/include/trick/VariableServerThread.hh \
object_${TRICK_HOST_CPU}/VariableServerSessionThread_restart.o: VariableServerSessionThread_restart.cpp \
${TRICK_HOME}/include/trick/VariableServerSessionThread.hh \
${TRICK_HOME}/include/trick/tc.h \
${TRICK_HOME}/include/trick/trick_error_hndlr.h \
${TRICK_HOME}/include/trick/ThreadBase.hh \
${TRICK_HOME}/include/trick/VariableServerReference.hh \
${TRICK_HOME}/include/trick/VariableReference.hh \
${TRICK_HOME}/include/trick/VariableServerSession.hh \
${TRICK_HOME}/include/trick/reference.h \
${TRICK_HOME}/include/trick/attributes.h \
${TRICK_HOME}/include/trick/parameter_types.h \
${TRICK_HOME}/include/trick/value.h \
${TRICK_HOME}/include/trick/dllist.h \
${TRICK_HOME}/include/trick/variable_server_sync_types.h
object_${TRICK_HOST_CPU}/VariableServer_copy_data_top.o: VariableServer_copy_data_top.cpp \
object_${TRICK_HOST_CPU}/VariableServer_copy_and_write_top.o: VariableServer_copy_and_write_top.cpp \
${TRICK_HOME}/include/trick/VariableServer.hh \
${TRICK_HOME}/include/trick/tc.h \
${TRICK_HOME}/include/trick/trick_error_hndlr.h \
@ -387,9 +387,10 @@ object_${TRICK_HOST_CPU}/VariableServer_copy_data_top.o: VariableServer_copy_dat
${TRICK_HOME}/include/trick/JobData.hh \
${TRICK_HOME}/include/trick/InstrumentBase.hh \
${TRICK_HOME}/include/trick/variable_server_sync_types.h \
${TRICK_HOME}/include/trick/VariableServerThread.hh \
${TRICK_HOME}/include/trick/VariableServerSessionThread.hh \
${TRICK_HOME}/include/trick/ThreadBase.hh \
${TRICK_HOME}/include/trick/VariableServerReference.hh \
${TRICK_HOME}/include/trick/VariableReference.hh \
${TRICK_HOME}/include/trick/VariableServerSession.hh \
${TRICK_HOME}/include/trick/VariableServerListenThread.hh
object_${TRICK_HOST_CPU}/exit_var_thread.o: exit_var_thread.cpp \
${TRICK_HOME}/include/trick/VariableServer.hh \
@ -403,12 +404,13 @@ object_${TRICK_HOST_CPU}/exit_var_thread.o: exit_var_thread.cpp \
${TRICK_HOME}/include/trick/JobData.hh \
${TRICK_HOME}/include/trick/InstrumentBase.hh \
${TRICK_HOME}/include/trick/variable_server_sync_types.h \
${TRICK_HOME}/include/trick/VariableServerThread.hh \
${TRICK_HOME}/include/trick/VariableServerSessionThread.hh \
${TRICK_HOME}/include/trick/ThreadBase.hh \
${TRICK_HOME}/include/trick/VariableServerReference.hh \
${TRICK_HOME}/include/trick/VariableReference.hh \
${TRICK_HOME}/include/trick/VariableServerSession.hh \
${TRICK_HOME}/include/trick/VariableServerListenThread.hh \
${TRICK_HOME}/include/trick/tc_proto.h
object_${TRICK_HOST_CPU}/VariableServerThread_copy_data.o: VariableServerThread_copy_data.cpp \
object_${TRICK_HOST_CPU}/VariableServerSessionThread_copy_data.o: VariableServerSessionThread_copy_data.cpp \
${TRICK_HOME}/include/trick/VariableServer.hh \
${TRICK_HOME}/include/trick/tc.h \
${TRICK_HOME}/include/trick/trick_error_hndlr.h \
@ -420,16 +422,17 @@ object_${TRICK_HOST_CPU}/VariableServerThread_copy_data.o: VariableServerThread_
${TRICK_HOME}/include/trick/JobData.hh \
${TRICK_HOME}/include/trick/InstrumentBase.hh \
${TRICK_HOME}/include/trick/variable_server_sync_types.h \
${TRICK_HOME}/include/trick/VariableServerThread.hh \
${TRICK_HOME}/include/trick/VariableServerSessionThread.hh \
${TRICK_HOME}/include/trick/ThreadBase.hh \
${TRICK_HOME}/include/trick/VariableServerReference.hh \
${TRICK_HOME}/include/trick/VariableReference.hh \
${TRICK_HOME}/include/trick/VariableServerSession.hh \
${TRICK_HOME}/include/trick/VariableServerListenThread.hh \
${TRICK_HOME}/include/trick/exec_proto.h \
${TRICK_HOME}/include/trick/sim_mode.h \
${TRICK_HOME}/include/trick/realtimesync_proto.h \
${TRICK_HOME}/include/trick/Clock.hh \
${TRICK_HOME}/include/trick/Timer.hh
object_${TRICK_HOST_CPU}/VariableServerThread_connect.o: VariableServerThread_connect.cpp \
object_${TRICK_HOST_CPU}/VariableServerSessionThread_connect.o: VariableServerSessionThread_connect.cpp \
${TRICK_HOME}/include/trick/VariableServer.hh \
${TRICK_HOME}/include/trick/tc.h \
${TRICK_HOME}/include/trick/trick_error_hndlr.h \
@ -441,13 +444,14 @@ object_${TRICK_HOST_CPU}/VariableServerThread_connect.o: VariableServerThread_co
${TRICK_HOME}/include/trick/JobData.hh \
${TRICK_HOME}/include/trick/InstrumentBase.hh \
${TRICK_HOME}/include/trick/variable_server_sync_types.h \
${TRICK_HOME}/include/trick/VariableServerThread.hh \
${TRICK_HOME}/include/trick/VariableServerSessionThread.hh \
${TRICK_HOME}/include/trick/ThreadBase.hh \
${TRICK_HOME}/include/trick/VariableServerReference.hh \
${TRICK_HOME}/include/trick/VariableReference.hh \
${TRICK_HOME}/include/trick/VariableServerSession.hh \
${TRICK_HOME}/include/trick/VariableServerListenThread.hh \
${TRICK_HOME}/include/trick/release.h
object_${TRICK_HOST_CPU}/VariableServerThread_copy_sim_data.o: \
VariableServerThread_copy_sim_data.cpp \
object_${TRICK_HOST_CPU}/VariableServerSessionThread_copy_sim_data.o: \
VariableServerSessionThread_copy_sim_data.cpp \
${TRICK_HOME}/include/trick/VariableServer.hh \
${TRICK_HOME}/include/trick/tc.h \
${TRICK_HOME}/include/trick/trick_error_hndlr.h \
@ -459,21 +463,23 @@ object_${TRICK_HOST_CPU}/VariableServerThread_copy_sim_data.o: \
${TRICK_HOME}/include/trick/JobData.hh \
${TRICK_HOME}/include/trick/InstrumentBase.hh \
${TRICK_HOME}/include/trick/variable_server_sync_types.h \
${TRICK_HOME}/include/trick/VariableServerThread.hh \
${TRICK_HOME}/include/trick/VariableServerSessionThread.hh \
${TRICK_HOME}/include/trick/ThreadBase.hh \
${TRICK_HOME}/include/trick/VariableServerReference.hh \
${TRICK_HOME}/include/trick/VariableReference.hh \
${TRICK_HOME}/include/trick/VariableServerSession.hh \
${TRICK_HOME}/include/trick/VariableServerListenThread.hh \
${TRICK_HOME}/include/trick/memorymanager_c_intf.h \
${TRICK_HOME}/include/trick/var.h \
${TRICK_HOME}/include/trick/io_alloc.h \
${TRICK_HOME}/include/trick/exec_proto.h \
${TRICK_HOME}/include/trick/sim_mode.h
object_${TRICK_HOST_CPU}/VariableServerThread_freeze_init.o: VariableServerThread_freeze_init.cpp \
${TRICK_HOME}/include/trick/VariableServerThread.hh \
object_${TRICK_HOST_CPU}/VariableServerSession_freeze_init.o: VariableServerSession_freeze_init.cpp \
${TRICK_HOME}/include/trick/VariableServerSession.hh \
${TRICK_HOME}/include/trick/tc.h \
${TRICK_HOME}/include/trick/trick_error_hndlr.h \
${TRICK_HOME}/include/trick/ThreadBase.hh \
${TRICK_HOME}/include/trick/VariableServerReference.hh \
${TRICK_HOME}/include/trick/VariableReference.hh \
${TRICK_HOME}/include/trick/VariableServerSession.hh \
${TRICK_HOME}/include/trick/reference.h \
${TRICK_HOME}/include/trick/attributes.h \
${TRICK_HOME}/include/trick/parameter_types.h \
@ -481,8 +487,8 @@ object_${TRICK_HOST_CPU}/VariableServerThread_freeze_init.o: VariableServerThrea
${TRICK_HOME}/include/trick/dllist.h \
${TRICK_HOME}/include/trick/variable_server_sync_types.h \
${TRICK_HOME}/include/trick/TrickConstant.hh
object_${TRICK_HOST_CPU}/VariableServer_get_var_server_port.o: \
VariableServer_get_var_server_port.cpp \
object_${TRICK_HOST_CPU}/VariableServer_open_additional_servers.o: \
VariableServer_open_additional_servers.cpp \
${TRICK_HOME}/include/trick/VariableServer.hh \
${TRICK_HOME}/include/trick/tc.h \
${TRICK_HOME}/include/trick/trick_error_hndlr.h \
@ -494,16 +500,18 @@ object_${TRICK_HOST_CPU}/VariableServer_get_var_server_port.o: \
${TRICK_HOME}/include/trick/JobData.hh \
${TRICK_HOME}/include/trick/InstrumentBase.hh \
${TRICK_HOME}/include/trick/variable_server_sync_types.h \
${TRICK_HOME}/include/trick/VariableServerThread.hh \
${TRICK_HOME}/include/trick/VariableServerSessionThread.hh \
${TRICK_HOME}/include/trick/ThreadBase.hh \
${TRICK_HOME}/include/trick/VariableServerReference.hh \
${TRICK_HOME}/include/trick/VariableReference.hh \
${TRICK_HOME}/include/trick/VariableServerSession.hh \
${TRICK_HOME}/include/trick/VariableServerListenThread.hh
object_${TRICK_HOST_CPU}/VariableServerThread.o: VariableServerThread.cpp \
${TRICK_HOME}/include/trick/VariableServerThread.hh \
object_${TRICK_HOST_CPU}/VariableServerSessionThread.o: VariableServerSessionThread.cpp \
${TRICK_HOME}/include/trick/VariableServerSessionThread.hh \
${TRICK_HOME}/include/trick/tc.h \
${TRICK_HOME}/include/trick/trick_error_hndlr.h \
${TRICK_HOME}/include/trick/ThreadBase.hh \
${TRICK_HOME}/include/trick/VariableServerReference.hh \
${TRICK_HOME}/include/trick/VariableReference.hh \
${TRICK_HOME}/include/trick/VariableServerSession.hh \
${TRICK_HOME}/include/trick/reference.h \
${TRICK_HOME}/include/trick/attributes.h \
${TRICK_HOME}/include/trick/parameter_types.h \
@ -513,7 +521,7 @@ object_${TRICK_HOST_CPU}/VariableServerThread.o: VariableServerThread.cpp \
${TRICK_HOME}/include/trick/exec_proto.h \
${TRICK_HOME}/include/trick/sim_mode.h \
${TRICK_HOME}/include/trick/TrickConstant.hh
object_${TRICK_HOST_CPU}/VariableServerThread_loop.o: VariableServerThread_loop.cpp \
object_${TRICK_HOST_CPU}/VariableServerSessionThread_loop.o: VariableServerSessionThread_loop.cpp \
${TRICK_HOME}/include/trick/VariableServer.hh \
${TRICK_HOME}/include/trick/tc.h \
${TRICK_HOME}/include/trick/trick_error_hndlr.h \
@ -525,9 +533,10 @@ object_${TRICK_HOST_CPU}/VariableServerThread_loop.o: VariableServerThread_loop.
${TRICK_HOME}/include/trick/JobData.hh \
${TRICK_HOME}/include/trick/InstrumentBase.hh \
${TRICK_HOME}/include/trick/variable_server_sync_types.h \
${TRICK_HOME}/include/trick/VariableServerThread.hh \
${TRICK_HOME}/include/trick/VariableServerSessionThread.hh \
${TRICK_HOME}/include/trick/ThreadBase.hh \
${TRICK_HOME}/include/trick/VariableServerReference.hh \
${TRICK_HOME}/include/trick/VariableReference.hh \
${TRICK_HOME}/include/trick/VariableServerSession.hh \
${TRICK_HOME}/include/trick/VariableServerListenThread.hh \
${TRICK_HOME}/include/trick/input_processor_proto.h \
${TRICK_HOME}/include/trick/tc_proto.h \
@ -539,8 +548,8 @@ object_${TRICK_HOST_CPU}/VariableServerThread_loop.o: VariableServerThread_loop.
${TRICK_HOME}/include/trick/ExecutiveException.hh \
${TRICK_HOME}/include/trick/exec_proto.h \
${TRICK_HOME}/include/trick/sim_mode.h
object_${TRICK_HOST_CPU}/VariableServer_copy_data_scheduled.o: \
VariableServer_copy_data_scheduled.cpp \
object_${TRICK_HOST_CPU}/VariableServer_copy_and_write_scheduled.o: \
VariableServer_copy_and_write_scheduled.cpp \
${TRICK_HOME}/include/trick/VariableServer.hh \
${TRICK_HOME}/include/trick/tc.h \
${TRICK_HOME}/include/trick/trick_error_hndlr.h \
@ -552,9 +561,10 @@ object_${TRICK_HOST_CPU}/VariableServer_copy_data_scheduled.o: \
${TRICK_HOME}/include/trick/JobData.hh \
${TRICK_HOME}/include/trick/InstrumentBase.hh \
${TRICK_HOME}/include/trick/variable_server_sync_types.h \
${TRICK_HOME}/include/trick/VariableServerThread.hh \
${TRICK_HOME}/include/trick/VariableServerSessionThread.hh \
${TRICK_HOME}/include/trick/ThreadBase.hh \
${TRICK_HOME}/include/trick/VariableServerReference.hh \
${TRICK_HOME}/include/trick/VariableReference.hh \
${TRICK_HOME}/include/trick/VariableServerSession.hh \
${TRICK_HOME}/include/trick/VariableServerListenThread.hh \
${TRICK_HOME}/include/trick/TrickConstant.hh
object_${TRICK_HOST_CPU}/VariableServer_shutdown.o: VariableServer_shutdown.cpp \
@ -569,12 +579,13 @@ object_${TRICK_HOST_CPU}/VariableServer_shutdown.o: VariableServer_shutdown.cpp
${TRICK_HOME}/include/trick/JobData.hh \
${TRICK_HOME}/include/trick/InstrumentBase.hh \
${TRICK_HOME}/include/trick/variable_server_sync_types.h \
${TRICK_HOME}/include/trick/VariableServerThread.hh \
${TRICK_HOME}/include/trick/VariableServerSessionThread.hh \
${TRICK_HOME}/include/trick/ThreadBase.hh \
${TRICK_HOME}/include/trick/VariableServerReference.hh \
${TRICK_HOME}/include/trick/VariableReference.hh \
${TRICK_HOME}/include/trick/VariableServerSession.hh \
${TRICK_HOME}/include/trick/VariableServerListenThread.hh
object_${TRICK_HOST_CPU}/VariableServer_copy_data_freeze_scheduled.o: \
VariableServer_copy_data_freeze_scheduled.cpp \
object_${TRICK_HOST_CPU}/VariableServer_copy_and_write_freeze_scheduled.o: \
VariableServer_copy_and_write_freeze_scheduled.cpp \
${TRICK_HOME}/include/trick/VariableServer.hh \
${TRICK_HOME}/include/trick/tc.h \
${TRICK_HOME}/include/trick/trick_error_hndlr.h \
@ -586,12 +597,15 @@ object_${TRICK_HOST_CPU}/VariableServer_copy_data_freeze_scheduled.o: \
${TRICK_HOME}/include/trick/JobData.hh \
${TRICK_HOME}/include/trick/InstrumentBase.hh \
${TRICK_HOME}/include/trick/variable_server_sync_types.h \
${TRICK_HOME}/include/trick/VariableServerThread.hh \
${TRICK_HOME}/include/trick/VariableServerSessionThread.hh \
${TRICK_HOME}/include/trick/ThreadBase.hh \
${TRICK_HOME}/include/trick/VariableServerReference.hh \
${TRICK_HOME}/include/trick/VariableReference.hh \
${TRICK_HOME}/include/trick/VariableServerSession.hh \
${TRICK_HOME}/include/trick/VariableServerListenThread.hh \
${TRICK_HOME}/include/trick/TrickConstant.hh
object_${TRICK_HOST_CPU}/VariableReference.o: VariableReference.cpp \
object_${TRICK_HOST_CPU}/VariableReference.o: \
VariableReference.cpp \
${TRICK_HOME}/include/trick/VariableServerSession.hh \
${TRICK_HOME}/include/trick/VariableServer.hh \
${TRICK_HOME}/include/trick/tc.h \
${TRICK_HOME}/include/trick/trick_error_hndlr.h \
@ -603,9 +617,10 @@ object_${TRICK_HOST_CPU}/VariableReference.o: VariableReference.cpp \
${TRICK_HOME}/include/trick/JobData.hh \
${TRICK_HOME}/include/trick/InstrumentBase.hh \
${TRICK_HOME}/include/trick/variable_server_sync_types.h \
${TRICK_HOME}/include/trick/VariableServerThread.hh \
${TRICK_HOME}/include/trick/VariableServerSessionThread.hh \
${TRICK_HOME}/include/trick/ThreadBase.hh \
${TRICK_HOME}/include/trick/VariableServerReference.hh \
${TRICK_HOME}/include/trick/VariableReference.hh \
${TRICK_HOME}/include/trick/VariableServerSession.hh \
${TRICK_HOME}/include/trick/VariableServerListenThread.hh \
${TRICK_HOME}/include/trick/memorymanager_c_intf.h \
${TRICK_HOME}/include/trick/var.h \
@ -613,7 +628,7 @@ object_${TRICK_HOST_CPU}/VariableReference.o: VariableReference.cpp \
${TRICK_HOME}/include/trick/wcs_ext.h \
${TRICK_HOME}/include/trick/message_proto.h \
${TRICK_HOME}/include/trick/message_type.h
object_${TRICK_HOST_CPU}/VariableServerThread_write_stdio.o: VariableServerThread_write_stdio.cpp \
object_${TRICK_HOST_CPU}/VariableServerSessionThread_write_stdio.o: VariableServerSessionThread_write_stdio.cpp \
${TRICK_HOME}/include/trick/VariableServer.hh \
${TRICK_HOME}/include/trick/tc.h \
${TRICK_HOME}/include/trick/trick_error_hndlr.h \
@ -625,13 +640,14 @@ object_${TRICK_HOST_CPU}/VariableServerThread_write_stdio.o: VariableServerThrea
${TRICK_HOME}/include/trick/JobData.hh \
${TRICK_HOME}/include/trick/InstrumentBase.hh \
${TRICK_HOME}/include/trick/variable_server_sync_types.h \
${TRICK_HOME}/include/trick/VariableServerThread.hh \
${TRICK_HOME}/include/trick/VariableServerSessionThread.hh \
${TRICK_HOME}/include/trick/ThreadBase.hh \
${TRICK_HOME}/include/trick/VariableServerReference.hh \
${TRICK_HOME}/include/trick/VariableReference.hh \
${TRICK_HOME}/include/trick/VariableServerSession.hh \
${TRICK_HOME}/include/trick/VariableServerListenThread.hh \
${TRICK_HOME}/include/trick/variable_server_message_types.h \
${TRICK_HOME}/include/trick/tc_proto.h
object_${TRICK_HOST_CPU}/VariableServerThread_commands.o: VariableServerThread_commands.cpp \
object_${TRICK_HOST_CPU}/VariableServerSessionThread_commands.o: VariableServerSessionThread_commands.cpp \
${TRICK_HOME}/include/trick/VariableServer.hh \
${TRICK_HOME}/include/trick/tc.h \
${TRICK_HOME}/include/trick/trick_error_hndlr.h \
@ -643,9 +659,10 @@ object_${TRICK_HOST_CPU}/VariableServerThread_commands.o: VariableServerThread_c
${TRICK_HOME}/include/trick/JobData.hh \
${TRICK_HOME}/include/trick/InstrumentBase.hh \
${TRICK_HOME}/include/trick/variable_server_sync_types.h \
${TRICK_HOME}/include/trick/VariableServerThread.hh \
${TRICK_HOME}/include/trick/VariableServerSessionThread.hh \
${TRICK_HOME}/include/trick/ThreadBase.hh \
${TRICK_HOME}/include/trick/VariableServerReference.hh \
${TRICK_HOME}/include/trick/VariableReference.hh \
${TRICK_HOME}/include/trick/VariableServerSession.hh \
${TRICK_HOME}/include/trick/VariableServerListenThread.hh \
${TRICK_HOME}/include/trick/variable_server_message_types.h \
${TRICK_HOME}/include/trick/memorymanager_c_intf.h \
@ -674,9 +691,10 @@ object_${TRICK_HOST_CPU}/VariableServer_get_next_sync_call_time.o: \
${TRICK_HOME}/include/trick/JobData.hh \
${TRICK_HOME}/include/trick/InstrumentBase.hh \
${TRICK_HOME}/include/trick/variable_server_sync_types.h \
${TRICK_HOME}/include/trick/VariableServerThread.hh \
${TRICK_HOME}/include/trick/VariableServerSessionThread.hh \
${TRICK_HOME}/include/trick/ThreadBase.hh \
${TRICK_HOME}/include/trick/VariableServerReference.hh \
${TRICK_HOME}/include/trick/VariableReference.hh \
${TRICK_HOME}/include/trick/VariableServerSession.hh \
${TRICK_HOME}/include/trick/VariableServerListenThread.hh \
${TRICK_HOME}/include/trick/TrickConstant.hh
object_${TRICK_HOST_CPU}/VariableServer_restart.o: VariableServer_restart.cpp \
@ -691,9 +709,10 @@ object_${TRICK_HOST_CPU}/VariableServer_restart.o: VariableServer_restart.cpp \
${TRICK_HOME}/include/trick/JobData.hh \
${TRICK_HOME}/include/trick/InstrumentBase.hh \
${TRICK_HOME}/include/trick/variable_server_sync_types.h \
${TRICK_HOME}/include/trick/VariableServerThread.hh \
${TRICK_HOME}/include/trick/VariableServerSessionThread.hh \
${TRICK_HOME}/include/trick/ThreadBase.hh \
${TRICK_HOME}/include/trick/VariableServerReference.hh \
${TRICK_HOME}/include/trick/VariableReference.hh \
${TRICK_HOME}/include/trick/VariableServerSession.hh \
${TRICK_HOME}/include/trick/VariableServerListenThread.hh \
${TRICK_HOME}/include/trick/message_proto.h \
${TRICK_HOME}/include/trick/message_type.h \
@ -710,9 +729,10 @@ object_${TRICK_HOST_CPU}/var_server_ext.o: var_server_ext.cpp \
${TRICK_HOME}/include/trick/JobData.hh \
${TRICK_HOME}/include/trick/InstrumentBase.hh \
${TRICK_HOME}/include/trick/variable_server_sync_types.h \
${TRICK_HOME}/include/trick/VariableServerThread.hh \
${TRICK_HOME}/include/trick/VariableServerSessionThread.hh \
${TRICK_HOME}/include/trick/ThreadBase.hh \
${TRICK_HOME}/include/trick/VariableServerReference.hh \
${TRICK_HOME}/include/trick/VariableReference.hh \
${TRICK_HOME}/include/trick/VariableServerSession.hh \
${TRICK_HOME}/include/trick/VariableServerListenThread.hh \
${TRICK_HOME}/include/trick/exec_proto.h \
${TRICK_HOME}/include/trick/sim_mode.h \
@ -721,13 +741,14 @@ object_${TRICK_HOST_CPU}/var_server_ext.o: var_server_ext.cpp \
${TRICK_HOME}/include/trick/memorymanager_c_intf.h \
${TRICK_HOME}/include/trick/var.h \
${TRICK_HOME}/include/trick/io_alloc.h
object_${TRICK_HOST_CPU}/VariableServerThread_create_socket.o: \
VariableServerThread_create_socket.cpp \
${TRICK_HOME}/include/trick/VariableServerThread.hh \
object_${TRICK_HOST_CPU}/VariableServerSessionThread_create_socket.o: \
VariableServerSessionThread_create_socket.cpp \
${TRICK_HOME}/include/trick/VariableServerSessionThread.hh \
${TRICK_HOME}/include/trick/tc.h \
${TRICK_HOME}/include/trick/trick_error_hndlr.h \
${TRICK_HOME}/include/trick/ThreadBase.hh \
${TRICK_HOME}/include/trick/VariableServerReference.hh \
${TRICK_HOME}/include/trick/VariableReference.hh \
${TRICK_HOME}/include/trick/VariableServerSession.hh \
${TRICK_HOME}/include/trick/reference.h \
${TRICK_HOME}/include/trick/attributes.h \
${TRICK_HOME}/include/trick/parameter_types.h \
@ -741,9 +762,12 @@ object_${TRICK_HOST_CPU}/VariableServerListenThread.o: VariableServerListenThrea
${TRICK_HOME}/include/trick/VariableServerListenThread.hh \
${TRICK_HOME}/include/trick/tc.h \
${TRICK_HOME}/include/trick/trick_error_hndlr.h \
${TRICK_HOME}/include/trick/TCPClientListener.hh \
${TRICK_HOME}/include/trick/MulticastGroup.hh \
${TRICK_HOME}/include/trick/ThreadBase.hh \
${TRICK_HOME}/include/trick/VariableServerThread.hh \
${TRICK_HOME}/include/trick/VariableServerReference.hh \
${TRICK_HOME}/include/trick/VariableServerSessionThread.hh \
${TRICK_HOME}/include/trick/VariableReference.hh \
${TRICK_HOME}/include/trick/VariableServerSession.hh \
${TRICK_HOME}/include/trick/reference.h \
${TRICK_HOME}/include/trick/attributes.h \
${TRICK_HOME}/include/trick/parameter_types.h \
@ -756,7 +780,7 @@ object_${TRICK_HOST_CPU}/VariableServerListenThread.o: VariableServerListenThrea
${TRICK_HOME}/include/trick/command_line_protos.h \
${TRICK_HOME}/include/trick/message_proto.h \
${TRICK_HOME}/include/trick/message_type.h
object_${TRICK_HOST_CPU}/VariableServerThread_write_data.o: VariableServerThread_write_data.cpp \
object_${TRICK_HOST_CPU}/VariableServerSessionThread_write_data.o: VariableServerSessionThread_write_data.cpp \
${TRICK_HOME}/include/trick/VariableServer.hh \
${TRICK_HOME}/include/trick/tc.h \
${TRICK_HOME}/include/trick/trick_error_hndlr.h \
@ -768,9 +792,10 @@ object_${TRICK_HOST_CPU}/VariableServerThread_write_data.o: VariableServerThread
${TRICK_HOME}/include/trick/JobData.hh \
${TRICK_HOME}/include/trick/InstrumentBase.hh \
${TRICK_HOME}/include/trick/variable_server_sync_types.h \
${TRICK_HOME}/include/trick/VariableServerThread.hh \
${TRICK_HOME}/include/trick/VariableServerSessionThread.hh \
${TRICK_HOME}/include/trick/ThreadBase.hh \
${TRICK_HOME}/include/trick/VariableServerReference.hh \
${TRICK_HOME}/include/trick/VariableReference.hh \
${TRICK_HOME}/include/trick/VariableServerSession.hh \
${TRICK_HOME}/include/trick/VariableServerListenThread.hh \
${TRICK_HOME}/include/trick/variable_server_message_types.h \
${TRICK_HOME}/include/trick/bitfield_proto.h \
@ -790,9 +815,10 @@ object_${TRICK_HOST_CPU}/VariableServer_init.o: VariableServer_init.cpp \
${TRICK_HOME}/include/trick/JobData.hh \
${TRICK_HOME}/include/trick/InstrumentBase.hh \
${TRICK_HOME}/include/trick/variable_server_sync_types.h \
${TRICK_HOME}/include/trick/VariableServerThread.hh \
${TRICK_HOME}/include/trick/VariableServerSessionThread.hh \
${TRICK_HOME}/include/trick/ThreadBase.hh \
${TRICK_HOME}/include/trick/VariableServerReference.hh \
${TRICK_HOME}/include/trick/VariableReference.hh \
${TRICK_HOME}/include/trick/VariableServerSession.hh \
${TRICK_HOME}/include/trick/VariableServerListenThread.hh \
${TRICK_HOME}/include/trick/exec_proto.hh \
${TRICK_HOME}/include/trick/Executive.hh \
@ -804,7 +830,7 @@ object_${TRICK_HOST_CPU}/VariableServer_init.o: VariableServer_init.cpp \
${TRICK_HOME}/include/trick/Threads.hh \
${TRICK_HOME}/include/trick/ThreadTrigger.hh \
${TRICK_HOME}/include/trick/sim_mode.h
object_${TRICK_HOST_CPU}/VariableServer_copy_data_freeze.o: VariableServer_copy_data_freeze.cpp \
object_${TRICK_HOST_CPU}/VariableServer_copy_and_write_freeze.o: VariableServer_copy_and_write_freeze.cpp \
${TRICK_HOME}/include/trick/VariableServer.hh \
${TRICK_HOME}/include/trick/tc.h \
${TRICK_HOME}/include/trick/trick_error_hndlr.h \
@ -816,9 +842,10 @@ object_${TRICK_HOST_CPU}/VariableServer_copy_data_freeze.o: VariableServer_copy_
${TRICK_HOME}/include/trick/JobData.hh \
${TRICK_HOME}/include/trick/InstrumentBase.hh \
${TRICK_HOME}/include/trick/variable_server_sync_types.h \
${TRICK_HOME}/include/trick/VariableServerThread.hh \
${TRICK_HOME}/include/trick/VariableServerSessionThread.hh \
${TRICK_HOME}/include/trick/ThreadBase.hh \
${TRICK_HOME}/include/trick/VariableServerReference.hh \
${TRICK_HOME}/include/trick/VariableReference.hh \
${TRICK_HOME}/include/trick/VariableServerSession.hh \
${TRICK_HOME}/include/trick/VariableServerListenThread.hh
object_${TRICK_HOST_CPU}/VariableServer_default_data.o: VariableServer_default_data.cpp \
${TRICK_HOME}/include/trick/VariableServer.hh \
@ -832,9 +859,10 @@ object_${TRICK_HOST_CPU}/VariableServer_default_data.o: VariableServer_default_d
${TRICK_HOME}/include/trick/JobData.hh \
${TRICK_HOME}/include/trick/InstrumentBase.hh \
${TRICK_HOME}/include/trick/variable_server_sync_types.h \
${TRICK_HOME}/include/trick/VariableServerThread.hh \
${TRICK_HOME}/include/trick/VariableServerSessionThread.hh \
${TRICK_HOME}/include/trick/ThreadBase.hh \
${TRICK_HOME}/include/trick/VariableServerReference.hh \
${TRICK_HOME}/include/trick/VariableReference.hh \
${TRICK_HOME}/include/trick/VariableServerSession.hh \
${TRICK_HOME}/include/trick/VariableServerListenThread.hh
object_${TRICK_HOST_CPU}/VariableServer_freeze_init.o: VariableServer_freeze_init.cpp \
${TRICK_HOME}/include/trick/VariableServer.hh \
@ -848,9 +876,10 @@ object_${TRICK_HOST_CPU}/VariableServer_freeze_init.o: VariableServer_freeze_ini
${TRICK_HOME}/include/trick/JobData.hh \
${TRICK_HOME}/include/trick/InstrumentBase.hh \
${TRICK_HOME}/include/trick/variable_server_sync_types.h \
${TRICK_HOME}/include/trick/VariableServerThread.hh \
${TRICK_HOME}/include/trick/VariableServerSessionThread.hh \
${TRICK_HOME}/include/trick/ThreadBase.hh \
${TRICK_HOME}/include/trick/VariableServerReference.hh \
${TRICK_HOME}/include/trick/VariableReference.hh \
${TRICK_HOME}/include/trick/VariableServerSession.hh \
${TRICK_HOME}/include/trick/VariableServerListenThread.hh \
${TRICK_HOME}/include/trick/variable_server_proto.h \
${TRICK_HOME}/include/trick/TrickConstant.hh
@ -866,43 +895,26 @@ object_${TRICK_HOST_CPU}/VariableServer.o: VariableServer.cpp \
${TRICK_HOME}/include/trick/JobData.hh \
${TRICK_HOME}/include/trick/InstrumentBase.hh \
${TRICK_HOME}/include/trick/variable_server_sync_types.h \
${TRICK_HOME}/include/trick/VariableServerThread.hh \
${TRICK_HOME}/include/trick/VariableServerSessionThread.hh \
${TRICK_HOME}/include/trick/ThreadBase.hh \
${TRICK_HOME}/include/trick/VariableServerReference.hh \
${TRICK_HOME}/include/trick/VariableReference.hh \
${TRICK_HOME}/include/trick/VariableServerSession.hh \
${TRICK_HOME}/include/trick/VariableServerListenThread.hh \
${TRICK_HOME}/include/trick/tc_proto.h
object_${TRICK_HOST_CPU}/vs_format_ascii.o: vs_format_ascii.cpp \
${TRICK_HOME}/include/trick/parameter_types.h \
${TRICK_HOME}/include/trick/attributes.h \
${TRICK_HOME}/include/trick/bitfield_proto.h \
${TRICK_HOME}/include/trick/wcs_ext.h \
${TRICK_HOME}/include/trick/VariableServer.hh \
${TRICK_HOME}/include/trick/tc.h \
${TRICK_HOME}/include/trick/trick_error_hndlr.h \
${TRICK_HOME}/include/trick/reference.h \
${TRICK_HOME}/include/trick/value.h \
${TRICK_HOME}/include/trick/dllist.h \
${TRICK_HOME}/include/trick/JobData.hh \
${TRICK_HOME}/include/trick/InstrumentBase.hh \
${TRICK_HOME}/include/trick/variable_server_sync_types.h \
${TRICK_HOME}/include/trick/VariableServerThread.hh \
${TRICK_HOME}/include/trick/ThreadBase.hh \
${TRICK_HOME}/include/trick/VariableServerReference.hh \
${TRICK_HOME}/include/trick/VariableServerListenThread.hh \
${TRICK_HOME}/include/trick/TrickConstant.hh
object_${TRICK_HOST_CPU}/VariableServerThread_restart.o: VariableServerThread_restart.cpp \
${TRICK_HOME}/include/trick/VariableServerThread.hh \
object_${TRICK_HOST_CPU}/VariableServerSessionThread_restart.o: VariableServerSessionThread_restart.cpp \
${TRICK_HOME}/include/trick/VariableServerSessionThread.hh \
${TRICK_HOME}/include/trick/tc.h \
${TRICK_HOME}/include/trick/trick_error_hndlr.h \
${TRICK_HOME}/include/trick/ThreadBase.hh \
${TRICK_HOME}/include/trick/VariableServerReference.hh \
${TRICK_HOME}/include/trick/VariableReference.hh \
${TRICK_HOME}/include/trick/VariableServerSession.hh \
${TRICK_HOME}/include/trick/reference.h \
${TRICK_HOME}/include/trick/attributes.h \
${TRICK_HOME}/include/trick/parameter_types.h \
${TRICK_HOME}/include/trick/value.h \
${TRICK_HOME}/include/trick/dllist.h \
${TRICK_HOME}/include/trick/variable_server_sync_types.h
object_${TRICK_HOST_CPU}/VariableServer_copy_data_top.o: VariableServer_copy_data_top.cpp \
object_${TRICK_HOST_CPU}/VariableServer_copy_and_write_top.o: VariableServer_copy_and_write_top.cpp \
${TRICK_HOME}/include/trick/VariableServer.hh \
${TRICK_HOME}/include/trick/tc.h \
${TRICK_HOME}/include/trick/trick_error_hndlr.h \
@ -914,9 +926,10 @@ object_${TRICK_HOST_CPU}/VariableServer_copy_data_top.o: VariableServer_copy_dat
${TRICK_HOME}/include/trick/JobData.hh \
${TRICK_HOME}/include/trick/InstrumentBase.hh \
${TRICK_HOME}/include/trick/variable_server_sync_types.h \
${TRICK_HOME}/include/trick/VariableServerThread.hh \
${TRICK_HOME}/include/trick/VariableServerSessionThread.hh \
${TRICK_HOME}/include/trick/ThreadBase.hh \
${TRICK_HOME}/include/trick/VariableServerReference.hh \
${TRICK_HOME}/include/trick/VariableReference.hh \
${TRICK_HOME}/include/trick/VariableServerSession.hh \
${TRICK_HOME}/include/trick/VariableServerListenThread.hh
object_${TRICK_HOST_CPU}/exit_var_thread.o: exit_var_thread.cpp \
${TRICK_HOME}/include/trick/VariableServer.hh \
@ -930,12 +943,13 @@ object_${TRICK_HOST_CPU}/exit_var_thread.o: exit_var_thread.cpp \
${TRICK_HOME}/include/trick/JobData.hh \
${TRICK_HOME}/include/trick/InstrumentBase.hh \
${TRICK_HOME}/include/trick/variable_server_sync_types.h \
${TRICK_HOME}/include/trick/VariableServerThread.hh \
${TRICK_HOME}/include/trick/VariableServerSessionThread.hh \
${TRICK_HOME}/include/trick/ThreadBase.hh \
${TRICK_HOME}/include/trick/VariableServerReference.hh \
${TRICK_HOME}/include/trick/VariableReference.hh \
${TRICK_HOME}/include/trick/VariableServerSession.hh \
${TRICK_HOME}/include/trick/VariableServerListenThread.hh \
${TRICK_HOME}/include/trick/tc_proto.h
object_${TRICK_HOST_CPU}/VariableServerThread_copy_data.o: VariableServerThread_copy_data.cpp \
object_${TRICK_HOST_CPU}/VariableServerSessionThread_copy_data.o: VariableServerSessionThread_copy_data.cpp \
${TRICK_HOME}/include/trick/VariableServer.hh \
${TRICK_HOME}/include/trick/tc.h \
${TRICK_HOME}/include/trick/trick_error_hndlr.h \
@ -947,9 +961,10 @@ object_${TRICK_HOST_CPU}/VariableServerThread_copy_data.o: VariableServerThread_
${TRICK_HOME}/include/trick/JobData.hh \
${TRICK_HOME}/include/trick/InstrumentBase.hh \
${TRICK_HOME}/include/trick/variable_server_sync_types.h \
${TRICK_HOME}/include/trick/VariableServerThread.hh \
${TRICK_HOME}/include/trick/VariableServerSessionThread.hh \
${TRICK_HOME}/include/trick/ThreadBase.hh \
${TRICK_HOME}/include/trick/VariableServerReference.hh \
${TRICK_HOME}/include/trick/VariableReference.hh \
${TRICK_HOME}/include/trick/VariableServerSession.hh \
${TRICK_HOME}/include/trick/VariableServerListenThread.hh \
${TRICK_HOME}/include/trick/exec_proto.h \
${TRICK_HOME}/include/trick/sim_mode.h \
@ -969,12 +984,13 @@ object_${TRICK_HOST_CPU}/VariableServer_get_next_freeze_call_time.o: \
${TRICK_HOME}/include/trick/JobData.hh \
${TRICK_HOME}/include/trick/InstrumentBase.hh \
${TRICK_HOME}/include/trick/variable_server_sync_types.h \
${TRICK_HOME}/include/trick/VariableServerThread.hh \
${TRICK_HOME}/include/trick/VariableServerSessionThread.hh \
${TRICK_HOME}/include/trick/ThreadBase.hh \
${TRICK_HOME}/include/trick/VariableServerReference.hh \
${TRICK_HOME}/include/trick/VariableReference.hh \
${TRICK_HOME}/include/trick/VariableServerSession.hh \
${TRICK_HOME}/include/trick/VariableServerListenThread.hh \
${TRICK_HOME}/include/trick/TrickConstant.hh
object_${TRICK_HOST_CPU}/VariableServerThread_connect.o: VariableServerThread_connect.cpp \
object_${TRICK_HOST_CPU}/VariableServerSessionThread_connect.o: VariableServerSessionThread_connect.cpp \
${TRICK_HOME}/include/trick/VariableServer.hh \
${TRICK_HOME}/include/trick/tc.h \
${TRICK_HOME}/include/trick/trick_error_hndlr.h \
@ -986,13 +1002,14 @@ object_${TRICK_HOST_CPU}/VariableServerThread_connect.o: VariableServerThread_co
${TRICK_HOME}/include/trick/JobData.hh \
${TRICK_HOME}/include/trick/InstrumentBase.hh \
${TRICK_HOME}/include/trick/variable_server_sync_types.h \
${TRICK_HOME}/include/trick/VariableServerThread.hh \
${TRICK_HOME}/include/trick/VariableServerSessionThread.hh \
${TRICK_HOME}/include/trick/ThreadBase.hh \
${TRICK_HOME}/include/trick/VariableServerReference.hh \
${TRICK_HOME}/include/trick/VariableReference.hh \
${TRICK_HOME}/include/trick/VariableServerSession.hh \
${TRICK_HOME}/include/trick/VariableServerListenThread.hh \
${TRICK_HOME}/include/trick/release.h
object_${TRICK_HOST_CPU}/VariableServerThread_copy_sim_data.o: \
VariableServerThread_copy_sim_data.cpp \
object_${TRICK_HOST_CPU}/VariableServerSessionThread_copy_sim_data.o: \
VariableServerSessionThread_copy_sim_data.cpp \
${TRICK_HOME}/include/trick/VariableServer.hh \
${TRICK_HOME}/include/trick/tc.h \
${TRICK_HOME}/include/trick/trick_error_hndlr.h \
@ -1004,21 +1021,23 @@ object_${TRICK_HOST_CPU}/VariableServerThread_copy_sim_data.o: \
${TRICK_HOME}/include/trick/JobData.hh \
${TRICK_HOME}/include/trick/InstrumentBase.hh \
${TRICK_HOME}/include/trick/variable_server_sync_types.h \
${TRICK_HOME}/include/trick/VariableServerThread.hh \
${TRICK_HOME}/include/trick/VariableServerSessionThread.hh \
${TRICK_HOME}/include/trick/ThreadBase.hh \
${TRICK_HOME}/include/trick/VariableServerReference.hh \
${TRICK_HOME}/include/trick/VariableReference.hh \
${TRICK_HOME}/include/trick/VariableServerSession.hh \
${TRICK_HOME}/include/trick/VariableServerListenThread.hh \
${TRICK_HOME}/include/trick/memorymanager_c_intf.h \
${TRICK_HOME}/include/trick/var.h \
${TRICK_HOME}/include/trick/io_alloc.h \
${TRICK_HOME}/include/trick/exec_proto.h \
${TRICK_HOME}/include/trick/sim_mode.h
object_${TRICK_HOST_CPU}/VariableServerThread_freeze_init.o: VariableServerThread_freeze_init.cpp \
${TRICK_HOME}/include/trick/VariableServerThread.hh \
object_${TRICK_HOST_CPU}/VariableServerSessionThread_freeze_init.o: VariableServerSessionThread_freeze_init.cpp \
${TRICK_HOME}/include/trick/VariableServerSessionThread.hh \
${TRICK_HOME}/include/trick/tc.h \
${TRICK_HOME}/include/trick/trick_error_hndlr.h \
${TRICK_HOME}/include/trick/ThreadBase.hh \
${TRICK_HOME}/include/trick/VariableServerReference.hh \
${TRICK_HOME}/include/trick/VariableReference.hh \
${TRICK_HOME}/include/trick/VariableServerSession.hh \
${TRICK_HOME}/include/trick/reference.h \
${TRICK_HOME}/include/trick/attributes.h \
${TRICK_HOME}/include/trick/parameter_types.h \
@ -1026,8 +1045,8 @@ object_${TRICK_HOST_CPU}/VariableServerThread_freeze_init.o: VariableServerThrea
${TRICK_HOME}/include/trick/dllist.h \
${TRICK_HOME}/include/trick/variable_server_sync_types.h \
${TRICK_HOME}/include/trick/TrickConstant.hh
object_${TRICK_HOST_CPU}/VariableServer_get_var_server_port.o: \
VariableServer_get_var_server_port.cpp \
object_${TRICK_HOST_CPU}/VariableServer_open_additional_servers.o: \
VariableServer_open_additional_servers.cpp \
${TRICK_HOME}/include/trick/VariableServer.hh \
${TRICK_HOME}/include/trick/tc.h \
${TRICK_HOME}/include/trick/trick_error_hndlr.h \
@ -1039,16 +1058,18 @@ object_${TRICK_HOST_CPU}/VariableServer_get_var_server_port.o: \
${TRICK_HOME}/include/trick/JobData.hh \
${TRICK_HOME}/include/trick/InstrumentBase.hh \
${TRICK_HOME}/include/trick/variable_server_sync_types.h \
${TRICK_HOME}/include/trick/VariableServerThread.hh \
${TRICK_HOME}/include/trick/VariableServerSessionThread.hh \
${TRICK_HOME}/include/trick/ThreadBase.hh \
${TRICK_HOME}/include/trick/VariableServerReference.hh \
${TRICK_HOME}/include/trick/VariableReference.hh \
${TRICK_HOME}/include/trick/VariableServerSession.hh \
${TRICK_HOME}/include/trick/VariableServerListenThread.hh
object_${TRICK_HOST_CPU}/VariableServerThread.o: VariableServerThread.cpp \
${TRICK_HOME}/include/trick/VariableServerThread.hh \
object_${TRICK_HOST_CPU}/VariableServerSessionThread.o: VariableServerSessionThread.cpp \
${TRICK_HOME}/include/trick/VariableServerSessionThread.hh \
${TRICK_HOME}/include/trick/tc.h \
${TRICK_HOME}/include/trick/trick_error_hndlr.h \
${TRICK_HOME}/include/trick/ThreadBase.hh \
${TRICK_HOME}/include/trick/VariableServerReference.hh \
${TRICK_HOME}/include/trick/VariableReference.hh \
${TRICK_HOME}/include/trick/VariableServerSession.hh \
${TRICK_HOME}/include/trick/reference.h \
${TRICK_HOME}/include/trick/attributes.h \
${TRICK_HOME}/include/trick/parameter_types.h \
@ -1058,3 +1079,51 @@ object_${TRICK_HOST_CPU}/VariableServerThread.o: VariableServerThread.cpp \
${TRICK_HOME}/include/trick/exec_proto.h \
${TRICK_HOME}/include/trick/sim_mode.h \
${TRICK_HOME}/include/trick/TrickConstant.hh
object_${TRICK_HOST_CPU}/VariableServerSession.o: VariableServerSession.cpp \
${TRICK_HOME}/include/trick/VariableServerSessionThread.hh \
${TRICK_HOME}/include/trick/tc.h \
${TRICK_HOME}/include/trick/trick_error_hndlr.h \
${TRICK_HOME}/include/trick/ThreadBase.hh \
${TRICK_HOME}/include/trick/VariableReference.hh \
${TRICK_HOME}/include/trick/VariableServerSession.hh \
${TRICK_HOME}/include/trick/reference.h \
${TRICK_HOME}/include/trick/attributes.h \
${TRICK_HOME}/include/trick/parameter_types.h \
${TRICK_HOME}/include/trick/value.h \
${TRICK_HOME}/include/trick/dllist.h \
${TRICK_HOME}/include/trick/variable_server_sync_types.h \
${TRICK_HOME}/include/trick/exec_proto.h \
${TRICK_HOME}/include/trick/sim_mode.h \
${TRICK_HOME}/include/trick/TrickConstant.hh
object_${TRICK_HOST_CPU}/TCConnection.o: TCConnection.cpp \
${TRICK_HOME}/include/trick/TCConnection.hh \
${TRICK_HOME}/include/trick/ClientConnection.hh \
${TRICK_HOME}/include/trick/TCPClientListener.hh \
${TRICK_HOME}/include/trick/VariableServerSessionThread.hh \
${TRICK_HOME}/include/trick/tc.h \
${TRICK_HOME}/include/trick/trick_error_hndlr.h \
${TRICK_HOME}/include/trick/ThreadBase.hh \
${TRICK_HOME}/include/trick/VariableReference.hh \
${TRICK_HOME}/include/trick/VariableServerSession.hh \
${TRICK_HOME}/include/trick/reference.h \
${TRICK_HOME}/include/trick/attributes.h \
${TRICK_HOME}/include/trick/parameter_types.h \
${TRICK_HOME}/include/trick/value.h \
${TRICK_HOME}/include/trick/dllist.h \
${TRICK_HOME}/include/trick/variable_server_sync_types.h \
${TRICK_HOME}/include/trick/exec_proto.h \
${TRICK_HOME}/include/trick/sim_mode.h \
${TRICK_HOME}/include/trick/TrickConstant.hh \
${TRICK_HOME}/include/trick/tc_proto.h
object_${TRICK_HOST_CPU}/TCPClientListener.o: TCPClientListener.cpp \
${TRICK_HOME}/include/trick/TCPConnection.hh \
${TRICK_HOME}/include/trick/ClientConnection.hh \
${TRICK_HOME}/include/trick/TCPClientListener.hh \
${TRICK_HOME}/include/trick/tc.h \
${TRICK_HOME}/include/trick/trick_error_hndlr.h \
${TRICK_HOME}/include/trick/tc_proto.h
object_${TRICK_HOST_CPU}/MulticastGroup.o: MulticastGroup.cpp \
${TRICK_HOME}/include/trick/MulticastGroup.hh \
${TRICK_HOME}/include/trick/tc.h \
${TRICK_HOME}/include/trick/trick_error_hndlr.h \
${TRICK_HOME}/include/trick/tc_proto.h

View File

@ -1,80 +1,737 @@
#include <stdlib.h>
#include <iostream>
#include <udunits2.h>
#include "trick/VariableServer.hh"
#include <math.h> // for fpclassify
#include <iomanip> // for setprecision
#include <string.h>
#include <sstream>
#include "trick/VariableReference.hh"
#include "trick/memorymanager_c_intf.h"
#include "trick/wcs_ext.h"
#include "trick/map_trick_units_to_udunits.hh"
#include "trick/message_proto.h"
#include "trick/message_type.h"
Trick::VariableReference::VariableReference(REF2 * in_ref ) {
#include "trick/UdUnits.hh"
#include "trick/bitfield_proto.h"
#include "trick/trick_byteswap.h"
int k ;
// VariableReference copy setup: set address & size to copy into buffer
conversion_factor = cv_get_trivial() ;
ref = in_ref ;
address = ref->address ;
size = ref->attr->size ;
// char* and wchar* in Trick 7 have a type of string and wstring, respectively
// but in Trick 10 they are type char and wchar (probably John Penn's fault),
// so we need to keep track that they are really string and wstring
string_type = ref->attr->type ;
need_deref = false ;
if ( ref->num_index == ref->attr->num_index ) {
// single value
} else if ( ref->attr->index[ref->attr->num_index - 1].size != 0 ) {
// fixed array
for ( k = ref->attr->num_index-1; k > ref->num_index-1 ; k-- ) {
size *= ref->attr->index[k].size ;
}
} else {
// arrays with pointers
if ((ref->attr->num_index - ref->num_index) > 1 ) {
// you cannot request more than one dimension because they are not contiguous
message_publish(MSG_ERROR, "Variable Server Error: var_add(%s) requests more than one dimension of dynamic array.\n", ref->reference);
message_publish(MSG_ERROR, "Data is not contiguous so returned values are unpredictable.\n") ;
}
if ( ref->attr->type == TRICK_CHARACTER ) {
// treat char* like a c++ string (see below)
string_type = TRICK_STRING ;
need_deref = true;
} else if ( ref->attr->type == TRICK_WCHAR ) {
// treat wchar_t* like a wstring (see below)
string_type = TRICK_WSTRING ;
} else {
need_deref = true ;
size *= get_size((char*)address) ;
}
}
// handle strings: set a max buffer size, the copy size may vary so will be set in copy_sim_data
if (( string_type == TRICK_STRING ) || ( string_type == TRICK_WSTRING )) {
size = MAX_ARRAY_LENGTH ;
}
buffer_in = calloc( size, 1 ) ;
buffer_out = calloc( size, 1 ) ;
// Static variables to be addresses that are known to be the error ref address
int Trick::VariableReference::_bad_ref_int = 0 ;
int Trick::VariableReference::_do_not_resolve_bad_ref_int = 0 ;
REF2* Trick::VariableReference::make_error_ref(std::string in_name) {
REF2* new_ref;
new_ref = (REF2*)calloc(1, sizeof(REF2));
new_ref->reference = strdup(in_name.c_str()) ;
new_ref->units = NULL ;
new_ref->address = (char *)&_bad_ref_int ;
new_ref->attr = (ATTRIBUTES*)calloc(1, sizeof(ATTRIBUTES)) ;
new_ref->attr->type = TRICK_NUMBER_OF_TYPES ;
new_ref->attr->units = (char *)"--" ;
new_ref->attr->size = sizeof(int) ;
return new_ref;
}
std::ostream& Trick::operator<< (std::ostream& s, const Trick::VariableReference& vref) {
REF2* Trick::VariableReference::make_do_not_resolve_ref(std::string in_name) {
REF2* new_ref;
new_ref = (REF2*)calloc(1, sizeof(REF2));
new_ref->reference = strdup(in_name.c_str()) ;
new_ref->units = NULL ;
new_ref->address = (char *)&_do_not_resolve_bad_ref_int ;
new_ref->attr = (ATTRIBUTES*)calloc(1, sizeof(ATTRIBUTES)) ;
new_ref->attr->type = TRICK_NUMBER_OF_TYPES ;
new_ref->attr->units = (char *)"--" ;
new_ref->attr->size = sizeof(int) ;
return new_ref;
}
if (vref.ref->reference != NULL) {
s << " \"" << vref.ref->reference << "\"";
} else {
s<< " null";
// Helper function to deal with time variable
REF2* make_time_ref(double * time) {
REF2* new_ref;
new_ref = (REF2*)calloc(1, sizeof(REF2));
new_ref->reference = strdup("time") ;
new_ref->units = strdup("s") ;
new_ref->address = (char *)time ;
new_ref->attr = (ATTRIBUTES*)calloc(1, sizeof(ATTRIBUTES)) ;
new_ref->attr->type = TRICK_DOUBLE ;
new_ref->attr->units = strdup("s") ;
new_ref->attr->size = sizeof(double) ;
return new_ref;
}
Trick::VariableReference::VariableReference(std::string var_name, double* time) : _staged(false), _write_ready(false) {
if (var_name != "time") {
ASSERT(0);
}
return s;
_var_info = make_time_ref(time);
// Set up member variables
_address = _var_info->address;
_size = _var_info->attr->size ;
_deref = false;
// Deal with weirdness around string vs wstring
_trick_type = _var_info->attr->type ;
// Allocate stage and write buffers
_stage_buffer = calloc(_size, 1) ;
_write_buffer = calloc(_size, 1) ;
_conversion_factor = cv_get_trivial();
_base_units = _var_info->attr->units;
_requested_units = "s";
_name = _var_info->reference;
}
Trick::VariableReference::VariableReference(std::string var_name) : _staged(false), _write_ready(false) {
if (var_name == "time") {
ASSERT(0);
} else {
// get variable attributes from memory manager
_var_info = ref_attributes(var_name.c_str());
}
// Handle error cases
if ( _var_info == NULL ) {
// TODO: ERROR LOGGER sendErrorMessage("Variable Server could not find variable %s.\n", var_name);
// PRINTF IS NOT AN ERROR LOGGER @me
message_publish(MSG_ERROR, "Variable Server could not find variable %s.\n", var_name.c_str());
_var_info = make_error_ref(var_name);
} else if ( _var_info->attr ) {
if ( _var_info->attr->type == TRICK_STRUCTURED ) {
// sendErrorMessage("Variable Server: var_add cant add \"%s\" because its a composite variable.\n", var_name);
message_publish(MSG_ERROR, "Variable Server: var_add cant add \"%s\" because its a composite variable.\n", var_name.c_str());
free(_var_info);
_var_info = make_do_not_resolve_ref(var_name);
} else if ( _var_info->attr->type == TRICK_STL ) {
// sendErrorMessage("Variable Server: var_add cant add \"%s\" because its an STL variable.\n", var_name);
message_publish(MSG_ERROR,"Variable Server: var_add cant add \"%s\" because its an STL variable.\n", var_name.c_str());
free(_var_info);
_var_info = make_do_not_resolve_ref(var_name);
}
} else {
// sendErrorMessage("Variable Server: BAD MOJO - Missing ATTRIBUTES.");
message_publish(MSG_ERROR, "Variable Server: BAD MOJO - Missing ATTRIBUTES.");
free(_var_info);
_var_info = make_error_ref(var_name);
}
// Set up member variables
_var_info->units = NULL;
_address = _var_info->address;
_size = _var_info->attr->size ;
_deref = false;
// Deal with weirdness around string vs wstring
_trick_type = _var_info->attr->type ;
if ( _var_info->num_index == _var_info->attr->num_index ) {
// single value - nothing else necessary
} else if ( _var_info->attr->index[_var_info->attr->num_index - 1].size != 0 ) {
// Constrained array
for ( int i = _var_info->attr->num_index-1; i > _var_info->num_index-1 ; i-- ) {
_size *= _var_info->attr->index[i].size ;
}
} else {
// Unconstrained array
if ((_var_info->attr->num_index - _var_info->num_index) > 1 ) {
message_publish(MSG_ERROR, "Variable Server Error: var_add(%s) requests more than one dimension of dynamic array.\n", _var_info->reference);
message_publish(MSG_ERROR, "Data is not contiguous so returned values are unpredictable.\n") ;
}
if ( _var_info->attr->type == TRICK_CHARACTER ) {
_trick_type = TRICK_STRING ;
_deref = true;
} else if ( _var_info->attr->type == TRICK_WCHAR ) {
_trick_type = TRICK_WSTRING ;
_deref = true;
} else {
_deref = true ;
_size *= get_size((char*)_address) ;
}
}
// handle strings: set a max buffer size, the copy size may vary so will be set in copy_sim_data
if (( _trick_type == TRICK_STRING ) || ( _trick_type == TRICK_WSTRING )) {
_size = MAX_ARRAY_LENGTH ;
}
// Allocate stage and write buffers
_stage_buffer = calloc(_size, 1) ;
_write_buffer = calloc(_size, 1) ;
_conversion_factor = cv_get_trivial();
_base_units = _var_info->attr->units;
_requested_units = "";
_name = _var_info->reference;
// Done!
}
Trick::VariableReference::~VariableReference() {
free(ref) ;
free(buffer_in) ;
free(buffer_out) ;
if (_var_info != NULL) {
free( _var_info );
_var_info = NULL;
}
if (_stage_buffer != NULL) {
free (_stage_buffer);
_stage_buffer = NULL;
}
if (_write_buffer != NULL) {
free (_write_buffer);
_write_buffer = NULL;
}
if (_conversion_factor != NULL) {
cv_free(_conversion_factor);
}
}
std::string Trick::VariableReference::getName() const {
return _name;
}
int Trick::VariableReference::getSizeBinary() const {
return _size;
}
TRICK_TYPE Trick::VariableReference::getType() const {
return _trick_type;
}
std::string Trick::VariableReference::getBaseUnits() const {
return _base_units;
}
int Trick::VariableReference::setRequestedUnits(std::string units_name) {
// Some error logging lambdas - these should probably go somewhere else
// But I do kinda like them
auto publish = [](MESSAGE_TYPE type, const std::string& message) {
std::ostringstream oss;
oss << "Variable Server: " << message << std::endl;
message_publish(type, oss.str().c_str());
};
auto publishError = [&](const std::string& units) {
std::ostringstream oss;
oss << "units error for [" << getName() << "] [" << units << "]";
publish(MSG_ERROR, oss.str());
};
// If the units_name parameter is "xx", set it to the current units.
if (!units_name.compare("xx")) {
units_name = getBaseUnits();
}
// if unitless ('--') then do not convert to udunits
if(units_name.compare("--")) {
// Check to see if this is an old style Trick unit that needs to be converted to new udunits
std::string new_units = map_trick_units_to_udunits(units_name) ;
// Warn if a conversion has taken place
if ( units_name.compare(new_units) ) {
// TODO: MAKE BETTER SYSTEM FOR ERROR LOGGING
std::ostringstream oss;
oss << "[" << getName() << "] old-style units converted from ["
<< units_name << "] to [" << new_units << "]";
publish(MSG_WARNING, oss.str());
}
// Interpret base unit
ut_unit * from = ut_parse(Trick::UdUnits::get_u_system(), getBaseUnits().c_str(), UT_ASCII) ;
if ( !from ) {
std::cout << "Error in interpreting base units" << std::endl;
publishError(getBaseUnits());
ut_free(from) ;
return -1 ;
}
// Interpret requested unit
ut_unit * to = ut_parse(Trick::UdUnits::get_u_system(), new_units.c_str(), UT_ASCII) ;
if ( !to ) {
std::cout << "Error in interpreting requested units" << std::endl;
publishError(new_units);
ut_free(from) ;
ut_free(to) ;
return -1 ;
}
// Create a converter from the base to the requested
auto new_conversion_factor = ut_get_converter(from, to) ;
ut_free(from) ;
ut_free(to) ;
if ( !new_conversion_factor ) {
std::ostringstream oss;
oss << "[" << getName() << "] cannot convert units from [" << getBaseUnits()
<< "] to [" << new_units << "]";
publish(MSG_ERROR, oss.str());
return -1 ;
} else {
_conversion_factor = new_conversion_factor;
}
// Set the requested units. This will cause the unit string to be printed in write_value_ascii
_requested_units = new_units;
}
return 0;
}
int Trick::VariableReference::stageValue(bool validate_address) {
_write_ready = false;
// Copy <size> bytes from <address> to staging_point.
// Try to recreate connection if it has been broken
if (_var_info->address == &_bad_ref_int) {
REF2 *new_ref = ref_attributes(_var_info->reference);
if (new_ref != NULL) {
_var_info = new_ref;
_address = _var_info->address;
// _requested_units = "";
}
}
// if there's a pointer somewhere in the address path, follow it in case pointer changed
if ( _var_info->pointer_present == 1 ) {
_address = follow_address_path(_var_info) ;
if (_address == NULL) {
tagAsInvalid();
} else if ( validate_address ) {
validate();
} else {
_var_info->address = _address ;
}
}
// if this variable is a string we need to get the raw character string out of it.
if (( _trick_type == TRICK_STRING ) && !_deref) {
std::string * str_ptr = (std::string *)_var_info->address ;
// Get a pointer to the internal character array
_address = (void *)(str_ptr->c_str()) ;
}
// if this variable itself is a pointer, dereference it
if ( _deref ) {
_address = *(void**)_var_info->address ;
}
// handle c++ string and char*
if ( _trick_type == TRICK_STRING ) {
if (_address == NULL) {
_size = 0 ;
} else {
_size = strlen((char*)_address) + 1 ;
}
}
// handle c++ wstring and wchar_t*
if ( _trick_type == TRICK_WSTRING ) {
if (_address == NULL) {
_size = 0 ;
} else {
_size = wcslen((wchar_t *)_address) * sizeof(wchar_t);
}
}
if(_address != NULL) {
memcpy( _stage_buffer , _address , _size ) ;
}
_staged = true;
return 0;
}
bool Trick::VariableReference::validate() {
// The address is not NULL.
// Should be called by VariableServer Session if validateAddress is on.
// check the memory manager if the address falls into
// any of the memory blocks it knows of. Don't do this if we have a std::string or
// wstring type, or we already are pointing to a bad ref.
if ( (_trick_type != TRICK_STRING) and
(_trick_type != TRICK_WSTRING) and
(_var_info->address != &_bad_ref_int) and
(get_alloc_info_of(_address) == NULL) ) {
// This variable is broken, make it into an error ref
tagAsInvalid();
return false;
}
// Everything is fine
return true;
}
static void write_escaped_string( std::ostream& os, const char* s) {
for (int ii=0 ; ii<strlen(s) ; ii++) {
if (isprint(s[ii])) {
os << s[ii];
} else {
switch ((s)[ii]) {
case '\n': os << "\\n"; break;
case '\t': os << "\\t"; break;
case '\b': os << "\\b"; break;
case '\a': os << "\\a"; break;
case '\f': os << "\\f"; break;
case '\r': os << "\\n"; break;
case '\v': os << "\\v"; break;
case '\"': os << "\\\""; break;
default : {
// Replicating behavior from original vs_format_ascii
char temp_s[6];
sprintf(temp_s, "\\x%02x", s[ii]);
os << temp_s ;
break;
}
}
}
}
}
int Trick::VariableReference::getSizeAscii() const {
std::stringstream ss;
writeValueAscii(ss);
return ss.str().length();
}
int Trick::VariableReference::writeValueAscii( std::ostream& out ) const {
// This is copied and modified from vs_format_ascii
if (!isWriteReady()) {
return -1;
}
int bytes_written = 0;
void * buf_ptr = _write_buffer ;
while (bytes_written < _size) {
bytes_written += _var_info->attr->size ;
switch (_trick_type) {
case TRICK_CHARACTER:
if (_var_info->attr->num_index == _var_info->num_index) {
// Single char
out << (int)cv_convert_double(_conversion_factor, *(char *)buf_ptr);
} else {
// All but last dim specified, leaves a char array
write_escaped_string(out, (const char *) buf_ptr);
bytes_written = _size ;
}
break;
case TRICK_UNSIGNED_CHARACTER:
if (_var_info->attr->num_index == _var_info->num_index) {
// Single char
out << (unsigned int)cv_convert_double(_conversion_factor,*(unsigned char *)buf_ptr);
} else {
// All but last dim specified, leaves a char array
write_escaped_string(out, (const char *) buf_ptr);
bytes_written = _size ;
}
break;
case TRICK_WCHAR:{
if (_var_info->attr->num_index == _var_info->num_index) {
out << *(wchar_t *) buf_ptr;
} else {
// convert wide char string char string
size_t len = wcs_to_ncs_len((wchar_t *)buf_ptr) + 1 ;
char temp_buf[len];
wcs_to_ncs((wchar_t *) buf_ptr, temp_buf, len);
out << temp_buf;
bytes_written = _size ;
}
}
break;
case TRICK_STRING:
if ((char *) buf_ptr != NULL) {
write_escaped_string(out, (const char *) buf_ptr);
bytes_written = _size ;
} else {
out << '\0';
}
break;
case TRICK_WSTRING:
if ((wchar_t *) buf_ptr != NULL) {
// convert wide char string char string
size_t len = wcs_to_ncs_len( (wchar_t *)buf_ptr) + 1 ;
char temp_buf[len];
wcs_to_ncs( (wchar_t *) buf_ptr, temp_buf, len);
out << temp_buf;
bytes_written = _size ;
} else {
out << '\0';
}
break;
case TRICK_SHORT:
out << (short)cv_convert_double(_conversion_factor,*(short *)buf_ptr);
break;
case TRICK_UNSIGNED_SHORT:
out << (unsigned short)cv_convert_double(_conversion_factor,*(unsigned short *)buf_ptr);
break;
case TRICK_INTEGER:
case TRICK_ENUMERATED:
out << (int)cv_convert_double(_conversion_factor,*(int *)buf_ptr);
break;
case TRICK_BOOLEAN:
out << (int)cv_convert_double(_conversion_factor,*(bool *)buf_ptr);
break;
case TRICK_BITFIELD:
out << (GET_BITFIELD(buf_ptr, _var_info->attr->size, _var_info->attr->index[0].start, _var_info->attr->index[0].size));
break;
case TRICK_UNSIGNED_BITFIELD:
out << (GET_UNSIGNED_BITFIELD(buf_ptr, _var_info->attr->size, _var_info->attr->index[0].start, _var_info->attr->index[0].size));
break;
case TRICK_UNSIGNED_INTEGER:
out << (unsigned int)cv_convert_double(_conversion_factor,*(unsigned int *)buf_ptr);
break;
case TRICK_LONG: {
long l = *(long *)buf_ptr;
if (_conversion_factor != cv_get_trivial()) {
l = (long)cv_convert_double(_conversion_factor, l);
}
out << l;
break;
}
case TRICK_UNSIGNED_LONG: {
unsigned long ul = *(unsigned long *)buf_ptr;
if (_conversion_factor != cv_get_trivial()) {
ul = (unsigned long)cv_convert_double(_conversion_factor, ul);
}
out << ul;
break;
}
case TRICK_FLOAT:
out << std::setprecision(8) << cv_convert_float(_conversion_factor,*(float *)buf_ptr);
break;
case TRICK_DOUBLE:
out << std::setprecision(16) << cv_convert_double(_conversion_factor,*(double *)buf_ptr);
break;
case TRICK_LONG_LONG: {
long long ll = *(long long *)buf_ptr;
if (_conversion_factor != cv_get_trivial()) {
ll = (long long)cv_convert_double(_conversion_factor, ll);
}
out << ll;
break;
}
case TRICK_UNSIGNED_LONG_LONG: {
unsigned long long ull = *(unsigned long long *)buf_ptr;
if (_conversion_factor != cv_get_trivial()) {
ull = (unsigned long long)cv_convert_double(_conversion_factor, ull);
}
out << ull;
break;
}
case TRICK_NUMBER_OF_TYPES:
out << "BAD_REF";
break;
default:{
break;
}
} // end switch
if (bytes_written < _size) {
// if returning an array, continue array as comma separated values
out << ",";
buf_ptr = (void*) ((long)buf_ptr + _var_info->attr->size) ;
}
} //end while
if (_requested_units != "") {
if ( _var_info->attr->mods & TRICK_MODS_UNITSDASHDASH ) {
out << " {--}";
} else {
out << " {" << _requested_units << "}";
}
}
return 0;
}
void Trick::VariableReference::tagAsInvalid () {
std::string save_name(getName()) ;
free(_var_info) ;
_var_info = make_error_ref(save_name) ;
_address = _var_info->address ;
}
int Trick::VariableReference::prepareForWrite() {
if (!_staged) {
return 1;
}
void * temp_p = _stage_buffer;
_stage_buffer = _write_buffer;
_write_buffer = temp_p;
_staged = false;
_write_ready = true;
return 0;
}
bool Trick::VariableReference::isStaged() const {
return _staged;
}
bool Trick::VariableReference::isWriteReady() const {
return _write_ready;
}
int Trick::VariableReference::writeTypeBinary( std::ostream& out, bool byteswap ) const {
int local_type = _trick_type;
if (byteswap) {
local_type = trick_byteswap_int(local_type);
}
out.write(const_cast<const char *>(reinterpret_cast<char *>(&local_type)), sizeof(int));
return 0;
}
int Trick::VariableReference::writeSizeBinary( std::ostream& out, bool byteswap ) const {
int local_size = _size;
if (byteswap) {
local_size = trick_byteswap_int(local_size);
}
out.write(const_cast<const char *>(reinterpret_cast<char *>(&local_size)), sizeof(int));
return 0;
}
int Trick::VariableReference::writeNameBinary( std::ostream& out, bool byteswap ) const {
std::string name = getName();
out.write(name.c_str(), name.size());
return 0;
}
int Trick::VariableReference::writeNameLengthBinary( std::ostream& out, bool byteswap ) const {
int name_size = getName().size();
if (byteswap) {
name_size = trick_byteswap_int(name_size);
}
out.write(const_cast<const char *>(reinterpret_cast<char *>(&name_size)), sizeof(int));
return 0;
}
void Trick::VariableReference::byteswap_var (char * out, char * in) const {
byteswap_var(out, in, *this);
}
void Trick::VariableReference::byteswap_var (char * out, char * in, const VariableReference& ref) {
ATTRIBUTES * attr = ref._var_info->attr;
int array_size = 1;
// Determine how many elements are in this array if it is an array
for (int j = 0; j < ref._var_info->attr->num_index; j++) {
array_size *= attr->index[j].size;
}
switch (attr->size) {
case 1:
// If these are just characters, no need to byteswap
for (int j = 0; j < array_size; j++) {
out[j] = in[j];
}
break;
case 2: {
short * short_in = reinterpret_cast<short *> (in);
short * short_out = reinterpret_cast<short *> (out);
for (int j = 0; j < array_size; j++) {
short_out[j] = trick_byteswap_short(short_in[j]);
}
break;
}
case 4: {
int * int_in = reinterpret_cast<int *> (in);
int * int_out = reinterpret_cast<int *> (out);
for (int j = 0; j < array_size; j++) {
int_out[j] = trick_byteswap_int(int_in[j]);
}
break;
}
case 8: {
// We don't actually care if this is double or long, just that it's the right size
double * double_in = reinterpret_cast<double *> (in);
double * double_out = reinterpret_cast<double *> (out);
for (int j = 0; j < array_size; j++) {
double_out[j] = trick_byteswap_double(double_in[j]);
}
break;
}
}
}
int Trick::VariableReference::writeValueBinary( std::ostream& out, bool byteswap ) const {
if ( _trick_type == TRICK_BITFIELD ) {
int temp_i = GET_BITFIELD(_write_buffer , _var_info->attr->size ,
_var_info->attr->index[0].start, _var_info->attr->index[0].size) ;
out.write((char *)(&temp_i), _size);
return _size;
}
if ( _trick_type == TRICK_UNSIGNED_BITFIELD ) {
int temp_unsigned = GET_UNSIGNED_BITFIELD(_write_buffer , _var_info->attr->size ,
_var_info->attr->index[0].start, _var_info->attr->index[0].size) ;
out.write((char *)(&temp_unsigned), _size);
return _size;
}
if (_trick_type == TRICK_NUMBER_OF_TYPES) {
// TRICK_NUMBER_OF_TYPES is an error case
int temp_zero = 0 ;
out.write((char *)(&temp_zero), _size);
return _size;
}
if (byteswap) {
char * byteswap_buf = (char *) calloc (_size, 1);
byteswap_var(byteswap_buf, (char *) _write_buffer);
out.write(byteswap_buf, _size);
free (byteswap_buf);
}
else {
out.write((char *) _write_buffer, _size);
}
return _size;
}
std::ostream& Trick::operator<< (std::ostream& s, const Trick::VariableReference& ref) {
s << " \"" << ref.getName() << "\"";
return s;
}

View File

@ -16,10 +16,11 @@ Trick::VariableServer::VariableServer() :
}
Trick::VariableServer::~VariableServer() {
the_vs = NULL;
}
std::ostream& Trick::operator<< (std::ostream& s, Trick::VariableServer& vs) {
std::map < pthread_t , VariableServerThread * >::iterator it ;
std::map < pthread_t , VariableServerSessionThread * >::iterator it ;
s << "{\"variable_server_connections\":[\n";
int count = 0;
@ -52,51 +53,81 @@ bool Trick::VariableServer::get_info_msg() {
void Trick::VariableServer::set_var_server_info_msg_on() {
info_msg = true;
for ( auto& session_it : var_server_sessions ) {
session_it.second->set_info_message(info_msg);
}
}
void Trick::VariableServer::set_var_server_info_msg_off() {
info_msg = false;
for ( auto& session_it : var_server_sessions ) {
session_it.second->set_info_message(info_msg);
}
}
bool Trick::VariableServer::get_log() {
return log ;
}
bool Trick::VariableServer::get_session_log() {
return session_log ;
}
void Trick::VariableServer::set_var_server_log_on() {
log = true;
// turn log on for all current vs clients
std::map < pthread_t , VariableServerThread * >::iterator it ;
for ( it = var_server_threads.begin() ; it != var_server_threads.end() ; it++ ) {
(*it).second->set_log_on();
for ( auto& session_it : var_server_sessions ) {
session_it.second->set_log(true);
}
}
void Trick::VariableServer::set_var_server_log_off() {
log = false;
// turn log off for all current vs clients
std::map < pthread_t , VariableServerThread * >::iterator it ;
for ( it = var_server_threads.begin() ; it != var_server_threads.end() ; it++ ) {
(*it).second->set_log_off();
for ( auto& session_it : var_server_sessions ) {
session_it.second->set_log(false);
}
}
void Trick::VariableServer::set_var_server_session_log_on() {
session_log = true;
// turn log on for all current vs clients
for ( auto& session_it : var_server_sessions ) {
session_it.second->set_session_log(true);
}
}
void Trick::VariableServer::set_var_server_session_log_off() {
session_log = false;
// turn log off for all current vs clients
for ( auto& session_it : var_server_sessions ) {
session_it.second->set_session_log(false);
}
}
const char * Trick::VariableServer::get_hostname() {
return (listen_thread.get_hostname()) ;
return listen_thread.get_hostname();
}
Trick::VariableServerListenThread & Trick::VariableServer::get_listen_thread() {
return listen_thread ;
}
void Trick::VariableServer::add_vst(pthread_t in_thread_id, VariableServerThread * in_vst) {
void Trick::VariableServer::add_vst(pthread_t in_thread_id, VariableServerSessionThread * in_vst) {
pthread_mutex_lock(&map_mutex) ;
var_server_threads[in_thread_id] = in_vst ;
pthread_mutex_unlock(&map_mutex) ;
}
Trick::VariableServerThread * Trick::VariableServer::get_vst(pthread_t thread_id) {
std::map < pthread_t , Trick::VariableServerThread * >::iterator it ;
Trick::VariableServerThread * ret = NULL ;
void Trick::VariableServer::add_session(pthread_t in_thread_id, VariableServerSession * in_session) {
pthread_mutex_lock(&map_mutex) ;
var_server_sessions[in_thread_id] = in_session ;
pthread_mutex_unlock(&map_mutex) ;
}
Trick::VariableServerSessionThread * Trick::VariableServer::get_vst(pthread_t thread_id) {
std::map < pthread_t , Trick::VariableServerSessionThread * >::iterator it ;
Trick::VariableServerSessionThread * ret = NULL ;
pthread_mutex_lock(&map_mutex) ;
it = var_server_threads.find(thread_id) ;
if ( it != var_server_threads.end() ) {
@ -106,16 +137,33 @@ Trick::VariableServerThread * Trick::VariableServer::get_vst(pthread_t thread_id
return ret ;
}
Trick::VariableServerSession * Trick::VariableServer::get_session(pthread_t thread_id) {
Trick::VariableServerSession * ret = NULL ;
pthread_mutex_lock(&map_mutex) ;
auto it = var_server_sessions.find(thread_id) ;
if ( it != var_server_sessions.end() ) {
ret = (*it).second ;
}
pthread_mutex_unlock(&map_mutex) ;
return ret ;
}
void Trick::VariableServer::delete_vst(pthread_t thread_id) {
pthread_mutex_lock(&map_mutex) ;
var_server_threads.erase(thread_id) ;
pthread_mutex_unlock(&map_mutex) ;
}
void Trick::VariableServer::delete_session(pthread_t thread_id) {
pthread_mutex_lock(&map_mutex) ;
var_server_sessions.erase(thread_id) ;
pthread_mutex_unlock(&map_mutex) ;
}
void Trick::VariableServer::set_copy_data_job( Trick::JobData * in_job ) {
copy_data_job = in_job ;
}
void Trick::VariableServer::set_copy_data_freeze_job( Trick::JobData * in_job ) {
copy_data_freeze_job = in_job ;
void Trick::VariableServer::set_copy_and_write_freeze_job( Trick::JobData * in_job ) {
copy_and_write_freeze_job = in_job ;
}

View File

@ -3,201 +3,196 @@
#include <pwd.h>
#include "trick/VariableServerListenThread.hh"
#include "trick/VariableServerThread.hh"
#include "trick/tc_proto.h"
#include "trick/VariableServerSessionThread.hh"
#include "trick/exec_proto.h"
#include "trick/command_line_protos.h"
#include "trick/message_proto.h"
#include "trick/message_type.h"
Trick::VariableServerListenThread::VariableServerListenThread() :
#define MAX_MACHINE_NAME 80
Trick::VariableServerListenThread::VariableServerListenThread() : VariableServerListenThread (NULL) {}
Trick::VariableServerListenThread::VariableServerListenThread(TCPClientListener * listener) :
Trick::SysThread("VarServListen"),
port(0),
user_port_requested(false),
broadcast(true),
listen_dev()
_requested_source_address(""),
_requested_port(0),
_user_requested_address(false),
_broadcast(true),
_listener(listener),
_multicast(new MulticastGroup())
{
char hname[80];
gethostname(hname , (size_t) 80 ) ;
source_address = std::string(hname) ;
strcpy(listen_dev.client_tag, "<empty>");
tc_error(&listen_dev, 0);
pthread_mutex_init(&restart_pause, NULL);
if (_listener != NULL) {
// If we were passed a listener
// We assume it is already initialized
_requested_source_address = _listener->getHostname();
_requested_port = _listener->getPort();
_user_requested_address = true;
} else {
// Otherwise, make one
_listener = new TCPClientListener;
}
cancellable = false;
}
Trick::VariableServerListenThread::~VariableServerListenThread() {
free(listen_dev.hostname) ;
free(listen_dev.error_handler) ;
delete _listener;
delete _multicast;
}
void Trick::VariableServerListenThread::set_multicast_group (MulticastGroup * group) {
delete _multicast;
_multicast = group;
}
const char * Trick::VariableServerListenThread::get_hostname() {
return listen_dev.hostname;
std::string hostname = _requested_source_address;
char * ret = (char *) malloc(hostname.length() + 1);
strncpy(ret, hostname.c_str(), hostname.length());
ret[hostname.length()] = '\0';
return ret;
}
unsigned short Trick::VariableServerListenThread::get_port() {
return port;
return _requested_port;
}
void Trick::VariableServerListenThread::set_port(unsigned short in_port) {
port = in_port;
user_port_requested = true ;
_requested_port = in_port;
_user_requested_address = true ;
}
#ifndef __APPLE__
void Trick::VariableServerListenThread::set_socket_priority(unsigned short in_socket_priority) {
socket_priority = in_socket_priority;
user_socket_priority_requested = true ;
_socket_priority = in_socket_priority;
_user_socket_priority_requested = true ;
}
#endif
std::string Trick::VariableServerListenThread::get_user_tag() {
return user_tag ;
return _user_tag ;
}
const std::string& Trick::VariableServerListenThread::get_user_tag_ref() {
return user_tag ;
return _user_tag ;
}
void Trick::VariableServerListenThread::set_user_tag(std::string in_tag) {
user_tag = in_tag ;
_user_tag = in_tag ;
}
void Trick::VariableServerListenThread::set_source_address(const char * address) {
if ( address == NULL ) {
source_address = std::string("") ;
_requested_source_address = std::string("") ;
} else {
source_address = std::string(address) ;
_requested_source_address = std::string(address) ;
}
user_port_requested = true ;
_user_requested_address = true;
}
std::string Trick::VariableServerListenThread::get_source_address() {
return source_address ;
return _requested_source_address ;
}
bool Trick::VariableServerListenThread::get_broadcast() {
return broadcast;
return _broadcast;
}
void Trick::VariableServerListenThread::set_broadcast(bool in_broadcast) {
broadcast = in_broadcast;
_broadcast = in_broadcast;
}
// Called from default data
int Trick::VariableServerListenThread::init_listen_device() {
int ret;
ret = tc_init(&listen_dev);
if (ret == TC_SUCCESS) {
port = listen_dev.port ;
} else {
fprintf(stderr, "ERROR: Could not establish listen port for Variable Server. Aborting.\n");
ret = -1 ;
}
return ret ;
int ret = _listener->initialize();
_requested_port = _listener->getPort();
_requested_source_address = _listener->getHostname();
apply_socket_priority();
return ret;
}
// Called from init jobs
int Trick::VariableServerListenThread::check_and_move_listen_device() {
int ret ;
if ( source_address.compare(listen_dev.hostname) or port != listen_dev.port ) {
if (_user_requested_address) {
/* The user has requested a different source address or port in the input file */
tc_disconnect(&listen_dev) ;
ret = tc_init_with_connection_info(&listen_dev, AF_INET, SOCK_STREAM, source_address.c_str(), port) ;
if (ret != TC_SUCCESS) {
_listener->disconnect();
ret = _listener->initialize(_requested_source_address, _requested_port);
_requested_port = _listener->getPort();
_requested_source_address = _listener->getHostname();
apply_socket_priority();
if (ret != 0) {
message_publish(MSG_ERROR, "ERROR: Could not establish variable server source_address %s: port %d. Aborting.\n",
source_address.c_str(), port);
_requested_source_address.c_str(), _requested_port);
return -1 ;
}
}
return 0 ;
}
void Trick::VariableServerListenThread::create_tcp_socket(const char * address, unsigned short in_port ) {
int result = tc_init_with_connection_info(&listen_dev, AF_INET, SOCK_STREAM, address, in_port) ;
if (result != 0) {
message_publish(MSG_ERROR, "ERROR: Could not establish additional listen port at address %s and port %d for Variable Server.\n", address, in_port);
}
}
void * Trick::VariableServerListenThread::thread_body() {
// This thread listens for incoming client connections, and when one is received, creates a new thread to handle the session
// Also broadcasts on multicast channel
fd_set rfds;
struct timeval timeout_time = { 2, 0 };
char buf1[1024] = { 0 } ;
struct passwd * passp ;
Trick::VariableServerThread * vst ;
int value;
std::string version;
char * user_name ;
test_shutdown();
int mcast_socket = 0;
struct sockaddr_in mcast_addr ;
struct sockaddr_in mcast_addr_legacy ;
version = std::string(exec_get_current_version()) ;
std::string version = std::string(exec_get_current_version()) ;
version.erase(version.find_last_not_of(" \t\f\v\n\r")+1);
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
passp = getpwuid(getuid()) ;
// get username to _broadcast on multicast channel
struct passwd *passp = getpwuid(getuid()) ;
std::string user_name;
if ( passp == NULL ) {
user_name = strdup("unknown") ;
} else {
user_name = strdup(passp->pw_name) ;
}
_listener->setBlockMode(true);
tc_blockio(&listen_dev, TC_COMM_BLOCKIO);
if ( broadcast ) {
if ((mcast_socket = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
perror("vs_mcast_init socket");
}
value = 1;
if (setsockopt(mcast_socket, SOL_SOCKET, SO_REUSEADDR, (char *) &value, (socklen_t) sizeof(value)) < 0) {
perror("setsockopt: reuseaddr");
}
#ifdef SO_REUSEPORT
if (setsockopt(mcast_socket, SOL_SOCKET, SO_REUSEPORT, (char *) &value, sizeof(value)) < 0) {
perror("setsockopt: reuseport");
}
#endif
/* Set up destination address */
memset(&mcast_addr, 0, sizeof(mcast_addr));
mcast_addr.sin_family = AF_INET;
mcast_addr.sin_addr.s_addr = inet_addr("239.3.14.15");
mcast_addr.sin_port = htons((uint16_t) 9265);
memset(&mcast_addr_legacy, 0, sizeof(mcast_addr_legacy));
mcast_addr_legacy.sin_family = AF_INET;
mcast_addr_legacy.sin_addr.s_addr = inet_addr("224.3.14.15");
mcast_addr_legacy.sin_port = htons((uint16_t) 9265);
if ( _broadcast ) {
initializeMulticast();
}
while (1) {
// Quit here if it's time
test_shutdown();
FD_ZERO(&rfds);
FD_SET(listen_dev.socket, &rfds);
timeout_time.tv_sec = 2 ;
select(listen_dev.socket + 1, &rfds, NULL, NULL, &timeout_time);
// Pause here if we need to
test_pause();
if (FD_ISSET(listen_dev.socket, &rfds)) {
// pause here during restart
pthread_mutex_lock(&restart_pause) ;
vst = new Trick::VariableServerThread(&listen_dev) ;
// Look for a new client requesting a connection
if (_listener->checkForNewConnections()) {
// Create a new thread to service this connection
VariableServerSessionThread * vst = new Trick::VariableServerSessionThread() ;
vst->set_connection(_listener->setUpNewConnection());
vst->copy_cpus(get_cpus()) ;
vst->create_thread() ;
vst->wait_for_accept() ;
pthread_mutex_unlock(&restart_pause) ;
} else if ( broadcast ) {
snprintf(buf1 , sizeof(buf1), "%s\t%hu\t%s\t%d\t%s\t%s\t%s\t%s\t%s\t%hu\n" , listen_dev.hostname , (unsigned short)listen_dev.port ,
user_name , (int)getpid() , command_line_args_get_default_dir() , command_line_args_get_cmdline_name() ,
command_line_args_get_input_file() , version.c_str() , user_tag.c_str(), (unsigned short)listen_dev.port ) ;
ConnectionStatus status = vst->wait_for_accept() ;
sendto(mcast_socket , buf1 , strlen(buf1) , 0 , (struct sockaddr *)&mcast_addr , (socklen_t)sizeof(mcast_addr)) ;
sendto(mcast_socket , buf1 , strlen(buf1) , 0 , (struct sockaddr *)&mcast_addr_legacy , (socklen_t)sizeof(mcast_addr)) ;
if (status == CONNECTION_FAIL) {
// If the connection failed, the thread will exit.
// Make sure it joins fully before deleting the vst object
vst->join_thread();
delete vst;
}
} else if ( _broadcast ) {
// Otherwise, broadcast on the multicast channel if enabled
char buf1[1024];
snprintf(buf1 , sizeof(buf1), "%s\t%hu\t%s\t%d\t%s\t%s\t%s\t%s\t%s\t%hu\n" , _listener->getHostname().c_str(), (unsigned short)_listener->getPort() ,
user_name.c_str() , (int)getpid() , command_line_args_get_default_dir() , command_line_args_get_cmdline_name() ,
command_line_args_get_input_file() , version.c_str() , _user_tag.c_str(), (unsigned short)_listener->getPort() ) ;
std::string message(buf1);
if (!_multicast->isInitialized()) {
// In case broadcast was turned on after this loop was entered
initializeMulticast();
}
_multicast->broadcast(message);
}
}
@ -210,58 +205,60 @@ int Trick::VariableServerListenThread::restart() {
int ret ;
if ( user_port_requested ) {
_listener->restart();
char hname[80];
static struct sockaddr_in s_in;
gethostname(hname, (size_t) 80);
// Test to see if the restart address is on this machine. If it is not, it's not an error, clear source address
if ( strcmp( source_address.c_str(), hname )) {
if (! inet_pton(AF_INET, source_address.c_str(), (struct in_addr *)&s_in.sin_addr.s_addr) ) {
//printf("clearing source_address\n") ;
source_address.clear() ;
}
if ( _user_requested_address ) {
// If the use requested an address and/or port, make sure we reinitialize to the same one
if (!_listener->validateSourceAddress(_requested_source_address)) {
_requested_source_address.clear() ;
}
printf("variable server restart user_port requested set %d\n", port) ;
message_publish(MSG_INFO, "variable server restart user_port requested set %s:%d\n",_requested_source_address.c_str(), _requested_port);
tc_disconnect(&listen_dev) ;
ret = tc_init_with_connection_info(&listen_dev, AF_INET, SOCK_STREAM, source_address.c_str(), port) ;
if (ret != TC_SUCCESS) {
message_publish(MSG_ERROR, "ERROR: Could not establish listen port %d for Variable Server. Aborting.\n", port);
_listener->disconnect();
ret = _listener->initialize(_requested_source_address, _requested_port);
apply_socket_priority();
if (ret != 0) {
message_publish(MSG_ERROR, "ERROR: Could not establish listen port %d for Variable Server. Aborting.\n", _requested_port);
return (-1);
}
} else {
struct sockaddr_in s_in;
int s_in_size = sizeof(s_in) ;
getsockname( listen_dev.socket , (struct sockaddr *)&s_in, (socklen_t *)&s_in_size) ;
printf("restart variable server message port = %d\n" , ntohs(s_in.sin_port)) ;
port = listen_dev.port = ntohs(s_in.sin_port);
// Otherwise, just ask the listener what port it's using
_listener->checkSocket();
message_publish(MSG_INFO, "restart variable server message port = %d\n", _listener->getPort());
}
initializeMulticast();
return 0 ;
}
void Trick::VariableServerListenThread::initializeMulticast() {
_multicast->initialize();
_multicast->addAddress("239.3.14.15", 9265);
_multicast->addAddress("224.3.14.15", 9265);
}
void Trick::VariableServerListenThread::pause_listening() {
pthread_mutex_lock(&restart_pause) ;
force_thread_to_pause();
}
void Trick::VariableServerListenThread::restart_listening() {
pthread_mutex_unlock(&restart_pause) ;
_listener->restart();
unpause_thread();
}
void Trick::VariableServerListenThread::dump( std::ostream & oss ) {
oss << "Trick::VariableServerListenThread (" << name << ")" << std::endl ;
oss << " source_address = " << source_address << std::endl ;
oss << " port = " << port << std::endl ;
oss << " user_port_requested = " << user_port_requested << std::endl ;
oss << " user_tag = " << user_tag << std::endl ;
oss << " broadcast = " << broadcast << std::endl ;
oss << " source_address = " << _listener->getHostname() << std::endl ;
oss << " port = " << _listener->getPort() << std::endl ;
oss << " user_requested_address = " << _user_requested_address << std::endl ;
oss << " user_tag = " << _user_tag << std::endl ;
oss << " broadcast = " << _broadcast << std::endl ;
Trick::ThreadBase::dump(oss) ;
}
#ifndef __APPLE__
void Trick::VariableServerListenThread::apply_socket_priority(TCDevice *listen_device, TCDevice *device) {
if (user_socket_priority_requested) tc_set_socket_priority(listen_device, device, socket_priority);
void Trick::VariableServerListenThread::apply_socket_priority() {
if (_user_socket_priority_requested) _listener->checkSocket();
}
#endif

View File

@ -0,0 +1,255 @@
#include "trick/VariableServerSession.hh"
#include "trick/TrickConstant.hh"
#include "trick/exec_proto.h"
#include "trick/Message_proto.hh"
#include "trick/message_proto.h"
#include "trick/input_processor_proto.h"
#include "trick/realtimesync_proto.h"
int Trick::VariableServerSession::instance_counter = 0;
std::string Trick::VariableServerSession::log_subdir = "session_logs";
Trick::VariableServerSession::VariableServerSession() {
_debug = 0;
_enabled = true ;
_log = false ;
_session_log = false;
_session_log_msg_stream = -1;
_info_msg = false;
_copy_mode = VS_COPY_ASYNC ;
_write_mode = VS_WRITE_ASYNC ;
_frame_multiple = 1 ;
_frame_offset = 0 ;
_freeze_frame_multiple = 1 ;
_freeze_frame_offset = 0 ;
_update_rate = 0.1 ;
_cycle_tics = (long long)(_update_rate * exec_get_time_tic_value()) ;
if (_cycle_tics == 0) {
_cycle_tics = 1;
}
_next_tics = TRICK_MAX_LONG_LONG ;
_freeze_next_tics = TRICK_MAX_LONG_LONG ;
_byteswap = false ;
_validate_address = false ;
_send_stdio = false ;
_binary_data = false;
_byteswap = false;
_binary_data_nonames = false;
_exit_cmd = false;
_pause_cmd = false;
_instance_num = instance_counter++;
pthread_mutex_init(&_copy_mutex, NULL);
}
Trick::VariableServerSession::~VariableServerSession() {
for (unsigned int ii = 0 ; ii < _session_variables.size() ; ii++ ) {
delete _session_variables[ii];
}
}
void Trick::VariableServerSession::set_connection(ClientConnection * conn) {
_connection = conn;
log_connection_opened();
}
bool Trick::VariableServerSession::is_session_log_open() {
return _session_log_msg_stream != -1;
}
void Trick::VariableServerSession::open_session_log() {
std::string name = "VSSession" + std::to_string(_instance_num);
_session_log_msg_stream = open_custom_message_file(log_subdir + "/" + name + ".log", name);
}
// Command to turn on log to varserver_log file
int Trick::VariableServerSession::set_log(bool on_off) {
_log = on_off;
return(0) ;
}
// Command to turn on individual session log file
int Trick::VariableServerSession::set_session_log(bool on_off) {
_session_log = on_off;
return(0) ;
}
bool Trick::VariableServerSession::get_pause() {
return _pause_cmd ;
}
void Trick::VariableServerSession::set_pause( bool on_off) {
_pause_cmd = on_off ;
}
bool Trick::VariableServerSession::get_exit_cmd() {
return _exit_cmd ;
}
void Trick::VariableServerSession::pause_copy() {
pthread_mutex_lock(&_copy_mutex);
}
void Trick::VariableServerSession::unpause_copy() {
pthread_mutex_unlock(&_copy_mutex);
}
void Trick::VariableServerSession::disconnect_references() {
for (VariableReference * variable : _session_variables) {
variable->tagAsInvalid();
}
}
long long Trick::VariableServerSession::get_next_tics() const {
if ( ! _enabled ) {
return TRICK_MAX_LONG_LONG ;
}
return _next_tics ;
}
long long Trick::VariableServerSession::get_freeze_next_tics() const {
if ( ! _enabled ) {
return TRICK_MAX_LONG_LONG ;
}
return _freeze_next_tics ;
}
void Trick::VariableServerSession::log_connection_opened() {
if (_session_log) {
if (!is_session_log_open()) {
open_session_log();
}
message_publish(_session_log_msg_stream, "Variable Server Session started with %s:%d\n", _connection->getClientHostname().c_str(), _connection->getClientPort());
}
}
void Trick::VariableServerSession::log_received_message(const std::string& msg) {
if (_log) {
message_publish(MSG_PLAYBACK, "tag=<%s> time=%f %s", _connection->getClientTag().c_str(), exec_get_sim_time(), msg.c_str());
}
if (_session_log) {
if (!is_session_log_open())
open_session_log();
message_publish(_session_log_msg_stream, "tag=<%s> time=%f %s", _connection->getClientTag().c_str(), exec_get_sim_time(), msg.c_str());
}
if (_debug >= 3) {
message_publish(MSG_DEBUG, "%p tag=<%s> var_server received bytes = msg_len = %d\n", _connection, _connection->getClientTag().c_str(), msg.size());
}
if (_debug >= 1 || _info_msg) {
message_publish(MSG_DEBUG, "tag=<%s> time=%f %s", _connection->getClientTag().c_str(), exec_get_sim_time(), msg.c_str());
}
}
int Trick::VariableServerSession::handle_message() {
std::string received_message;
int nbytes = _connection->read(received_message);
if (nbytes > 0) {
log_received_message(received_message);
ip_parse(received_message.c_str()); /* returns 0 if no parsing error */
}
return nbytes;
}
Trick::VariableReference * Trick::VariableServerSession::find_session_variable(std::string name) const {
for (VariableReference * ref : _session_variables) {
// Look for matching name
if (name.compare(ref->getName()) == 0) {
return ref;
}
}
return NULL;
}
int Trick::VariableServerSession::set_info_message(bool on) {
_info_msg = on;
return 0;
}
double Trick::VariableServerSession::get_update_rate() const {
return _update_rate;
}
VS_WRITE_MODE Trick::VariableServerSession::get_write_mode () const {
return _write_mode;
}
VS_COPY_MODE Trick::VariableServerSession::get_copy_mode () const {
return _copy_mode;
}
long long Trick::VariableServerSession::get_cycle_tics() const {
return _cycle_tics;
}
int Trick::VariableServerSession::get_frame_multiple () const {
return _frame_multiple;
}
int Trick::VariableServerSession::get_frame_offset () const {
return _frame_offset;
}
int Trick::VariableServerSession::get_freeze_frame_multiple () const {
return _freeze_frame_multiple;
}
int Trick::VariableServerSession::get_freeze_frame_offset () const {
return _freeze_frame_offset;
}
bool Trick::VariableServerSession::get_enabled () const {
return _enabled;
}
void Trick::VariableServerSession::set_freeze_next_tics(long long tics) {
_freeze_next_tics = tics;
}
void Trick::VariableServerSession::set_next_tics(long long tics) {
_next_tics = tics;
}
void Trick::VariableServerSession::set_exit_cmd() {
_exit_cmd = true;
}
std::ostream& Trick::operator<< (std::ostream& s, const Trick::VariableServerSession& session) {
if (session._binary_data) {
s << " \"format\":\"BINARY\",\n";
} else {
s << " \"format\":\"ASCII\",\n";
}
s << " \"update_rate\":" << session.get_update_rate() << ",\n";
s << " \"variables\":[\n";
int n_vars = (int)session._session_variables.size();
for (int i=0 ; i<n_vars ; i++) {
s << *(session._session_variables[i]);
if ((n_vars-i)>1) {
s << "," ;
}
s << "\n";
}
s << " ]\n";
return s;
}

View File

@ -0,0 +1,134 @@
#include <iostream>
#include <stdlib.h>
#include "trick/VariableServerSessionThread.hh"
#include "trick/exec_proto.h"
#include "trick/message_proto.h"
#include "trick/message_type.h"
#include "trick/TrickConstant.hh"
#include "trick/UDPConnection.hh"
#include "trick/TCPConnection.hh"
Trick::VariableServer * Trick::VariableServerSessionThread::_vs = NULL ;
static int instance_num = 0;
Trick::VariableServerSessionThread::VariableServerSessionThread() : VariableServerSessionThread (new VariableServerSession()) {}
Trick::VariableServerSessionThread::VariableServerSessionThread(VariableServerSession * session) :
Trick::SysThread(std::string("VarServer" + std::to_string(instance_num++))) , _debug(0), _session(session), _connection(NULL) {
_connection_status = CONNECTION_PENDING ;
pthread_mutex_init(&_connection_status_mutex, NULL);
pthread_cond_init(&_connection_status_cv, NULL);
cancellable = false;
}
Trick::VariableServerSessionThread::~VariableServerSessionThread() {
cleanup();
}
std::ostream& Trick::operator<< (std::ostream& s, Trick::VariableServerSessionThread& vst) {
// Write a JSON representation of a Trick::VariableServerSessionThread to an ostream.
s << " \"connection\":{\n";
s << " \"client_tag\":\"" << vst._connection->getClientTag() << "\",\n";
s << " \"client_IP_address\":\"" << vst._connection->getClientHostname() << "\",\n";
s << " \"client_port\":\"" << vst._connection->getClientPort() << "\",\n";
pthread_mutex_lock(&vst._connection_status_mutex);
if (vst._connection_status == CONNECTION_SUCCESS) {
s << *(vst._session);
}
pthread_mutex_unlock(&vst._connection_status_mutex);
s << " }" << std::endl;
return s;
}
void Trick::VariableServerSessionThread::set_vs_ptr(Trick::VariableServer * in_vs) {
_vs = in_vs ;
}
Trick::VariableServer * Trick::VariableServerSessionThread::get_vs() {
return _vs ;
}
void Trick::VariableServerSessionThread::set_client_tag(std::string tag) {
_connection->setClientTag(tag);
}
void Trick::VariableServerSessionThread::set_connection(Trick::ClientConnection * in_connection) {
_connection = in_connection;
}
Trick::ConnectionStatus Trick::VariableServerSessionThread::wait_for_accept() {
pthread_mutex_lock(&_connection_status_mutex);
while ( _connection_status == CONNECTION_PENDING ) {
pthread_cond_wait(&_connection_status_cv, &_connection_status_mutex);
}
pthread_mutex_unlock(&_connection_status_mutex);
return _connection_status;
}
// Gets called from the main thread as a job
void Trick::VariableServerSessionThread::preload_checkpoint() {
// Stop variable server processing at the top of the processing loop.
force_thread_to_pause();
// Make sure that the _session has been initialized
pthread_mutex_lock(&_connection_status_mutex);
if (_connection_status == CONNECTION_SUCCESS) {
// Let the thread complete any data copying it has to do
// and then suspend data copying until the checkpoint is reloaded.
_session->pause_copy();
// Save the pause state of this thread.
_saved_pause_cmd = _session->get_pause();
// Disallow data writing.
_session->set_pause(true);
// Temporarily "disconnect" the variable references from Trick Managed Memory
// by tagging each as a "bad reference".
_session->disconnect_references();
// Allow data copying to continue.
_session->unpause_copy();
}
pthread_mutex_unlock(&_connection_status_mutex);
}
// Gets called from the main thread as a job
void Trick::VariableServerSessionThread::restart() {
// Set the pause state of this thread back to its "pre-checkpoint reload" state.
_connection->restart();
pthread_mutex_lock(&_connection_status_mutex);
if (_connection_status == CONNECTION_SUCCESS) {
_session->set_pause(_saved_pause_cmd) ;
}
pthread_mutex_unlock(&_connection_status_mutex);
// Restart the variable server processing.
unpause_thread();
}
void Trick::VariableServerSessionThread::cleanup() {
_connection->disconnect();
if (_session != NULL) {
delete _session;
_session = NULL;
}
}

View File

@ -0,0 +1,139 @@
#include <iostream>
#ifdef __linux
#include <cxxabi.h>
#endif
#include "trick/VariableServer.hh"
#include "trick/message_proto.h"
#include "trick/realtimesync_proto.h"
#include "trick/ExecutiveException.hh"
#include "trick/exec_proto.h"
#include "trick/VariableServerSessionThread.hh"
void exit_var_thread(void *in_vst) ;
void * Trick::VariableServerSessionThread::thread_body() {
// Check for short running sims
test_shutdown(NULL, NULL);
// We need to make the thread to VariableServerSessionThread map before we accept the connection.
// Otherwise we have a race where this thread is unknown to the variable server and the
// client gets confirmation that the connection is ready for communication.
_vs->add_vst( pthread_self() , this ) ;
// Accept client connection
int status = _connection->start();
if (status != 0) {
_vs->delete_vst(pthread_self());
// Tell main thread that we failed to initialize
pthread_mutex_lock(&_connection_status_mutex);
_connection_status = CONNECTION_FAIL;
pthread_cond_signal(&_connection_status_cv);
pthread_mutex_unlock(&_connection_status_mutex);
thread_shutdown();
}
// if log is set on for variable server (e.g., in input file), turn log on for each client
if (_vs->get_log()) {
_session->set_log(true);
}
if (_vs->get_session_log()) {
_session->set_session_log(true);
}
if (_vs->get_info_msg()) {
_session->set_info_message(true);
}
// Give the initialized connection to the session
// Don't touch the connection anymore until we shut them both down
_session->set_connection(_connection);
_vs->add_session( pthread_self(), _session );
// Tell main that we are ready
pthread_mutex_lock(&_connection_status_mutex);
_connection_status = CONNECTION_SUCCESS;
pthread_cond_signal(&_connection_status_cv);
pthread_mutex_unlock(&_connection_status_mutex);
try {
while (1) {
// Shutdown here if it's time
test_shutdown(exit_var_thread, (void *) this);
// Pause here if we are in a restart condition
test_pause();
// Look for a message from the client
// Parse and execute if one is availible
int read_status = _session->handle_message();
if ( read_status < 0 ) {
break ;
}
// Check to see if exit is necessary
if (_session->get_exit_cmd() == true) {
break;
}
// Tell session it's time to copy and write if the mode is correct
int ret =_session->copy_and_write_async();
if (ret < 0) {
break;
}
// Sleep for the appropriate cycle time
usleep((unsigned int) (_session->get_update_rate() * 1000000));
}
} catch (Trick::ExecutiveException & ex ) {
message_publish(MSG_ERROR, "\nVARIABLE SERVER COMMANDED exec_terminate\n ROUTINE: %s\n DIAGNOSTIC: %s\n" ,
ex.file.c_str(), ex.message.c_str()) ;
exec_signal_terminate();
} catch (const std::exception &ex) {
message_publish(MSG_ERROR, "\nVARIABLE SERVER caught std::exception\n DIAGNOSTIC: %s\n" ,
ex.what()) ;
exec_signal_terminate();
#ifdef __linux
#ifdef __GNUC__
#if __GNUC__ >= 4 && __GNUC_MINOR__ >= 2
// for post gcc 4.1.2 or whatever glibc version is used in RHEL6 and above.
} catch (abi::__forced_unwind&) {
//pthread_exit and pthread_cancel will cause an abi::__forced_unwind to be thrown. Rethrow it.
throw;
#endif
#endif
#endif
} catch (...) {
#ifdef __linux
#ifdef __GNUC__
#if (__GNUC__ == 4 && __GNUC_MINOR__ == 1) || __GNUC__ == 12
// for gcc 4.1.2 or whatever glib version in RHEL 5 that does not work with the abi::__forced_unwind
// Also seems to have a problem with gcc 12
throw;
#else
message_publish(MSG_ERROR, "\nVARIABLE SERVER caught unknown exception\n" ) ;
exec_signal_terminate();
#endif
#endif
#endif
}
if (_debug >= 3) {
message_publish(MSG_DEBUG, "%p tag=<%s> var_server receive loop exiting\n", _connection, _connection->getClientTag().c_str());
}
thread_shutdown(exit_var_thread, this);
// No return from this.
}

Some files were not shown because too many files have changed in this diff Show More