20#define access(f,a) _access(f,a)
30#define SQLDB(x) ((sqlite3*)(x))
43 int result = access(filename.c_str(),
F_OK);
64 id INTEGER PRIMARY KEY,\n\
94 const char *
add_structure =
"ALTER TABLE subscriptions ADD COLUMN mode";
104 id INTEGER PRIMARY KEY,\n\
132 const char *
add_structure =
"ALTER TABLE topics ADD COLUMN structure";
142 id INTEGER PRIMARY KEY,\n\
154 name TEXT PRIMARY KEY,\n\
170 if (implementation !=
nullptr) {
171 auto* db = (
sqlite3 *)implementation;
173 implementation =
nullptr;
179 const std::string& dest,
180 const std::string&
mode) {
185 if (
psrc.getCarrier()==
"topic") {
188 if (
pdest.getCarrier()==
"topic") {
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(),
208 if (
msg !=
nullptr) {
215 if (
psrc.getCarrier()!=
"topic") {
216 if (
pdest.getCarrier()!=
"topic") {
226 if (
pdest.getCarrier()!=
"topic") {
235 const std::string& dest) {
240 psrc.getPortName().c_str(),
241 pdest.getPortName().c_str());
267 query =
sqlite3_mprintf(
"DELETE FROM live WHERE name=%Q AND stamp < DATETIME('now','-30 seconds')",
281 if (
msg !=
nullptr) {
300 char *
query =
nullptr;
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());
309 if (
msg !=
nullptr) {
332 char *
query =
nullptr;
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());
340 if (
msg !=
nullptr) {
363 const std::string&
mode) {
365 "+++ Checking %s %s / %s %s",
372 if (store !=
nullptr) {
380 "++> check connection %s %s",
389 if (!
csrc.isValid()) {
393 if (!
cdest.isValid()) {
404 const std::string& src,
const std::string& dest,
407 const std::string&
mode) {
409 "--- Checking %s %s / %s %s",
415 if (store !=
nullptr) {
419 contact = store->
query(src);
421 contact = store->
query(dest);
425 "--> check connection %s %s",
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());
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");
463 if (
msg !=
nullptr) {
477 bsrc.addString(
"src");
480 bdest.addString(
"dest");
481 bdest.addString(dest);
484 if (
mode !=
nullptr) {
487 bmode.addString(
"mode");
494 btopic.addString(
"topic");
536 char *
query =
nullptr;
568 if (
msg !=
nullptr) {
580 std::vector<std::vector<std::string> >
subs;
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());
591 if (
msg !=
nullptr) {
602 std::vector<std::string>
sub;
603 sub.emplace_back(src);
604 sub.emplace_back(dest);
625 char *
query =
nullptr;
647 const std::string& value) {
660 if (
msg !=
nullptr) {
674 char *
query =
nullptr;
yarp::os::Contact query(const std::string &name) override
A simple collection of objects that can be described and transmitted in a portable way.
Bottle & addList()
Places an empty nested list in the bottle, at the end of the list.
void addString(const char *str)
Places a string in the bottle, at the end of the list.
A mini-server for performing network communication in the background.
Abstract interface for a database of port names.
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)
yarp::os::NameStore * getStore()
void connect(const std::string &src, const std::string &dest)
#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.