bool MonavRunnerPrivate::retrieveData( const RouteRequest *route, const QString &mapDir, RoutingResult* reply ) const { QLocalSocket socket; socket.connectToServer( "MoNavD" ); if ( socket.waitForConnected() ) { if ( m_plugin->monavVersion() == MonavPlugin::Monav_0_3 ) { CommandType commandType; commandType.value = CommandType::RoutingCommand; commandType.post( &socket ); } RoutingCommand command; QVector<Node> waypoints; for ( int i = 0; i < route->size(); ++i ) { Node coordinate; coordinate.longitude = route->at( i ).longitude( GeoDataCoordinates::Degree ); coordinate.latitude = route->at( i ).latitude( GeoDataCoordinates::Degree ); waypoints << coordinate; } command.dataDirectory = mapDir; command.lookupRadius = 1500; command.waypoints = waypoints; command.lookupStrings = true; command.post( &socket ); socket.flush(); if ( reply->read( &socket ) ) { switch ( reply->type ) { case RoutingResult::LoadFailed: mDebug() << "failed to load monav map from " << mapDir; return false; break; case RoutingResult::RouteFailed: mDebug() << "failed to retrieve route from monav daemon"; return false; break; case RoutingResult::TypeLookupFailed: mDebug() << "failed to lookup type from monav daemon"; return false; break; case RoutingResult::NameLookupFailed: mDebug() << "failed to lookup name from monav daemon"; return false; break; case RoutingResult::Success: return true; } } else { mDebug() << "Failed to read reply"; } } else { mDebug() << "No connection to MoNavD"; } return false; }
int main( int argc, char *argv[] ) { CommandType commandType; UnpackCommand unpackCommand; RoutingCommand routingCommand; routingCommand.lookupStrings = true; if ( !processArguments( &commandType, &unpackCommand, &routingCommand, argc, argv ) ) { qDebug() << "usage:" << argv[0] << "data-directory latitude1 longitude1 latitude2 longitude2 [...latitudeN longitudeN]"; qDebug() << "\tcomputes a route using between the specified waypoints"; qDebug() << "usage:" << argv[0] << "monav-map-module-file"; qDebug() << "\tunpacks a map module"; return 1; } QLocalSocket connection; connection.connectToServer( "MoNavD" ); if ( !connection.waitForConnected() ) { qDebug() << "failed to connect to daemon:" << connection.error(); return 2; } commandType.post( &connection ); if ( commandType.value == CommandType::UnpackCommand ) { unpackCommand.post( &connection ); connection.flush(); UnpackResult reply; reply.type = UnpackResult::FailUnpacking; reply.read( &connection ); qDebug() << connection.state(); if ( reply.type == UnpackResult::FailUnpacking ) { qDebug() << "failed to unpack map file"; return 3; } qDebug() << "finished unpacking map file"; return 0; } routingCommand.post( &connection ); connection.flush(); RoutingResult reply; reply.read( &connection ); qDebug() << connection.state(); if ( reply.type == RoutingResult::LoadFailed ) { qDebug() << "failed to load data directory"; return 3; } else if ( reply.type == RoutingResult::RouteFailed ) { qDebug() << "failed to compute route"; return 3; } else if ( reply.type == RoutingResult::NameLookupFailed ) { qDebug() << "failed to compute route"; return 3; } else if ( reply.type == RoutingResult::TypeLookupFailed ) { qDebug() << "failed to compute route"; return 3; }else if ( reply.type == RoutingResult::Success ) { int seconds = reply.seconds; qDebug() << "distance:" << seconds / 60 / 60 << "h" << ( seconds / 60 ) % 60 << "m" << seconds % 60 << "s"; qDebug() << "nodes:" << reply.pathNodes.size(); qDebug() << "edges:" << reply.pathEdges.size(); unsigned node = 0; for ( int i = 0; i < reply.pathEdges.size(); i++ ) { QString name = reply.nameStrings[reply.pathEdges[i].name]; QString type = reply.typeStrings[reply.pathEdges[i].type]; qDebug() << "name:" << name.toUtf8() << "type:" << type << "nodes:" << reply.pathEdges[i].length + 1 << "seconds:" << reply.pathEdges[i].seconds << "branching possible:" << reply.pathEdges[i].branchingPossible; for ( unsigned j = 0; j <= reply.pathEdges[i].length; j++ ) { QString latitude, longitude; latitude.setNum( reply.pathNodes[j + node].latitude, 'g', 10 ); longitude.setNum( reply.pathNodes[j + node].longitude, 'g', 10 ); qDebug() << latitude.toLatin1().data() << longitude.toLatin1().data(); } node += reply.pathEdges[i].length; } } else { qDebug() << "return value not recognized"; return 5; } }