YARP
Yet Another Robot Platform
ConnectThread.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  * Copyright (C) 2006-2010 RobotCub Consortium
4  * All rights reserved.
5  *
6  * This software may be modified and distributed under the terms of the
7  * BSD-3-Clause license. See the accompanying LICENSE file for details.
8  */
9 
12 
13 #include <yarp/os/Network.h>
14 
16 
17 namespace {
18 YARP_SERVERSQL_LOG_COMPONENT(CONNECTTHREAD, "yarp.serversql.impl.ConnectThread")
19 } // namespace
20 
21 
22 ConnectThread::ConnectThread(std::mutex& mutex) : mutex(mutex)
23 {
24 }
25 
27 {
28  do {
29  mutex.lock();
30  if (ct==0) {
31  needed = false;
32  }
33  ct--;
34  mutex.unlock();
35 
36  yCTrace(CONNECTTHREAD,
37  " ]]] con %s %s / %d %d",
38  src.c_str(),
39  dest.c_str(),
40  ct,
41  needed);
42  if (!needed) { break; }
43  if (positive) {
45  yCTrace(CONNECTTHREAD,
46  " (((Trying to connect %s and %s)))",
47  src.c_str(),
48  dest.c_str());
50  }
51  } else {
53  yCTrace(CONNECTTHREAD,
54  " (((Trying to disconnect %s and %s)))\n",
55  src.c_str(),
56  dest.c_str());
58  }
59  }
60  } while (true);
61 }
yarp::serversql::impl::ConnectThread
Definition: ConnectThread.h:22
Network.h
YARP_SERVERSQL_LOG_COMPONENT
#define YARP_SERVERSQL_LOG_COMPONENT(name, name_string)
Definition: LogComponent.h:37
yarp::serversql::impl::ConnectThread::positive
bool positive
Definition: ConnectThread.h:25
yarp::serversql::impl::ConnectThread::dest
std::string dest
Definition: ConnectThread.h:30
yarp::serversql::impl::ConnectThread::needed
bool needed
Definition: ConnectThread.h:24
ConnectThread.h
yarp::serversql::impl::ConnectThread::ct
int ct
Definition: ConnectThread.h:26
yarp::serversql::impl::ConnectThread::mutex
std::mutex & mutex
Definition: ConnectThread.h:27
LogComponent.h
yarp::serversql::impl::ConnectThread::src
std::string src
Definition: ConnectThread.h:29
yarp::os::NetworkBase::connect
static bool connect(const std::string &src, const std::string &dest, const std::string &carrier="", bool quiet=true)
Request that an output port connect to an input port.
Definition: Network.cpp:685
yarp::os::NetworkBase::isConnected
static bool isConnected(const std::string &src, const std::string &dest, bool quiet)
Check if a connection exists between two ports.
Definition: Network.cpp:730
yCTrace
#define yCTrace(component,...)
Definition: LogComponent.h:88
yarp::serversql::impl::ConnectThread::run
void run() override
Main body of the new thread.
Definition: ConnectThread.cpp:26
yarp::os::NetworkBase::disconnect
static bool disconnect(const std::string &src, const std::string &dest, bool quiet)
Request that an output port disconnect from an input port.
Definition: Network.cpp:703