21#define access(f,a) _access(f,a)
31#define SQLDB(x) ((sqlite3*)(x))
44 int result = access(filename.c_str(),
F_OK);
65 id INTEGER PRIMARY KEY,\n\
95 const char *
add_structure =
"ALTER TABLE subscriptions ADD COLUMN mode";
105 id INTEGER PRIMARY KEY,\n\
133 const char *
add_structure =
"ALTER TABLE topics ADD COLUMN structure";
143 id INTEGER PRIMARY KEY,\n\
155 name TEXT PRIMARY KEY,\n\
171 if (implementation !=
nullptr) {
172 auto* db = (
sqlite3 *)implementation;
174 implementation =
nullptr;
180 const std::string& dest,
181 const std::string& mode) {
186 if (
psrc.getCarrier()==
"topic") {
189 if (
pdest.getCarrier()==
"topic") {
193 const char *
zmode = mode.c_str();
197 char *
query =
sqlite3_mprintf(
"INSERT INTO subscriptions (src,dest,srcFull,destFull,mode) VALUES(%Q,%Q,%Q,%Q,%Q)",
198 psrc.getPortName().c_str(),
199 pdest.getPortName().c_str(),
209 if (msg !=
nullptr) {
216 if (
psrc.getCarrier()!=
"topic") {
217 if (
pdest.getCarrier()!=
"topic") {
227 if (
pdest.getCarrier()!=
"topic") {
236 const std::string& dest) {
241 psrc.getPortName().c_str(),
242 pdest.getPortName().c_str());
265 if (store !=
nullptr) {
287 query =
sqlite3_mprintf(
"DELETE FROM live WHERE name=%Q AND stamp < DATETIME('now','-30 seconds')",
301 if (msg !=
nullptr) {
326 char *
query =
nullptr;
328 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());
335 if (msg !=
nullptr) {
364 char *
query =
nullptr;
366 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());
372 if (msg !=
nullptr) {
395 const std::string& mode) {
406 "+++ Checking %s %s / %s %s",
413 if (store !=
nullptr) {
421 "++> check connection %s %s",
430 if (!
csrc.isValid()) {
434 if (!
cdest.isValid()) {
445 const std::string& src,
const std::string& dest,
448 const std::string& mode) {
459 "--- Checking %s %s / %s %s",
465 if (store !=
nullptr) {
469 contact = store->
query(src);
471 contact = store->
query(dest);
475 "--> check connection %s %s",
502 char *
query =
nullptr;
503 if (std::string(port)!=
"") {
504 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());
506 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");
513 if (msg !=
nullptr) {
527 bsrc.addString(
"src");
530 bdest.addString(
"dest");
531 bdest.addString(dest);
534 if (mode !=
nullptr) {
537 bmode.addString(
"mode");
538 bmode.addString(mode);
544 btopic.addString(
"topic");
586 char *
query =
nullptr;
618 if (msg !=
nullptr) {
630 std::vector<std::vector<std::string> >
subs;
635 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());
641 if (msg !=
nullptr) {
652 std::vector<std::string>
sub;
653 sub.emplace_back(src);
654 sub.emplace_back(dest);
657 sub.emplace_back(mode?mode:
"");
675 char *
query =
nullptr;
697 const std::string& value) {
710 if (msg !=
nullptr) {
724 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.