diff options
author | Scott Murray <scott.murray@konsulko.com> | 2019-08-30 11:40:23 -0400 |
---|---|---|
committer | Scott Murray <scott.murray@konsulko.com> | 2019-09-05 00:18:27 +0000 |
commit | da9d177514fe438edd8262226cdc770df6c9eb82 (patch) | |
tree | e33d2af8d2e129b372caf34afac37366b641553a /libnavi/include | |
parent | dd61aa309b3a082488c9d3c383c1601fd3efbc2a (diff) |
Initial check in
Initial check in of contents of the original repository:
git://github.com/AGLExport/agl-service-navigation
as of commit 1f1ffc92fcc882aa5e885badbc91a3384f5d77b1.
Bug-AGL: SPEC-2787
Signed-off-by: Scott Murray <scott.murray@konsulko.com>
Change-Id: I02d008ee73cdfd88f1e7587ee57101187b9c4d6d
(cherry picked from commit f14ecdd52975ae365af5ed32648bf55dddacb8d9)
Diffstat (limited to 'libnavi/include')
-rw-r--r-- | libnavi/include/BinderClient.h | 57 | ||||
-rw-r--r-- | libnavi/include/JsonRequestGenerator.h | 29 | ||||
-rw-r--r-- | libnavi/include/JsonResponseAnalyzer.h | 25 | ||||
-rw-r--r-- | libnavi/include/RequestManage.h | 64 | ||||
-rw-r--r-- | libnavi/include/RequestManageListener.h | 17 | ||||
-rw-r--r-- | libnavi/include/libnavicore.hpp | 69 | ||||
-rw-r--r-- | libnavi/include/traces.h | 38 |
7 files changed, 299 insertions, 0 deletions
diff --git a/libnavi/include/BinderClient.h b/libnavi/include/BinderClient.h new file mode 100644 index 0000000..70a6558 --- /dev/null +++ b/libnavi/include/BinderClient.h @@ -0,0 +1,57 @@ +// Copyright 2017 AISIN AW CO.,LTD + +#pragma once + +#include <map> +#include <tuple> +#include <vector> +#include <string> + +#include "libnavicore.hpp" + +#include "RequestManageListener.h" +#include "RequestManage.h" + +#define API_NAME "naviapi" + +/** + * @brief API name + */ +#define VERB_GETPOSITION "navicore_getposition" +#define VERB_GETALLROUTES "navicore_getallroutes" +#define VERB_CREATEROUTE "navicore_createroute" +#define VERB_PAUSESIMULATION "navicore_pausesimulation" +#define VERB_SETSIMULATIONMODE "navicore_setsimulationmode" +#define VERB_CANCELROUTECALCULATION "navicore_cancelroutecalculation" +#define VERB_SETWAYPOINTS "navicore_setwaypoints" +#define VERB_CALCULATEROUTE "navicore_calculateroute" +#define VERB_GETALLSESSIONS "navicore_getallsessions" + +/** + * @brief Binder client class + */ +class BinderClient : public RequestManageListener +{ +public: + BinderClient(); + ~BinderClient(); + + bool ConnectServer(std::string url , naviapi::NavicoreListener* listener); + void NavicoreGetPosition(const std::vector< int32_t >& valuesToReturn); + void NavicoreGetAllRoutes(); + void NavicoreCreateRoute(const uint32_t& sessionHandle); + void NavicorePauseSimulation(const uint32_t& sessionHandle); + void NavicoreSetSimulationMode(const uint32_t& sessionHandle, const bool& activate); + void NavicoreCancelRouteCalculation(const uint32_t& sessionHandle, const uint32_t& routeHandle); + void NavicoreSetWaypoints(const uint32_t& sessionHandle, const uint32_t& routeHandle, const bool& startFromCurrentPosition, const std::vector<naviapi::Waypoint>& waypointsList); + void NavicoreCalculateRoute(const uint32_t& sessionHandle, const uint32_t& routeHandle); + void NavicoreGetAllSessions(); + +private: + void OnReply(struct json_object *reply); + +private: + naviapi::NavicoreListener* navicoreListener; + RequestManage* requestMng; +}; + diff --git a/libnavi/include/JsonRequestGenerator.h b/libnavi/include/JsonRequestGenerator.h new file mode 100644 index 0000000..7cd6979 --- /dev/null +++ b/libnavi/include/JsonRequestGenerator.h @@ -0,0 +1,29 @@ +// Copyright 2017 AW SOFTWARE CO.,LTD +// Copyright 2017 AISIN AW CO.,LTD + +#pragma once + +#include <stdint.h> +#include <string> +#include <vector> + +#include "libnavicore.hpp" + +/** +* @brief Class for generating Json request +*/ +class JsonRequestGenerator +{ +public: + static std::string CreateRequestGetPosition(const std::vector< int32_t >& valuesToReturn); + static std::string CreateRequestGetAllRoutes(); + static std::string CreateRequestCreateRoute(const uint32_t* sessionHandle); + static std::string CreateRequestPauseSimulation(const uint32_t* sessionHandle); + static std::string CreateRequestSetSimulationMode(const uint32_t* sessionHandle, const bool* activate); + static std::string CreateRequestCancelRouteCalculation(const uint32_t* sessionHandle, const uint32_t* routeHandle); + static std::string CreateRequestSetWaypoints(const uint32_t* sessionHandle, const uint32_t* routeHandle, + const bool* startFromCurrentPosition, const std::vector<naviapi::Waypoint>* waypointsList); + static std::string CreateRequestCalculateroute(const uint32_t* sessionHandle, const uint32_t* routeHandle); + static std::string CreateRequestGetAllSessions(); +}; + diff --git a/libnavi/include/JsonResponseAnalyzer.h b/libnavi/include/JsonResponseAnalyzer.h new file mode 100644 index 0000000..50b2cd2 --- /dev/null +++ b/libnavi/include/JsonResponseAnalyzer.h @@ -0,0 +1,25 @@ +// Copyright 2017 AW SOFTWARE CO.,LTD +// Copyright 2017 AISIN AW CO.,LTD + +#pragma once + +#include <json-c/json.h> +#include <stdint.h> +#include <string> +#include <vector> +#include <map> + +#include "libnavicore.hpp" + +/** +* @brief JSON response analysis class +*/ +class JsonResponseAnalyzer +{ +public: + static std::map< int32_t, naviapi::variant > AnalyzeResponseGetPosition( std::string& res_json ); + static std::vector< uint32_t > AnalyzeResponseGetAllRoutes( std::string& res_json ); + static uint32_t AnalyzeResponseCreateRoute( std::string& res_json ); + static std::map<uint32_t, std::string> AnalyzeResponseGetAllSessions( std::string& res_json ); +}; + diff --git a/libnavi/include/RequestManage.h b/libnavi/include/RequestManage.h new file mode 100644 index 0000000..05ffcdf --- /dev/null +++ b/libnavi/include/RequestManage.h @@ -0,0 +1,64 @@ +// Copyright 2017 AISIN AW CO.,LTD + +#pragma once + +#include <stdint.h> +#include <string> +#include <pthread.h> + +extern "C" { + #include <afb/afb-wsj1.h> + #include <afb/afb-ws-client.h> +} + +#include "RequestManageListener.h" + +/** +* @brief Class for request +*/ +class RequestManage +{ +public: + pthread_cond_t cond; + pthread_mutex_t mutex; + + struct afb_wsj1* wsj1; + std::string* requestURL; + struct afb_wsj1_itf wsj1_itf; + +private: + RequestManageListener* listener; + int request_cnt; + uint32_t sessionHandle; + uint32_t routeHandle; + + // Function called from thread + static void* BinderThread(void* param); + + // Callback function + void OnReply(struct afb_wsj1_msg *msg); + void OnHangup(struct afb_wsj1 *wsj1); + void OnCallStatic(const char *api, const char *verb, struct afb_wsj1_msg *msg); + void OnEventStatic(const char *event, struct afb_wsj1_msg *msg); + + static void OnReplyStatic(void *closure, struct afb_wsj1_msg *msg); + static void OnHangupStatic(void *closure, struct afb_wsj1 *wsj1); + static void OnCallStatic(void *closure, const char *api, const char *verb, struct afb_wsj1_msg *msg); + static void OnEventStatic(void *closure, const char *event, struct afb_wsj1_msg *msg); + +// ================================================================================================== +// public +// ================================================================================================== +public: + RequestManage(); + ~RequestManage(); + + bool Connect(const char* api_url, RequestManageListener* listener); + bool IsConnect(); + bool CallBinderAPI(const char *api, const char *verb, const char *object); + void SetSessionHandle(uint32_t session); + uint32_t GetSessionHandle(); + void SetRouteHandle(uint32_t route); + uint32_t GetRouteHandle(); +}; + diff --git a/libnavi/include/RequestManageListener.h b/libnavi/include/RequestManageListener.h new file mode 100644 index 0000000..3b0c932 --- /dev/null +++ b/libnavi/include/RequestManageListener.h @@ -0,0 +1,17 @@ +// Copyright 2017 AISIN AW CO.,LTD + +#pragma once + +#include <json-c/json.h> + +class RequestManageListener +{ +public: + RequestManageListener() { + } + virtual ~RequestManageListener() { + } + + virtual void OnReply(struct json_object *reply) = 0; +}; + diff --git a/libnavi/include/libnavicore.hpp b/libnavi/include/libnavicore.hpp new file mode 100644 index 0000000..66200d9 --- /dev/null +++ b/libnavi/include/libnavicore.hpp @@ -0,0 +1,69 @@ +// Copyright 2017 AISIN AW CO.,LTD + +#pragma once + +#include <map> +#include <string> +#include <tuple> +#include <vector> + +#include <stdint.h> + +namespace naviapi { + +static const uint32_t NAVICORE_TIMESTAMP = 0x0010; +static const uint32_t NAVICORE_LATITUDE = 0x00a0; +static const uint32_t NAVICORE_LONGITUDE = 0x00a1; +static const uint32_t NAVICORE_HEADING = 0x00a3; +static const uint32_t NAVICORE_SPEED = 0x00a4; +static const uint32_t NAVICORE_SIMULATION_MODE = 0x00e3; + +typedef union +{ + bool _bool; + int32_t _int32_t; + uint32_t _uint32_t; + double _double; +} variant; + +typedef std::tuple<double, double> Waypoint; + +class NavicoreListener +{ +public: + NavicoreListener(); + virtual ~NavicoreListener(); + + virtual void getAllSessions_reply(const std::map< uint32_t, std::string >& allSessions); + virtual void getPosition_reply(std::map< int32_t, variant > position); + virtual void getAllRoutes_reply(std::vector< uint32_t > allRoutes); + virtual void createRoute_reply(uint32_t routeHandle); +}; // class NavicoreListener + +class Navicore +{ +private: + NavicoreListener* mListener; + +public: + Navicore(); + virtual ~Navicore(); + + bool connect(int argc, char *argv[], NavicoreListener* listener); + void disconnect(); + + void getAllSessions(); + void getPosition(std::vector<int32_t> params); + void getAllRoutes(); + void createRoute(uint32_t session); + + void pauseSimulation(uint32_t session); + void setSimulationMode(uint32_t session, bool activate); + void cancelRouteCalculation(uint32_t session, uint32_t routeHandle); + void setWaypoints(uint32_t session, uint32_t routeHandle, bool flag, std::vector<Waypoint>); + void calculateRoute(uint32_t session, uint32_t routeHandle); + +}; // class Navicore + +}; // namespace naviapi + diff --git a/libnavi/include/traces.h b/libnavi/include/traces.h new file mode 100644 index 0000000..a1f96ec --- /dev/null +++ b/libnavi/include/traces.h @@ -0,0 +1,38 @@ +// Copyright 2017 AISIN AW CO.,LTD + +#ifndef __TRACE_H__ +#define __TRACE_H__ + +#include <stdio.h> + +#define BLACK "\033[30m" +#define RED "\033[31m" +#define GREEN "\033[32m" +#define YELLOW "\033[33m" +#define BLUE "\033[34m" +#define PURPLE "\033[35m" +#define DGREEN "\033[6m" +#define WHITE "\033[7m" +#define CYAN "\x1b[36m" +#define NONE "\033[0m" + +#ifdef NDEBUG + +#define TRACE_DEBUG_JSON(fmt, args...) +#define TRACE_DEBUG(fmt, args...) +#define TRACE_INFO(fmt, args...) +#define TRACE_WARN(fmt, args...) +#define TRACE_ERROR(fmt, args...) + +#else + +#define TRACE_DEBUG(fmt, args...) do { fprintf(stderr, "[%s:%d] " CYAN "DEBUG" NONE ": " fmt "\n", __func__, __LINE__, ##args); } while(0) +#define TRACE_INFO(fmt, args...) do { fprintf(stderr, "[%s:%d] " GREEN "INFO" NONE ": " fmt "\n", __func__, __LINE__, ##args); } while(0) +#define TRACE_WARN(fmt, args...) do { fprintf(stderr, "[%s:%d] " YELLOW "WARN" NONE": " fmt "\n", __func__, __LINE__, ##args); } while(0) +#define TRACE_ERROR(fmt, args...) do { fprintf(stderr, "[%s:%d] " RED "ERROR" NONE ": " fmt "\n", __func__, __LINE__, ##args); } while(0) + +#define TRACE_DEBUG_JSON(fmt, args...) + +#endif + +#endif // __TRACE_H__ |