mirror of
https://github.com/nasa/trick.git
synced 2024-12-20 05:37:55 +00:00
Refactored to avoid duplicate code
This commit is contained in:
parent
2202360f77
commit
448320602e
@ -93,7 +93,7 @@ namespace Trick {
|
||||
@code <my_drg> = trick.DRBinary("<in_name>") @endcode
|
||||
@copydoc Trick::DataRecordGroup::DataRecordGroup(string in_name)
|
||||
*/
|
||||
DRBinary( std::string in_name, bool register_group = true, bool configure_jobs = true ) ;
|
||||
DRBinary( std::string in_name, bool register_group = true, unsigned long job_config = 0x7F ) ;
|
||||
|
||||
/**
|
||||
@copybrief Trick::DataRecordGroup::format_specific_header
|
||||
|
@ -149,7 +149,7 @@ namespace Trick {
|
||||
@brief Constructor that creates a new data recording group with the given @c in_name.
|
||||
@param in_name - the new data recording group name
|
||||
*/
|
||||
DataRecordGroup( std::string in_name = "", bool configure_jobs = true ) ;
|
||||
DataRecordGroup( std::string in_name = "", unsigned long job_config = 0x7F ) ;
|
||||
|
||||
~DataRecordGroup() ;
|
||||
|
||||
@ -405,6 +405,12 @@ namespace Trick {
|
||||
*/
|
||||
virtual int add_time_variable() ;
|
||||
|
||||
/**
|
||||
@brief This function adds jobs to the DRG based on job_config bits. By default a DRG should be constructed with all jobs on.
|
||||
@returns void
|
||||
*/
|
||||
virtual void configure_jobs(unsigned long job_config) ;
|
||||
|
||||
/** Check that a variable is supported by data recording. */
|
||||
/** Variable must be a single primitive type - no STL, array, structured, string */
|
||||
bool isSupportedType(REF2 * ref2, std::string& message);
|
||||
|
@ -22,7 +22,7 @@ PROGRAMMERS:
|
||||
Other classes inherit from DRBinary. In these cases, we don't want to register the memory as DRBinary,
|
||||
so register_group will be set to false.
|
||||
*/
|
||||
Trick::DRBinary::DRBinary( std::string in_name, bool register_group, bool configure_jobs ) : Trick::DataRecordGroup(in_name) {
|
||||
Trick::DRBinary::DRBinary( std::string in_name, bool register_group, unsigned long job_config ) : Trick::DataRecordGroup(in_name, job_config) {
|
||||
if ( register_group ) {
|
||||
register_group_with_mm(this, "Trick::DRBinary") ;
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ Trick::DataRecordBuffer::~DataRecordBuffer() {
|
||||
free(ref) ;
|
||||
}
|
||||
|
||||
Trick::DataRecordGroup::DataRecordGroup( std::string in_name, bool configure_jobs ) :
|
||||
Trick::DataRecordGroup::DataRecordGroup( std::string in_name, unsigned long job_config ) :
|
||||
record(true) ,
|
||||
inited(false) ,
|
||||
group_name(in_name) ,
|
||||
@ -104,20 +104,7 @@ Trick::DataRecordGroup::DataRecordGroup( std::string in_name, bool configure_job
|
||||
For context - FrameDataRecordGroup does not want to create restart jobs,
|
||||
but rather the FrameLog object which owns those DRG's will manually retsart them from the FrameLog's restart job.
|
||||
*/
|
||||
if(configure_jobs) {
|
||||
// add_jobs_to_queue will fill in job_id later
|
||||
// make the init job run after all other initialization jobs but before the post init checkpoint
|
||||
// job so users can allocate memory in initialization jobs and checkpointing data rec groups will work
|
||||
add_job(0, 1, (char *)"initialization", NULL, cycle, (char *)"init", (char *)"TRK", 65534) ;
|
||||
add_job(0, 2, (char *)"end_of_frame", NULL, 1.0, (char *)"write_data", (char *)"TRK") ;
|
||||
add_job(0, 3, (char *)"checkpoint", NULL, 1.0, (char *)"checkpoint", (char *)"TRK") ;
|
||||
add_job(0, 4, (char *)"post_checkpoint", NULL, 1.0, (char *)"clear_checkpoint_vars", (char *)"TRK") ;
|
||||
// run the restart job in phase 60001
|
||||
add_job(0, 5, (char *)"restart", NULL, 1.0, (char *)"restart", (char *)"TRK", 60001) ;
|
||||
add_job(0, 6, (char *)"shutdown", NULL, 1.0, (char *)"shutdown", (char *)"TRK") ;
|
||||
|
||||
write_job = add_job(0, 99, (char *)job_class.c_str(), NULL, cycle, (char *)"data_record" , (char *)"TRK") ;
|
||||
}
|
||||
configure_jobs(job_config);
|
||||
|
||||
add_time_variable() ;
|
||||
}
|
||||
@ -439,6 +426,30 @@ int Trick::DataRecordGroup::init() {
|
||||
|
||||
}
|
||||
|
||||
void Trick::DataRecordGroup::configure_jobs(unsigned long job_config)
|
||||
{
|
||||
// add_jobs_to_queue will fill in job_id later
|
||||
// make the init job run after all other initialization jobs but before the post init checkpoint
|
||||
// job so users can allocate memory in initialization jobs and checkpointing data rec groups will work
|
||||
if(job_config & 1)
|
||||
add_job(0, 1, (char *)"initialization", NULL, cycle, (char *)"init", (char *)"TRK", 65534) ;
|
||||
if(job_config & 2)
|
||||
add_job(0, 2, (char *)"end_of_frame", NULL, 1.0, (char *)"write_data", (char *)"TRK") ;
|
||||
if(job_config & 4)
|
||||
add_job(0, 3, (char *)"checkpoint", NULL, 1.0, (char *)"checkpoint", (char *)"TRK") ;
|
||||
if(job_config & 8)
|
||||
add_job(0, 4, (char *)"post_checkpoint", NULL, 1.0, (char *)"clear_checkpoint_vars", (char *)"TRK") ;
|
||||
if(job_config & 16)
|
||||
// run the restart job in phase 60001
|
||||
add_job(0, 5, (char *)"restart", NULL, 1.0, (char *)"restart", (char *)"TRK", 60001) ;
|
||||
if(job_config & 32)
|
||||
add_job(0, 6, (char *)"shutdown", NULL, 1.0, (char *)"shutdown", (char *)"TRK") ;
|
||||
|
||||
if(job_config & 64)
|
||||
write_job = add_job(0, 99, (char *)job_class.c_str(), NULL, cycle, (char *)"data_record" , (char *)"TRK") ;
|
||||
|
||||
}
|
||||
|
||||
int Trick::DataRecordGroup::checkpoint() {
|
||||
unsigned int jj ;
|
||||
|
||||
|
@ -9,19 +9,7 @@
|
||||
-# All instances get the end_of_frame frame_log_clear job.
|
||||
*/
|
||||
Trick::FrameDataRecordGroup::FrameDataRecordGroup( int in_thread_id , std::string in_name )
|
||||
: Trick::DRBinary(in_name, false, false) , thread_id(in_thread_id ) {
|
||||
// add_jobs_to_queue will fill in job_id later
|
||||
// make the init job run after all other initialization jobs but before the post init checkpoint
|
||||
// job so users can allocate memory in initialization jobs and checkpointing data rec groups will work
|
||||
add_job(0, 1, (char *)"initialization", NULL, cycle, (char *)"init", (char *)"TRK", 65534) ;
|
||||
add_job(0, 2, (char *)"end_of_frame", NULL, 1.0, (char *)"write_data", (char *)"TRK") ;
|
||||
add_job(0, 3, (char *)"checkpoint", NULL, 1.0, (char *)"checkpoint", (char *)"TRK") ;
|
||||
add_job(0, 4, (char *)"post_checkpoint", NULL, 1.0, (char *)"clear_checkpoint_vars", (char *)"TRK") ;
|
||||
// run the restart job in phase 60001
|
||||
add_job(0, 6, (char *)"shutdown", NULL, 1.0, (char *)"shutdown", (char *)"TRK") ;
|
||||
|
||||
write_job = add_job(0, 99, (char *)job_class.c_str(), NULL, cycle, (char *)"data_record" , (char *)"TRK") ;
|
||||
|
||||
: Trick::DRBinary(in_name, false, 0x6F) , thread_id(in_thread_id ) {
|
||||
if ( thread_id > 0 ) {
|
||||
add_job(thread_id, 1000, (char *)"top_of_frame", NULL, 1.0, (char *)"start_timer", (char *)"TRK", 1) ;
|
||||
// Frame logging uses phase 65533 in FrameLog.ccp. Stop the timer just before that.
|
||||
|
Loading…
Reference in New Issue
Block a user