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());
262 if (
nc.getNestedName().size()>0) {
264 if (store !=
nullptr) {
286 query =
sqlite3_mprintf(
"DELETE FROM live WHERE name=%Q AND stamp < DATETIME('now','-30 seconds')",
300 if (
msg !=
nullptr) {
319 if (
nc.getNestedName().size()>0) {
325 char *
query =
nullptr;
327 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());
334 if (
msg !=
nullptr) {
357 if (
nc.getNestedName().size()>0) {
363 char *
query =
nullptr;
365 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());
371 if (
msg !=
nullptr) {
394 const std::string&
mode) {
397 if (
nc.getNestedName().size()>0) {
399 if (
nc.getNestedName().size()>0) {
405 "+++ Checking %s %s / %s %s",
412 if (store !=
nullptr) {
420 "++> check connection %s %s",
429 if (!
csrc.isValid()) {
433 if (!
cdest.isValid()) {
444 const std::string& src,
const std::string& dest,
447 const std::string&
mode) {
450 if (
nc.getNestedName().size()>0) {
452 if (
nc.getNestedName().size()>0) {
458 "--- Checking %s %s / %s %s",
464 if (store !=
nullptr) {
468 contact = store->
query(src);
470 contact = store->
query(dest);
474 "--> check connection %s %s",
501 char *
query =
nullptr;
502 if (std::string(port)!=
"") {
503 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());
505 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");
512 if (
msg !=
nullptr) {
526 bsrc.addString(
"src");
529 bdest.addString(
"dest");
530 bdest.addString(dest);
533 if (
mode !=
nullptr) {
536 bmode.addString(
"mode");
543 btopic.addString(
"topic");
585 char *
query =
nullptr;
617 if (
msg !=
nullptr) {
629 std::vector<std::vector<std::string> >
subs;
634 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());
640 if (
msg !=
nullptr) {
651 std::vector<std::string>
sub;
652 sub.emplace_back(src);
653 sub.emplace_back(dest);
674 char *
query =
nullptr;
696 const std::string& value) {
709 if (
msg !=
nullptr) {
723 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.
An abstract name space for ports.
virtual Contact unregisterAdvanced(const std::string &name, NameStore *store)
Remove contact information, with access to the contact information of other ports for cross-referenci...
virtual Contact registerAdvanced(const Contact &contact, NameStore *store)
Record contact information, with access to the contact information of other ports for cross-referenci...
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()
yarp::os::NameSpace * getDelegate()
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.