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