TEST(Session, Works) { std::unique_ptr<OpcUa::Remote::Server> computer = OpcUa::Remote::Connect(GetEndpoint()); OpcUa::Remote::SessionParameters session; session.ClientDescription.Name.Text = "opcua client"; session.SessionName = "test"; session.EndpointURL = GetEndpoint(); session.Timeout = 1000; computer->CreateSession(session); computer->ActivateSession(); computer->CloseSession(); }
/** * Return true if position is at the end of the path */ bool CNavPath::IsAtEnd( const Vector &pos ) const { if (!IsValid()) return false; const float epsilon = 20.0f; return (pos - GetEndpoint()).IsLengthLessThan( epsilon ); }
const char* Socket::ToString(char s[ENDPOINT_STRING_SIZE]) { Endpoint endpoint; if (!GetEndpoint(endpoint)) return ""; return endpoint.ToString(s); }
bool MessageManager::RegisterCallback(int socketFD, Ticket &outTicket) { MessageEndpointLock endpointLock = GetEndpoint(socketFD); if(endpointLock.m_endpoint != NULL) { return endpointLock.m_endpoint->RegisterCallback(outTicket); } return false; }
void LegController<n_joints>::UpdateState(double time_elapsed, LegCommand<n_joints>* out_command) { // Update the state of the simulation current_time += time_elapsed; // Hold position if there is no controlled path if (path == NULL) { motion_complete = true; for (int i = 0; i < n_joints; i++) { out_command->joint_commands[i].angle = model->joints[i].Theta(); } return; } LegCommand<n_joints> command; // Clamp progress to 1.0 double progress = (current_time + time_elapsed)/deadline; if (progress > 1.0) { progress = 1.0; } // Get the next point in the path and attempt to head towards it. Eigen::Vector3d next_interpoint = path->Value(progress); double solved = GetJointCommands(next_interpoint, time_elapsed, &command); if (solved >= 0) { *out_command = command; infeasible = false; } else { infeasible = true; // Hold position for (int i = 0; i < n_joints; i++) { out_command->joint_commands[i].angle = model->joints[i].Theta(); } } if (!motion_complete && current_time >= deadline && (path->Value(1.0) - GetEndpoint()).squaredNorm() < destination_epsilon_squared) { motion_complete = true; } }
Message *MessageManager::ReadMessage(Ticket &ticket, int timeout) { //Read lock the Endpoint (so it can't get deleted from us while we're using it) MessageEndpointLock endpointLock = GetEndpoint(ticket.m_socketFD); if(endpointLock.m_endpoint == NULL) { return new ErrorMessage(ERROR_SOCKET_CLOSED); } Message *message = endpointLock.m_endpoint->PopMessage(ticket, timeout); if(message->m_messageType == ERROR_MESSAGE) { ErrorMessage *errorMessage = (ErrorMessage*)message; if(errorMessage->m_errorType == ERROR_SOCKET_CLOSED) { //TODO: Close the socket with libevent? } } return message; }
FollowUp ListeningSocket::Perform (const Notification & n) { FollowUp retr; if (do_shutdown) { retr.Remove=true; return retr; } for (;;) { struct sockaddr_storage addr; socklen_t len=sizeof(addr); auto socket=accept( this->socket, reinterpret_cast<struct sockaddr *>(&addr), &len ); // Check for failure if (socket==-1) { // Was the failure just because // the operation would block? if (WouldBlock()) break; // Were we interrupted? if (WasInterrupted()) continue; // Actually an error Raise(); } // Increment statistic ++retr.Accepted; auto ep=GetEndpoint(&addr); SmartPointer<Connection> conn; try { conn=SmartPointer<Connection>::Make( socket, ep.IP, ep.Port, this->ep.IP, this->ep.Port, this->ep.Receive, this->ep.Disconnect ); } catch (...) { // Make sure the socket gets // closed close(socket); throw; } // Fire off a callback to handle this // incoming connections #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wpedantic" retr.Action.Add([ this, conn=std::move(conn), socket ] (SmartPointer<ChannelBase> channel) mutable { FollowUp f; // Should this connection be allowed? if (this->ep.Accept) { try { // If the connection is not admitted, // return at once, the connection will // automatically be dropped by the Socket // RAII container if (!this->ep.Accept(AcceptEvent{ conn->IP(), conn->Port(), this->ep.IP, this->ep.Port })) return f; } catch (...) { // Consider throwing the same thing // as returning false return f; } } // The connection is allowed ++f.Incoming; // Fire the connect handler if (this->ep.Connect) { ConnectEvent event; event.Conn=conn; try { this->ep.Connect(std::move(event)); // Ignore user exceptions } catch (...) { } } // Add the connection f.Add=Channel{ socket, std::move(conn).Convert<ChannelBase>() }; return f; }); #pragma GCC diagnostic pop } return retr; }