MCPcopy Create free account
hub / github.com/BehaviorTree/Groot / on_Connect

Method on_Connect

bt_editor/sidepanel_monitor.cpp:155–213  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

153}
154
155void SidepanelMonitor::on_Connect()
156{
157 if( !_connected)
158 {
159 QString address = ui->lineEdit->text();
160 if( address.isEmpty() )
161 {
162 address = ui->lineEdit->placeholderText();
163 ui->lineEdit->setText(address);
164 }
165 bool failed = false;
166 if( !address.isEmpty() )
167 {
168 _connection_address_pub = "tcp://" + address.toStdString() + std::string(":1666");
169 _connection_address_req = "tcp://" + address.toStdString() + std::string(":1667");
170 try{
171 _zmq_subscriber.connect( _connection_address_pub.c_str() );
172
173 int timeout_ms = 1;
174 _zmq_subscriber.setsockopt(ZMQ_SUBSCRIBE, "", 0);
175 _zmq_subscriber.setsockopt(ZMQ_RCVTIMEO,&timeout_ms, sizeof(int) );
176
177 if( !getTreeFromServer() )
178 {
179 failed = true;
180 _connected = false;
181 }
182 }
183 catch(zmq::error_t& err)
184 {
185 failed = true;
186 }
187 }
188 else {
189 failed = true;
190 }
191
192 if( !failed )
193 {
194 _connected = true;
195 ui->lineEdit->setDisabled(true);
196 _timer->start(20);
197 connectionUpdate(true);
198 }
199 else{
200 QMessageBox::warning(this,
201 tr("ZeroMQ connection"),
202 tr("Was not able to connect to [%1]\n").arg(_connection_address_pub.c_str()),
203 QMessageBox::Close);
204 }
205 }
206 else{
207 _connected = false;
208 ui->lineEdit->setDisabled(false);
209 _timer->stop();
210
211 connectionUpdate(false);
212 }

Callers 1

clearMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected