ngc 1.4.0
 
Loading...
Searching...
No Matches
ngcdcsPUBLISHER.hpp
Go to the documentation of this file.
1
7#ifndef ngcdcsPUBLISHER_H
8#define ngcdcsPUBLISHER_H
9
10
11#ifndef __cplusplus
12#error This is a C++ include file and cannot be used from plain C
13#endif
14
16
17/*
18 * Publishing methods
19 */
20#define ngcdcsPUB_POSTPONE 0x1 //< postpone until completion
21#define ngcdcsPUB_KEEP 0x2 //< keep in list
22
27{
28public:
31
34
37 ngcbLIST *l;
39 logLevel = other.logLevel;
40 for (l=other.list_.First();l!=NULL;l=l->next)
41 {
42 ngcdcs_exp_topic *topic = static_cast<ngcdcs_exp_topic *>(l->item);
43 if (topic != NULL) list_.Add(new ngcdcs_exp_topic(*topic));
44 }
45 return (*this);
46 }
47
50 ngcbLIST *l;
52 logLevel = other.logLevel;
53 for (l=other.list_.First();l!=NULL;l=l->next)
54 {
55 ngcdcs_exp_topic *topic = static_cast<ngcdcs_exp_topic *>(l->item);
56 if (topic != NULL) list_.Add(new ngcdcs_exp_topic(*topic));
57 }
58 }
59
62
64 virtual ~ngcdcsPUBLISHER() {Clear();}
65
67 void Clear() {
68 ngcbLIST *l;
69 for (l=list_.First();l!=NULL;l=l->next)
70 {
71 ngcdcs_exp_topic *topic = static_cast<ngcdcs_exp_topic *>(l->item);
72 if (topic != NULL) delete topic;
73 }
74 list_.Clear();
75 }
76
78 void Remove(const char *id) {
79 ngcbLIST *l = list_.First();
80 while (l != NULL)
81 {
82 if (l->item != NULL)
83 {
84 ngcdcs_exp_topic *topic = static_cast<ngcdcs_exp_topic *>(l->item);
85 l = l->next;
86 if (strcmp(topic->id, id) == 0)
87 {
88 list_.Remove(topic); delete topic;
89 }
90 }
91 else
92 {
93 l = l->next;
94 }
95 }
96 }
97
99 void Remove(int id) {
100 char s[64];
101 sprintf(s, "%d", id);
102 Remove(s);
103 }
104
106 void Push(const ngcdcs_exp_topic &topic) {
107 if (strcmp(topic.status, "Active") == 0)
108 {
109 /*
110 * Add the topic to the list
111 */
112 list_.Add(new ngcdcs_exp_topic(topic));
113
114 if (!(topic.method & ngcdcsPUB_POSTPONE))
115 {
116 /*
117 * Publish immediately
118 */
119 PublishList_(topic.id, topic.status);
120 }
121 }
122 else if (strlen(topic.fileName) > 0)
123 {
124 /*
125 * Add the topic to the list and publish
126 */
127 list_.Add(new ngcdcs_exp_topic(topic));
128 PublishList_(topic.id, topic.status);
129 Clear();
130 }
131 else if (strlen(topic.status) > 0)
132 {
133 /*
134 * Update status and publish the list again
135 */
136 PublishList_(topic.id, topic.status);
137 Clear();
138 }
139 else
140 {
141 /*
142 * No file, no status - we do nothing
143 */
144 }
145 }
146
147protected:
148
150 virtual void Publish(const ngcdcs_exp_topic &topic) {
151 if (verboseLevel > 0)
152 {
153 fprintf(stdout, "data: %s,%s,%s:%s\n", topic.id, topic.status,
154 topic.host, topic.fileName);
155 }
156 }
157
158private:
160 ngcbLIST list_;
161
163 void PublishList_(const char *id, const char *status) {
164 ngcbLIST *l;
165 for (l = list_.First(); l != NULL; l = l->next)
166 {
167 if (l->item != NULL)
168 {
169 ngcdcs_exp_topic *topic = static_cast<ngcdcs_exp_topic *>(l->item);
170 if (strcmp(topic->id, id) == 0)
171 {
172 /*
173 * Exposure id matches. We update the status and publish
174 */
175 strcpy(topic->status, status);
176 Publish(*topic);
177 }
178 }
179 }
180 }
181};
182
183#endif
Definition ngcbLIST.hpp:33
void * item
Item.
Definition ngcbLIST.hpp:36
void Clear()
Clear list.
Definition ngcbLIST.cpp:39
ngcbLIST * First() const
Return list entry point.
Definition ngcbLIST.cpp:31
ngcbLIST * next
Next item.
Definition ngcbLIST.hpp:39
ngcdcsPUBLISHER & operator=(const ngcdcsPUBLISHER &other)
Operator =.
Definition ngcdcsPUBLISHER.hpp:36
int logLevel
Logging level.
Definition ngcdcsPUBLISHER.hpp:33
int verboseLevel
Verbose level.
Definition ngcdcsPUBLISHER.hpp:30
ngcdcsPUBLISHER(const ngcdcsPUBLISHER &other)
Copy constructor.
Definition ngcdcsPUBLISHER.hpp:49
void Remove(int id)
Remove all topics marked with an id from publisher list.
Definition ngcdcsPUBLISHER.hpp:99
ngcdcsPUBLISHER()
Constructor.
Definition ngcdcsPUBLISHER.hpp:61
void Clear()
Clear publisher list.
Definition ngcdcsPUBLISHER.hpp:67
void Push(const ngcdcs_exp_topic &topic)
Push topic to publisher.
Definition ngcdcsPUBLISHER.hpp:106
virtual ~ngcdcsPUBLISHER()
Destructor.
Definition ngcdcsPUBLISHER.hpp:64
virtual void Publish(const ngcdcs_exp_topic &topic)
Publisher.
Definition ngcdcsPUBLISHER.hpp:150
void Remove(const char *id)
Remove all topics marked with an id from publisher list.
Definition ngcdcsPUBLISHER.hpp:78
#define ngcdcsPUB_POSTPONE
Definition ngcdcsPUBLISHER.hpp:20
Definition ngcdcsEXP.hpp:141
char status[32]
Definition ngcdcsEXP.hpp:145
char id[64]
Definition ngcdcsEXP.hpp:142
char host[64]
Definition ngcdcsEXP.hpp:143
int method
Definition ngcdcsEXP.hpp:146
char fileName[256]
Definition ngcdcsEXP.hpp:144