• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nasa / trick / 9210803248

23 May 2024 03:29PM UTC coverage: 55.831% (-0.03%) from 55.856%
9210803248

push

github

web-flow
message (#1712)

0 of 8 new or added lines in 1 file covered. (0.0%)

1 existing line in 1 file now uncovered.

12265 of 21968 relevant lines covered (55.83%)

72665.76 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

21.62
/trick_source/sim_services/Message/Message_c_intf.cpp
1

2
#include <iostream>
3
#include <stdio.h>
4
#include <stdarg.h>
5

6
#include "trick/MessagePublisher.hh"
7
#include "trick/MessageCout.hh"
8
#include "trick/MessageFile.hh"
9
#include "trick/MessageCustomFile.hh"
10
#include "trick/MessageTCDevice.hh"
11
#include "trick/message_proto.h"
12

13
#define MAX_MSG_HEADER_SIZE 256
14
#define MAX_MSG_SIZE 20480
15

16
/** Global pointer to the MessagePubliser. */
17
extern Trick::MessagePublisher * the_message_publisher ;
18

19
/**
20
 @relates Trick::MessagePublisher
21
 @copydoc Trick::MessagePublisher::subscribe
22
 */
23
int message_subscribe( Trick::MessageSubscriber * in_ms ) {
×
24
    the_message_publisher->subscribe(in_ms) ;
×
25
    return(0) ;
×
26
}
27
 
28
/**
29
 @relates Trick::MessagePublisher
30
 @copydoc Trick::MessagePublisher::unsubscribe
31
 */
32
int message_unsubscribe( Trick::MessageSubscriber * in_ms ) {
×
33
    the_message_publisher->unsubscribe(in_ms) ;
×
34
    return(0) ;
×
35
}
36

37

38
/**
39
 @relates Trick::MessagePublisher
40
 @copydoc Trick::MessagePublisher::subscribe
41
 */
NEW
42
extern "C" int message_add_subscriber( void * in_ms ) {
×
NEW
43
    the_message_publisher->subscribe((Trick::MessageSubscriber *)in_ms) ;
×
NEW
44
    return(0) ;
×
45
}
46
 
47
/**
48
 @relates Trick::MessagePublisher
49
 @copydoc Trick::MessagePublisher::unsubscribe
50
 */
NEW
51
extern "C" int message_remove_subscriber( void * in_ms ) {
×
NEW
52
    the_message_publisher->unsubscribe((Trick::MessageSubscriber *)in_ms) ;
×
NEW
53
    return(0) ;
×
54
}
55

56
/**
57
 @relates Trick::MessagePublisher
58
 @copydoc Trick::MessagePublisher::getSubscriber
59
 */
NEW
60
extern "C" void * message_get_subscriber( const char * sub_name ) {
×
NEW
61
    return (void *)the_message_publisher->getSubscriber(sub_name) ;
×
62
}
63

64
/**
65
 @relates Trick::MessagePublisher
66
 @userdesc Command to publish a message, which sends the message to all subscribers.
67
 Creates a header that is prepended to the message, so that the output looks like this:
68
 @code |L <level>|<date>|<hostname>|<Trick::MessagePublisher::sim_name>|T <process id>|<sim time>| <format_msg> @endcode
69
 Calls Trick::MessagePublisher::publish.
70
 @par Python Usage:
71
 @code trick.message_publish(<level>, "<format_msg>") @endcode
72
 @param level - the published message level
73
 @param format_msg - the published message C format message string
74
 @return always 0
75
 */
76
extern "C" int message_publish(int level, const char * format_msg, ...) {
1,962✔
77

78
    char msg_buf[MAX_MSG_SIZE];
79
    va_list args;
80

81
    va_start(args, format_msg);
1,962✔
82
    (void) vsnprintf(msg_buf, MAX_MSG_SIZE, format_msg, args);
1,962✔
83
    va_end(args);
1,962✔
84

85
    if (the_message_publisher != NULL) {
1,962✔
86
        the_message_publisher->publish(level, msg_buf) ;
1,947✔
87
    } else {
88
        // if we don't have a message publisher, simply print message to terminal
89
        message_publish_standalone(level, msg_buf) ;
15✔
90
    }
91

92
    return (0);
1,962✔
93
}
94

95
extern "C" int vmessage_publish(int level, const char * format_msg, va_list args) {
×
96

97
    char msg_buf[MAX_MSG_SIZE];
98

99
    (void) vsnprintf(msg_buf, MAX_MSG_SIZE, format_msg, args);
×
100

101
    if (the_message_publisher != NULL) {
×
102
        the_message_publisher->publish(level, msg_buf) ;
×
103
    } else {
104
        // if we don't have a message publisher, simply print message to terminal
105
        message_publish_standalone(level, msg_buf) ;
×
106
    }
107

108
    return (0);
×
109
}
110
/**
111
 @relates Trick::MessagePublisher
112
 @userdesc A send health & status routine provided for backwards compatibility; simply calls message_publish with level 0.
113
 @par Python Usage:
114
 @code trick.send_hs(None, "<format_msg>") @endcode
115
 @param fp - the file which the published message goes to (this is ignored, message goes to all subscribers)
116
 @param format_msg - the published message C format message string
117
 @return always 0
118
 */
119
extern "C" int send_hs(FILE * fp __attribute__ ((unused)), const char * format_msg, ...) {
×
120

121
    char msg_buf[MAX_MSG_SIZE];
122
    va_list args;
123

124
    va_start(args, format_msg);
×
125
    (void) vsnprintf(msg_buf, MAX_MSG_SIZE, format_msg, args);
×
126
    va_end(args);
×
127

128
    message_publish(0, msg_buf) ;
×
129

130
    return (0);
×
131
}
132

133
extern "C" int vsend_hs(FILE * fp __attribute__ ((unused)), const char * format_msg, va_list args) {
×
134

135
    vmessage_publish(0, format_msg, args) ;
×
136
    return (0);
×
137
}
138

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc