From 477da952f98dda785c3a729dd297decc0503bb7f Mon Sep 17 00:00:00 2001 From: Matt Ranostay Date: Mon, 11 Nov 2019 00:48:02 -0800 Subject: poi-yelp: change to libqtappfw navigation interface Switch from DBus interface to rewritten agl-service-nagivation binding via the libqtappfw wrapper interface. Bug-AGL: SPEC-2880 Change-Id: I4244de4db250af438dda6b6173940f6a49fe34f2 Signed-off-by: Matt Ranostay --- CMakeLists.txt | 7 ++-- MainApp.cpp | 119 +++------------------------------------------------------ MainApp.h | 13 +++---- config.xml.in | 2 +- main.cpp | 19 +++++---- 5 files changed, 25 insertions(+), 135 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1fd1cd0..dd6be29 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,21 +25,20 @@ pkg_check_modules(QT5_CORE REQUIRED Qt5Core) pkg_check_modules(JSON REQUIRED json-c) pkg_check_modules(QT5_WIDGETS REQUIRED Qt5Widgets) pkg_check_modules(QT5_NETWORK REQUIRED Qt5Network) -pkg_check_modules(AGL_NAVIAPI REQUIRED libnaviapi-agl) -pkg_check_modules(AFBWSC REQUIRED libafbwsc) +pkg_check_modules(QTAPPFW REQUIRED qtappfw) pkg_check_modules(QLIBWIN REQUIRED qlibwindowmanager) pkg_check_modules(LIBHS REQUIRED libhomescreen) -include_directories( ${PROJECT_SOURCE_DIR}/ ${AFBWSC_INCLUDE_DIRS} ${AGL_NAVIAPI_INCLUDE_DIRS} ${QT5_CORE_INCLUDE_DIRS} ${QT5_WIDGETS_INCLUDE_DIRS} ${QT5_NETWORK_INCLUDE_DIRS} ${JSON_INCLUDE_DIRS} ${QLIBWIN_INCLUDE_DIRS} ${LIBHS_INCLUDE_DIRS} ) +include_directories( ${PROJECT_SOURCE_DIR}/ ${QTAPPFW_INCLUDE_DIRS} ${QT5_CORE_INCLUDE_DIRS} ${QT5_WIDGETS_INCLUDE_DIRS} ${QT5_NETWORK_INCLUDE_DIRS} ${JSON_INCLUDE_DIRS} ${QLIBWIN_INCLUDE_DIRS} ${LIBHS_INCLUDE_DIRS} ) qt5_wrap_cpp(yelp_client_SRC MainApp.h InfoPanelLabel.h ClickableLabel.h Keyboard.h) QT5_ADD_RESOURCES(yelp_client_QRC yelp-client.qrc) add_executable( yelp-client main.cpp MainApp.cpp InfoPanel.cpp InfoPanelLabel.cpp Keyboard.cpp yelp-client.qrc ${yelp_client_SRC} ${yelp_client_QRC}) #target_link_libraries( yelp-client binderclient ) -target_link_libraries( yelp-client ${AFBWSC_LIBRARIES} ${AGL_NAVIAPI_LIBRARIES} ${JSON_LIBRARIES} ${QLIBWIN_LIBRARIES} ${LIBHS_LIBRARIES} ) +target_link_libraries( yelp-client ${QTAPPFW_LIBRARIES} ${JSON_LIBRARIES} ${QLIBWIN_LIBRARIES} ${LIBHS_LIBRARIES} ) qt5_use_modules(yelp-client Core Widgets Network) install (TARGETS yelp-client DESTINATION bin) diff --git a/MainApp.cpp b/MainApp.cpp index 6689507..a75462a 100644 --- a/MainApp.cpp +++ b/MainApp.cpp @@ -50,13 +50,13 @@ using namespace std; -MainApp::MainApp():QMainWindow(Q_NULLPTR, Qt::FramelessWindowHint), +MainApp::MainApp(Navigation *navigation):QMainWindow(Q_NULLPTR, Qt::FramelessWindowHint), networkManager(this),searchBtn(QIcon(tr(":/images/loupe-90.png")), tr(""), this), lineEdit(this),keyboard(QRect(0, 688, COMPLETE_W_WITH_KB, 720), this), mutex(QMutex::Recursive),token(""),currentSearchingText(""),currentSearchedText(""), pSearchReply(NULL),pInfoPanel(NULL),pResultList(NULL),currentLatitude(36.136261),currentLongitude(-115.151254), navicoreSession(0),currentIndex(0),fontId(-1),isInfoScreen(false), - isInputDisplayed(false),isKeyboard(false),isAglNavi(false) + isInputDisplayed(false),isKeyboard(false),isAglNavi(false), naviapi(navigation) { //this->setAttribute(Qt::WA_TranslucentBackground); this->setStyleSheet("border: none;"); @@ -115,8 +115,6 @@ MainApp::MainApp():QMainWindow(Q_NULLPTR, Qt::FramelessWindowHint), isAglNavi = true; connect(this, SIGNAL(positionGotSignal()), this, SLOT(positionGot())); - connect(this, SIGNAL(allRoutesGotSignal()), this, SLOT(allRoutesGot())); - connect(this, SIGNAL(routeCreatedSignal()), this, SLOT(routeCreated())); this->setGeometry(QRect(this->pos().x(), this->pos().y(), COMPLETE_W_WITH_KB, COMPLETE_H_WITH_KB)); this->setStyleSheet("background-image: url(:/images/AGL_POI_Background.png);"); @@ -275,11 +273,7 @@ void MainApp::textChanged(const QString & text) } this->currentSearchingText = text; - /* we need to know our current position */ - std::vector Params; - Params.push_back(naviapi::NAVICORE_LONGITUDE); - Params.push_back(naviapi::NAVICORE_LATITUDE); - naviapi.getPosition(Params); + emit positionGotSignal(); mutex.unlock(); } @@ -578,7 +572,7 @@ void MainApp::SetDestination(int index) this->destinationLatitude = Businesses[index].Latitude; this->destinationLongitude = Businesses[index].Longitude; - naviapi.getAllRoutes(); + SetWayPoints(0); mutex.unlock(); } @@ -766,18 +760,6 @@ bool MainApp::IsCoordinatesConsistent(Business & business) } /* end of workaround */ -bool MainApp::CheckNaviApi(int argc, char *argv[]) -{ - bool ret = naviapi.connect(argc, argv, this); - - if (ret == true) - { - naviapi.getAllSessions(); - } - - return ret; -} - int MainApp::AuthenticatePOI(const QString & CredentialsFile) { char buf[512]; @@ -899,12 +881,7 @@ int MainApp::StartMonitoringUserInput() void MainApp::SetWayPoints(uint32_t myRoute) { /* set the destination : */ - naviapi::Waypoint destWp(this->destinationLatitude, this->destinationLongitude); - std::vector myWayPoints; - myWayPoints.push_back(destWp); - naviapi.setWaypoints(navicoreSession, myRoute, true, myWayPoints); - - naviapi.calculateRoute(navicoreSession, myRoute); + naviapi->sendWaypoint(this->destinationLatitude, this->destinationLongitude); /* reset search: */ currentSearchingText = tr(""); @@ -946,60 +923,6 @@ void MainApp::getAllSessions_reply(const std::map< uint32_t, std::string >& allS mutex.unlock(); } - -void MainApp::getPosition_reply(std::map< int32_t, naviapi::variant > position) -{ - mutex.lock(); - - std::map< int32_t, naviapi::variant >::iterator it; - for (it = position.begin(); it != position.end(); it++) - { - if (it->first == naviapi::NAVICORE_LATITUDE) - { - currentLatitude = it->second._double; - } - else if (it->first == naviapi::NAVICORE_LONGITUDE) - { - currentLongitude = it->second._double; - } - } - - TRACE_INFO("Current position: %f, %f", currentLatitude, currentLongitude); - - mutex.unlock(); - - emit positionGotSignal(); -} - -void MainApp::getAllRoutes_reply(std::vector< uint32_t > allRoutes) -{ - mutex.lock(); - - uint32_t routeHandle = 0; - - if (allRoutes.size() != 0) - { - routeHandle = allRoutes[0]; - } - - this->currentRouteHandle = routeHandle; - - mutex.unlock(); - - emit allRoutesGotSignal(); -} - -void MainApp::createRoute_reply(uint32_t routeHandle) -{ - mutex.lock(); - - this->currentRouteHandle = routeHandle; - - mutex.unlock(); - - emit routeCreatedSignal(); -} - void MainApp::positionGot() { mutex.lock(); @@ -1021,35 +944,3 @@ void MainApp::positionGot() mutex.unlock(); } - -void MainApp::allRoutesGot() -{ - mutex.lock(); - - /* check if a route already exists, if not create it : */ - if (this->currentRouteHandle == 0) - { - naviapi.createRoute(navicoreSession); - } - else - { - naviapi.pauseSimulation(navicoreSession); - naviapi.setSimulationMode(navicoreSession, false); - naviapi.cancelRouteCalculation(navicoreSession, this->currentRouteHandle); - sleep(1); - - SetWayPoints(this->currentRouteHandle); - } - - mutex.unlock(); -} - -void MainApp::routeCreated() -{ - mutex.lock(); - - SetWayPoints(this->currentRouteHandle); - - mutex.unlock(); -} - diff --git a/MainApp.h b/MainApp.h index 66defee..7d0b9de 100644 --- a/MainApp.h +++ b/MainApp.h @@ -12,16 +12,15 @@ #include "InfoPanel.h" #include "Keyboard.h" -#include +#include -class MainApp: public QMainWindow, public naviapi::NavicoreListener +class MainApp: public QMainWindow { Q_OBJECT public: - explicit MainApp(); + explicit MainApp(Navigation *navigation); ~MainApp(); - bool CheckNaviApi(int argc, char *argv[]); int AuthenticatePOI(const QString & CredentialsFile); int StartMonitoringUserInput(); void setInfoScreen(bool val) { isInfoScreen = val; } @@ -39,7 +38,7 @@ class MainApp: public QMainWindow, public naviapi::NavicoreListener int FillResultList(std::vector & list, int focusIndex = 0); void SetWayPoints(uint32_t myRoute); - naviapi::Navicore naviapi; + Navigation *naviapi; QNetworkAccessManager networkManager; QPushButton searchBtn; QLineEdit lineEdit; @@ -68,7 +67,7 @@ class MainApp: public QMainWindow, public naviapi::NavicoreListener public: void getAllSessions_reply(const std::map< uint32_t, std::string >& allSessions); - void getPosition_reply(std::map< int32_t, naviapi::variant > position); + //void getPosition_reply(std::map< int32_t, naviapi::variant > position); void getAllRoutes_reply(std::vector< uint32_t > allRoutes); void createRoute_reply(uint32_t routeHandle); @@ -84,8 +83,6 @@ class MainApp: public QMainWindow, public naviapi::NavicoreListener void cancelClicked(); void positionGot(); - void allRoutesGot(); - void routeCreated(); signals: void allSessionsGotSignal(); diff --git a/config.xml.in b/config.xml.in index bec206d..a20cdef 100644 --- a/config.xml.in +++ b/config.xml.in @@ -6,7 +6,7 @@ POI App AISIN AW - + diff --git a/main.cpp b/main.cpp index 77e910f..2f360f3 100644 --- a/main.cpp +++ b/main.cpp @@ -6,6 +6,7 @@ #include #include +#include #define DEFAULT_CREDENTIALS_FILE "/etc/poikey" @@ -40,6 +41,15 @@ int main(int argc, char *argv[], char *env[]) QString secret = QString(argv[2]); std::string token = secret.toStdString(); + QUrl bindingAddress; + bindingAddress.setScheme(QStringLiteral("ws")); + bindingAddress.setHost(QStringLiteral("localhost")); + bindingAddress.setPort(port); + bindingAddress.setPath(QStringLiteral("/api")); + QUrlQuery query; + query.addQueryItem(QStringLiteral("token"), secret); + bindingAddress.setQuery(query); + if (qwm->init(port, secret) != 0) { exit(EXIT_FAILURE); } @@ -51,7 +61,7 @@ int main(int argc, char *argv[], char *env[]) qwm->set_event_handler(QLibWindowmanager::Event_SyncDraw, SyncDrawHandler); - mainapp = new MainApp(); + mainapp = new MainApp(new Navigation(bindingAddress)); hs->init(port, token.c_str()); @@ -61,13 +71,6 @@ int main(int argc, char *argv[], char *env[]) mainapp->setInfoScreen(true); mainapp->setKeyboard(true); - /* check naviapi */ - if (mainapp->CheckNaviApi(argc, argv) == false) - { - cerr << "Error: naviapi check failed" << endl; - return -1; - } - /* then, authenticate connexion to POI service: */ if (mainapp->AuthenticatePOI(credentialsFile) < 0) { -- cgit 1.2.3-korg