YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
SubscriberOnSql.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-FileCopyrightText: 2006-2010 RobotCub Consortium
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <cstdlib>
8#include <cstdio>
9
10#include <sqlite3.h>
11
15
16#if !defined(_WIN32)
17#include <unistd.h>
18#else
19#include <io.h>
20#define access(f,a) _access(f,a)
21#endif
22
23#include <vector>
24#include <string>
25
26#ifndef F_OK
27#define F_OK 0
28#endif
29
30#define SQLDB(x) ((sqlite3*)(x))
31
32using namespace yarp::os;
33using namespace yarp::serversql::impl;
34
35namespace {
36YARP_SERVERSQL_LOG_COMPONENT(SUBSCRIBERONSQL, "yarp.serversql.impl.SubscriberOnSql")
37} // namespace
38
39
40bool SubscriberOnSql::open(const std::string& filename, bool fresh) {
41 sqlite3 *db = nullptr;
42 if (fresh) {
43 int result = access(filename.c_str(),F_OK);
44 if (result==0) {
45 yCWarning(SUBSCRIBERONSQL, "Database needs to be recreated.");
46 yCWarning(SUBSCRIBERONSQL, "Please move %s out of the way.", filename.c_str());
47 return false;
48 }
49
50 }
51 int result = sqlite3_open_v2(filename.c_str(),
52 &db,
54 nullptr);
55 if (result!=SQLITE_OK) {
56 yCError(SUBSCRIBERONSQL, "Failed to open database %s", filename.c_str());
57 if (db != nullptr) {
58 sqlite3_close(db);
59 }
60 return false;
61 }
62
63 const char *create_subscribe_table = "CREATE TABLE IF NOT EXISTS subscriptions (\n\
64 id INTEGER PRIMARY KEY,\n\
65 src TEXT,\n\
66 dest TEXT,\n\
67 srcFull TEXT,\n\
68 destFull TEXT,\n\
69 mode TEXT);";
70
71 result = sqlite3_exec(db, create_subscribe_table, nullptr, nullptr, nullptr);
72 if (result!=SQLITE_OK) {
73 sqlite3_close(db);
74 yCError(SUBSCRIBERONSQL, "Failed to set up subscriptions table");
75 std::exit(1);
76 }
77
78 const char *check_subscriptions_size = "PRAGMA table_info(subscriptions)";
79
80 sqlite3_stmt *statement = nullptr;
81 result = sqlite3_prepare_v2(db, check_subscriptions_size, -1, &statement, nullptr);
82 if (result!=SQLITE_OK) {
83 yCError(SUBSCRIBERONSQL, "Failed to set up subscriptions table");
84 std::exit(1);
85 }
86
87 int count = 0;
89 count++;
90 }
92
93 if (count==5) {
94 const char *add_structure = "ALTER TABLE subscriptions ADD COLUMN mode";
95 result = sqlite3_exec(db, add_structure, nullptr, nullptr, nullptr);
96 if (result!=SQLITE_OK) {
97 sqlite3_close(db);
98 yCError(SUBSCRIBERONSQL, "Failed to set up subscriptions table");
99 std::exit(1);
100 }
101 }
102
103 const char *create_topic_table = "CREATE TABLE IF NOT EXISTS topics (\n\
104 id INTEGER PRIMARY KEY,\n\
105 topic TEXT,\n\
106 structure TEXT);";
107
108 result = sqlite3_exec(db, create_topic_table, nullptr, nullptr, nullptr);
109 if (result!=SQLITE_OK) {
110 sqlite3_close(db);
111 yCError(SUBSCRIBERONSQL, "Failed to set up topics table");
112 std::exit(1);
113 }
114
115 const char *check_topic_size = "PRAGMA table_info(topics)";
116
117 statement = nullptr;
118 result = sqlite3_prepare_v2(db, check_topic_size, -1, &statement, nullptr);
119 if (result!=SQLITE_OK) {
120 yCError(SUBSCRIBERONSQL, "Failed to set up topics table");
121 std::exit(1);
122 }
123
124 count = 0;
125 while (sqlite3_step(statement) == SQLITE_ROW) {
126 //sqlite3_column_text(statement,1);
127 count++;
128 }
130
131 if (count==2) {
132 const char *add_structure = "ALTER TABLE topics ADD COLUMN structure";
133 result = sqlite3_exec(db, add_structure, nullptr, nullptr, nullptr);
134 if (result!=SQLITE_OK) {
135 sqlite3_close(db);
136 yCError(SUBSCRIBERONSQL, "Failed to set up topics table");
137 std::exit(1);
138 }
139 }
140
141 const char *create_live_table = "CREATE TABLE IF NOT EXISTS live (\n\
142 id INTEGER PRIMARY KEY,\n\
143 name TEXT UNIQUE,\n\
144 stamp DATETIME);";
145
146 result = sqlite3_exec(db, create_live_table, nullptr, nullptr, nullptr);
147 if (result!=SQLITE_OK) {
148 sqlite3_close(db);
149 yCError(SUBSCRIBERONSQL, "Failed to set up live table");
150 std::exit(1);
151 }
152
153 const char *create_struct_table = "CREATE TABLE IF NOT EXISTS structures (\n\
154 name TEXT PRIMARY KEY,\n\
155 yarp TEXT);";
156
157 result = sqlite3_exec(db, create_struct_table, nullptr, nullptr, nullptr);
158 if (result!=SQLITE_OK) {
159 sqlite3_close(db);
160 yCError(SUBSCRIBERONSQL, "Failed to set up structures table");
161 std::exit(1);
162 }
163
164 implementation = db;
165 return true;
166}
167
168
170 if (implementation != nullptr) {
171 auto* db = (sqlite3 *)implementation;
172 sqlite3_close(db);
173 implementation = nullptr;
174 }
175 return true;
176}
177
178bool SubscriberOnSql::addSubscription(const std::string& src,
179 const std::string& dest,
180 const std::string& mode) {
181 removeSubscription(src,dest);
183 psrc.apply(src);
184 pdest.apply(dest);
185 if (psrc.getCarrier()=="topic") {
186 setTopic(psrc.getPortName(),"",true);
187 }
188 if (pdest.getCarrier()=="topic") {
189 setTopic(pdest.getPortName(),"",true);
190 }
191 char *msg = nullptr;
192 const char *zmode = mode.c_str();
193 if (mode == "") {
194 zmode = nullptr;
195 }
196 char *query = sqlite3_mprintf("INSERT INTO subscriptions (src,dest,srcFull,destFull,mode) VALUES(%Q,%Q,%Q,%Q,%Q)",
197 psrc.getPortName().c_str(),
198 pdest.getPortName().c_str(),
199 src.c_str(),
200 dest.c_str(),
201 zmode);
202 yCDebug(SUBSCRIBERONSQL, "Query: %s", query);
203
204 bool ok = true;
205 int result = sqlite3_exec(SQLDB(implementation), query, nullptr, nullptr, &msg);
206 if (result!=SQLITE_OK) {
207 ok = false;
208 if (msg != nullptr) {
211 }
212 }
214 if (ok) {
215 if (psrc.getCarrier()!="topic") {
216 if (pdest.getCarrier()!="topic") {
217 checkSubscription(psrc.getPortName(),
218 pdest.getPortName(),
219 src,
220 dest,
221 mode);
222 } else {
223 hookup(psrc.getPortName());
224 }
225 } else {
226 if (pdest.getCarrier()!="topic") {
227 hookup(pdest.getPortName());
228 }
229 }
230 }
231 return ok;
232}
233
234bool SubscriberOnSql::removeSubscription(const std::string& src,
235 const std::string& dest) {
237 psrc.apply(src);
238 pdest.apply(dest);
239 char *query = sqlite3_mprintf("DELETE FROM subscriptions WHERE src = %Q AND dest = %Q",
240 psrc.getPortName().c_str(),
241 pdest.getPortName().c_str());
242 yCDebug(SUBSCRIBERONSQL, "Query: %s", query);
243
244 int result = sqlite3_exec(SQLDB(implementation), query, nullptr, nullptr, nullptr);
245 bool ok = true;
246 if (result!=SQLITE_OK) {
247 yCError(SUBSCRIBERONSQL, "Error in query");
248 ok = false;
249 }
251
252 return ok;
253}
254
255
256bool SubscriberOnSql::welcome(const std::string& port, int activity) {
257 mutex.lock();
258
259 char *msg = nullptr;
260 char *query;
261 if (activity>0) {
262 query = sqlite3_mprintf("INSERT OR IGNORE INTO live (name,stamp) VALUES(%Q,DATETIME('now'))",
263 port.c_str());
264 } else {
265 // Port not responding. Mark as non-live.
266 if (activity==0) {
267 query = sqlite3_mprintf("DELETE FROM live WHERE name=%Q AND stamp < DATETIME('now','-30 seconds')",
268 port.c_str());
269 } else {
270 // activity = -1 -- definite dodo
271 query = sqlite3_mprintf("DELETE FROM live WHERE name=%Q",
272 port.c_str());
273 }
274 }
275 yCDebug(SUBSCRIBERONSQL, "Query: %s", query);
276
277 bool ok = true;
278 int result = sqlite3_exec(SQLDB(implementation), query, nullptr, nullptr, &msg);
279 if (result!=SQLITE_OK) {
280 ok = false;
281 if (msg != nullptr) {
284 }
285 }
287 mutex.unlock();
288
289 if (activity>0) {
290 hookup(port);
291 } else if (activity<0) {
292 breakdown(port);
293 }
294 return ok;
295}
296
297bool SubscriberOnSql::hookup(const std::string& port) {
298 mutex.lock();
299 sqlite3_stmt *statement = nullptr;
300 char *query = nullptr;
301 //query = sqlite3_mprintf("SELECT * FROM subscriptions WHERE src = %Q OR dest= %Q",port, port);
302 query = sqlite3_mprintf("SELECT src,dest,srcFull,destFull FROM subscriptions WHERE (src = %Q OR dest= %Q) AND EXISTS (SELECT NULL FROM live WHERE name=src) AND EXISTS (SELECT NULL FROM live WHERE name=dest) UNION SELECT s1.src, s2.dest, s1.srcFull, s2.destFull FROM subscriptions s1, subscriptions s2, topics t WHERE (s1.dest = t.topic AND s2.src = t.topic) AND (s1.src = %Q OR s2.dest = %Q) AND EXISTS (SELECT NULL FROM live WHERE name=s1.src) AND EXISTS (SELECT NULL FROM live WHERE name=s2.dest)",port.c_str(), port.c_str(), port.c_str(), port.c_str());
303 //
304 yCDebug(SUBSCRIBERONSQL, "Query: %s", query);
305
306 int result = sqlite3_prepare_v2(SQLDB(implementation), query, -1, &statement, nullptr);
307 if (result!=SQLITE_OK) {
308 const char *msg = sqlite3_errmsg(SQLDB(implementation));
309 if (msg != nullptr) {
311 }
312 }
313 while (result == SQLITE_OK && sqlite3_step(statement) == SQLITE_ROW) {
314 char *src = (char *)sqlite3_column_text(statement,0);
315 char *dest = (char *)sqlite3_column_text(statement,1);
316 char *srcFull = (char *)sqlite3_column_text(statement,2);
317 char *destFull = (char *)sqlite3_column_text(statement,3);
318 char *mode = (char *)sqlite3_column_text(statement,4);
320 }
323 mutex.unlock();
324
325 return false;
326}
327
328
329bool SubscriberOnSql::breakdown(const std::string& port) {
330 mutex.lock();
331 sqlite3_stmt *statement = nullptr;
332 char *query = nullptr;
333 // query = sqlite3_mprintf("SELECT src,dest,srcFull,destFull,mode FROM subscriptions WHERE ((src = %Q AND EXISTS (SELECT NULL FROM live WHERE name=dest)) OR (dest = %Q AND EXISTS (SELECT NULL FROM live WHERE name=src))) UNION SELECT s1.src, s2.dest, s1.srcFull, s2.destFull, NULL FROM subscriptions s1, subscriptions s2, topics t WHERE (s1.dest = t.topic AND s2.src = t.topic AND ((s1.src = %Q AND EXISTS (SELECT NULL FROM live WHERE name=s2.dest)) OR (s2.dest = %Q AND EXISTS (SELECT NULL FROM live WHERE name=s1.src))))",port, port, port, port);
334 query = sqlite3_mprintf("SELECT src,dest,srcFull,destFull,mode FROM subscriptions WHERE ((src = %Q AND (mode IS NOT NULL OR EXISTS (SELECT NULL FROM live WHERE name=dest))) OR (dest = %Q AND (mode IS NOT NULL OR EXISTS (SELECT NULL FROM live WHERE name=src)))) UNION SELECT s1.src, s2.dest, s1.srcFull, s2.destFull, NULL FROM subscriptions s1, subscriptions s2, topics t WHERE (s1.dest = t.topic AND s2.src = t.topic AND ((s1.src = %Q AND EXISTS (SELECT NULL FROM live WHERE name=s2.dest)) OR (s2.dest = %Q AND EXISTS (SELECT NULL FROM live WHERE name=s1.src))))",port.c_str(), port.c_str(), port.c_str(), port.c_str());
335 yCDebug(SUBSCRIBERONSQL, "Query: %s", query);
336
337 int result = sqlite3_prepare_v2(SQLDB(implementation), query, -1, &statement, nullptr);
338 if (result!=SQLITE_OK) {
339 const char *msg = sqlite3_errmsg(SQLDB(implementation));
340 if (msg != nullptr) {
342 }
343 }
344 while (result == SQLITE_OK && sqlite3_step(statement) == SQLITE_ROW) {
345 char *src = (char *)sqlite3_column_text(statement,0);
346 char *dest = (char *)sqlite3_column_text(statement,1);
347 char *srcFull = (char *)sqlite3_column_text(statement,2);
348 char *destFull = (char *)sqlite3_column_text(statement,3);
349 char *mode = (char *)sqlite3_column_text(statement,4);
350 breakSubscription(port,src,dest,srcFull,destFull,mode?mode:"");
351 }
354 mutex.unlock();
355
356 return false;
357}
358
359
360bool SubscriberOnSql::checkSubscription(const std::string& src,const std::string& dest,
361 const std::string& srcFull,
362 const std::string& destFull,
363 const std::string& mode) {
365 "+++ Checking %s %s / %s %s",
366 src.c_str(),
367 dest.c_str(),
368 srcFull.c_str(),
369 destFull.c_str());
370
371 NameStore *store = getStore();
372 if (store != nullptr) {
373 Contact csrc = store->query(src);
374 Contact cdest = store->query(dest);
375 if (csrc.isValid()&&cdest.isValid()) {
376 bool srcTopic = (csrc.getCarrier()=="topic");
377 bool destTopic = (cdest.getCarrier()=="topic");
378 if (!(srcTopic||destTopic)) {
380 "++> check connection %s %s",
381 srcFull.c_str(),
382 destFull.c_str());
384 }
385 }
386 if (mode!="") {
387 std::string mode_name = mode;
388 if (mode_name=="from") {
389 if (!csrc.isValid()) {
390 removeSubscription(src,dest);
391 }
392 } else if (mode_name=="to") {
393 if (!cdest.isValid()) {
394 removeSubscription(src,dest);
395 }
396 }
397 }
398 }
399 return false;
400}
401
402
404 const std::string& src, const std::string& dest,
405 const std::string& srcFull,
406 const std::string& destFull,
407 const std::string& mode) {
409 "--- Checking %s %s / %s %s",
410 src.c_str(),
411 dest.c_str(),
412 srcFull.c_str(),
413 destFull.c_str());
414 NameStore *store = getStore();
415 if (store != nullptr) {
416 bool srcDrop = std::string(dropper) == src;
417 Contact contact;
418 if (srcDrop) {
419 contact = store->query(src);
420 } else {
421 contact = store->query(dest);
422 }
423 if (contact.isValid()) {
425 "--> check connection %s %s",
426 srcFull.c_str(),
427 destFull.c_str());
429 }
430 if (mode!="") {
431 std::string mode_name = mode;
432 if (mode_name=="from") {
433 if (srcDrop) {
434 removeSubscription(src,dest);
435 }
436 } else if (mode_name=="to") {
437 if (!srcDrop) {
438 removeSubscription(src,dest);
439 }
440 }
441 }
442 }
443 return false;
444}
445
446
447
448bool SubscriberOnSql::listSubscriptions(const std::string& port,
449 yarp::os::Bottle& reply) {
450 mutex.lock();
451 sqlite3_stmt *statement = nullptr;
452 char *query = nullptr;
453 if (std::string(port)!="") {
454 query = sqlite3_mprintf("SELECT s.srcFull, s.DestFull, EXISTS(SELECT topic FROM topics WHERE topic = s.src), EXISTS(SELECT topic FROM topics WHERE topic = s.dest), s.mode FROM subscriptions s WHERE s.src = %Q OR s.dest= %Q ORDER BY s.src, s.dest",port.c_str(),port.c_str());
455 } else {
456 query = sqlite3_mprintf("SELECT s.srcFull, s.destFull, EXISTS(SELECT topic FROM topics WHERE topic = s.src), EXISTS(SELECT topic FROM topics WHERE topic = s.dest), s.mode FROM subscriptions s ORDER BY s.src, s.dest");
457 }
458 yCDebug(SUBSCRIBERONSQL, "Query: %s", query);
459
460 int result = sqlite3_prepare_v2(SQLDB(implementation), query, -1, &statement, nullptr);
461 if (result!=SQLITE_OK) {
462 const char *msg = sqlite3_errmsg(SQLDB(implementation));
463 if (msg != nullptr) {
465 }
466 }
467 reply.addString("subscriptions");
468 while (result == SQLITE_OK && sqlite3_step(statement) == SQLITE_ROW) {
469 char *src = (char *)sqlite3_column_text(statement,0);
470 char *dest = (char *)sqlite3_column_text(statement,1);
473 char *mode = (char *)sqlite3_column_text(statement,4);
474 Bottle& b = reply.addList();
475 b.addString("subscription");
476 Bottle bsrc;
477 bsrc.addString("src");
478 bsrc.addString(src);
480 bdest.addString("dest");
481 bdest.addString(dest);
482 b.addList() = bsrc;
483 b.addList() = bdest;
484 if (mode != nullptr) {
485 if (mode[0]!='\0') {
487 bmode.addString("mode");
488 bmode.addString(mode);
489 b.addList() = bmode;
490 }
491 }
492 if (srcTopic||destTopic) {
494 btopic.addString("topic");
495 btopic.addInt32(srcTopic);
496 btopic.addInt32(destTopic);
497 b.addList() = btopic;
498 }
499 }
502 mutex.unlock();
503
504 return true;
505}
506
507
508bool SubscriberOnSql::setTopic(const std::string& port, const std::string& structure,
509 bool active) {
510 if (structure!="" || !active) {
511 mutex.lock();
512 char *query = sqlite3_mprintf("DELETE FROM topics WHERE topic = %Q",
513 port.c_str());
514 yCDebug(SUBSCRIBERONSQL, "Query: %s", query);
515
516 int result = sqlite3_exec(SQLDB(implementation), query, nullptr, nullptr, nullptr);
517 bool ok = true;
518 if (result!=SQLITE_OK) {
519 yCError(SUBSCRIBERONSQL, "Error in query");
520 ok = false;
521 }
523 mutex.unlock();
524 if (!ok) {
525 return false;
526 }
527 if (!active) {
528 return true;
529 }
530 }
531
532 bool have_topic = false;
533 if (structure=="") {
534 mutex.lock();
535 sqlite3_stmt *statement = nullptr;
536 char *query = nullptr;
537 query = sqlite3_mprintf("SELECT topic FROM topics WHERE topic = %Q",
538 port.c_str());
539 yCDebug(SUBSCRIBERONSQL, "Query: %s", query);
540
541 int result = sqlite3_prepare_v2(SQLDB(implementation), query, -1, &statement, nullptr);
542 if (result!=SQLITE_OK) {
543 yCError(SUBSCRIBERONSQL, "Error in query");
544 }
545 if (result == SQLITE_OK && sqlite3_step(statement) == SQLITE_ROW) {
546 have_topic = true;
547 }
550 mutex.unlock();
551 }
552
553 if (structure!="" || !have_topic) {
554 mutex.lock();
555 char *msg = nullptr;
556 const char *pstructure = structure.c_str();
557 if (structure == "") {
558 pstructure = nullptr;
559 }
560 char *query = sqlite3_mprintf("INSERT INTO topics (topic,structure) VALUES(%Q,%Q)",
561 port.c_str(),pstructure);
562 yCDebug(SUBSCRIBERONSQL, "Query: %s", query);
563
564 bool ok = true;
565 int result = sqlite3_exec(SQLDB(implementation), query, nullptr, nullptr, &msg);
566 if (result!=SQLITE_OK) {
567 ok = false;
568 if (msg != nullptr) {
571 }
572 }
574 mutex.unlock();
575 if (!ok) {
576 return false;
577 }
578 }
579
580 std::vector<std::vector<std::string> > subs;
581
582 // go ahead and connect anything needed
583 mutex.lock();
584 sqlite3_stmt *statement = nullptr;
585 char *query = sqlite3_mprintf("SELECT s1.src, s2.dest, s1.srcFull, s2.destFull FROM subscriptions s1, subscriptions s2, topics t WHERE (t.topic = %Q AND s1.dest = t.topic AND s2.src = t.topic)", port.c_str());
586 yCDebug(SUBSCRIBERONSQL, "Query: %s", query);
587
588 int result = sqlite3_prepare_v2(SQLDB(implementation), query, -1, &statement, nullptr);
589 if (result!=SQLITE_OK) {
590 const char *msg = sqlite3_errmsg(SQLDB(implementation));
591 if (msg != nullptr) {
593 }
594 }
595 while (result == SQLITE_OK &&
597 char *src = (char *)sqlite3_column_text(statement,0);
598 char *dest = (char *)sqlite3_column_text(statement,1);
599 char *srcFull = (char *)sqlite3_column_text(statement,2);
600 char *destFull = (char *)sqlite3_column_text(statement,3);
601 char *mode = (char *)sqlite3_column_text(statement,4);
602 std::vector<std::string> sub;
603 sub.emplace_back(src);
604 sub.emplace_back(dest);
605 sub.emplace_back(srcFull);
606 sub.emplace_back(destFull);
607 sub.emplace_back(mode?mode:"");
608 subs.push_back(sub);
609 }
612 mutex.unlock();
613
614 for (auto& sub : subs) {
615 checkSubscription(sub[0],sub[1],sub[2],sub[3],sub[4]);
616 }
617
618 return true;
619}
620
621
623 mutex.lock();
624 sqlite3_stmt *statement = nullptr;
625 char *query = nullptr;
626 query = sqlite3_mprintf("SELECT topic FROM topics");
627 yCDebug(SUBSCRIBERONSQL, "Query: %s", query);
628
629 int result = sqlite3_prepare_v2(SQLDB(implementation), query, -1, &statement, nullptr);
630 if (result!=SQLITE_OK) {
631 yCError(SUBSCRIBERONSQL, "Error in query");
632 }
633 while (result == SQLITE_OK && sqlite3_step(statement) == SQLITE_ROW) {
634 char *topic = (char *)sqlite3_column_text(statement,0);
635 topics.addString(topic);
636 }
639 mutex.unlock();
640
641 return true;
642}
643
644
645bool SubscriberOnSql::setType(const std::string& family,
646 const std::string& structure,
647 const std::string& value) {
648 mutex.lock();
649 char *msg = nullptr;
650 char *query = sqlite3_mprintf("INSERT OR REPLACE INTO structures (name,%Q) VALUES(%Q,%Q)",
651 family.c_str(),
652 (structure=="") ? nullptr : structure.c_str(),
653 value.c_str());
654 yCDebug(SUBSCRIBERONSQL, "Query: %s", query);
655
656 bool ok = true;
657 int result = sqlite3_exec(SQLDB(implementation), query, nullptr, nullptr, &msg);
658 if (result!=SQLITE_OK) {
659 ok = false;
660 if (msg != nullptr) {
663 }
664 }
666 mutex.unlock();
667 return ok;
668}
669
670std::string SubscriberOnSql::getType(const std::string& family,
671 const std::string& structure) {
672 mutex.lock();
673 sqlite3_stmt *statement = nullptr;
674 char *query = nullptr;
675 query = sqlite3_mprintf("SELECT %s FROM structures WHERE name = %Q",
676 family.c_str(), structure.c_str());
677 yCDebug(SUBSCRIBERONSQL, "Query: %s", query);
678
679 int result = sqlite3_prepare_v2(SQLDB(implementation), query, -1, &statement, nullptr);
680 std::string sresult;
681 if (result!=SQLITE_OK) {
682 yCError(SUBSCRIBERONSQL, "Error in query");
683 }
684 if (result == SQLITE_OK && sqlite3_step(statement) == SQLITE_ROW) {
685 sresult = (const char *)sqlite3_column_text(statement,0);
686 }
689 mutex.unlock();
690
691 return sresult;
692}
FeatureMode mode
#define SQLDB(x)
#define F_OK
yarp::os::Contact query(const std::string &name) override
Definition NameService.h:40
A simple collection of objects that can be described and transmitted in a portable way.
Definition Bottle.h:64
Bottle & addList()
Places an empty nested list in the bottle, at the end of the list.
Definition Bottle.cpp:188
void addString(const char *str)
Places a string in the bottle, at the end of the list.
Definition Bottle.cpp:176
A mini-server for performing network communication in the background.
Represents how to reach a part of a YARP network.
Definition Contact.h:33
bool isValid() const
Checks if a Contact is tagged as valid.
Definition Contact.cpp:298
Abstract interface for a database of port names.
Definition NameStore.h:19
virtual Contact query(const std::string &name)=0
bool checkSubscription(const std::string &src, const std::string &dest, const std::string &srcFull, const std::string &destFull, const std::string &mode)
bool removeSubscription(const std::string &src, const std::string &dest) override
bool open(const std::string &filename, bool fresh=false)
bool hookup(const std::string &port)
bool welcome(const std::string &port, int activity) override
bool breakSubscription(const std::string &dropper, const std::string &src, const std::string &dest, const std::string &srcFull, const std::string &destFull, const std::string &mode)
bool addSubscription(const std::string &src, const std::string &dest, const std::string &mode) override
bool listSubscriptions(const std::string &port, yarp::os::Bottle &reply) override
std::string getType(const std::string &family, const std::string &structure) override
bool breakdown(const std::string &port)
bool setTopic(const std::string &port, const std::string &structure, bool active) override
bool listTopics(yarp::os::Bottle &topics) override
bool setType(const std::string &family, const std::string &structure, const std::string &value) override
void disconnect(const std::string &src, const std::string &dest, bool srcDrop)
Definition Subscriber.h:54
yarp::os::NameStore * getStore()
Definition Subscriber.h:38
void connect(const std::string &src, const std::string &dest)
Definition Subscriber.h:48
#define yCError(component,...)
#define yCWarning(component,...)
#define yCDebug(component,...)
#define YARP_SERVERSQL_LOG_COMPONENT(name, name_string)
An interface to the operating system, including Port based communication.