2016-12-07 17:02:09 -05:00
|
|
|
#ifndef SCRIPTING_ENVIRONMENT_LUA_HPP
|
|
|
|
#define SCRIPTING_ENVIRONMENT_LUA_HPP
|
2016-07-11 11:44:58 -04:00
|
|
|
|
2017-09-01 09:55:00 -04:00
|
|
|
#include "extractor/extraction_relation.hpp"
|
2017-08-15 07:57:44 -04:00
|
|
|
#include "extractor/location_dependent_data.hpp"
|
2016-07-11 11:44:58 -04:00
|
|
|
#include "extractor/raster_source.hpp"
|
2016-10-25 16:22:06 -04:00
|
|
|
#include "extractor/scripting_environment.hpp"
|
2016-07-11 11:44:58 -04:00
|
|
|
|
|
|
|
#include <tbb/enumerable_thread_specific.h>
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <mutex>
|
|
|
|
#include <string>
|
|
|
|
|
2016-10-25 16:22:06 -04:00
|
|
|
#include <sol2/sol.hpp>
|
2016-07-11 11:44:58 -04:00
|
|
|
|
|
|
|
namespace osrm
|
|
|
|
{
|
|
|
|
namespace extractor
|
|
|
|
{
|
|
|
|
|
2016-12-07 17:02:09 -05:00
|
|
|
struct LuaScriptingContext final
|
2016-07-11 11:44:58 -04:00
|
|
|
{
|
2017-08-15 07:57:44 -04:00
|
|
|
LuaScriptingContext(const LocationDependentData &location_dependent_data)
|
2017-10-03 08:17:45 -04:00
|
|
|
: location_dependent_data(location_dependent_data),
|
|
|
|
last_location_point(0., 180.) // assume (0,180) is invalid coordinate
|
2017-08-15 07:57:44 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-09-01 09:55:00 -04:00
|
|
|
void ProcessNode(const osmium::Node &,
|
|
|
|
ExtractionNode &result,
|
2017-09-27 12:05:05 -04:00
|
|
|
const ExtractionRelationContainer &relations);
|
2017-09-01 09:55:00 -04:00
|
|
|
void ProcessWay(const osmium::Way &,
|
|
|
|
ExtractionWay &result,
|
2017-09-27 12:05:05 -04:00
|
|
|
const ExtractionRelationContainer &relations);
|
2016-07-11 11:44:58 -04:00
|
|
|
|
|
|
|
ProfileProperties properties;
|
2017-05-18 08:27:28 -04:00
|
|
|
RasterContainer raster_sources;
|
2016-10-25 16:22:06 -04:00
|
|
|
sol::state state;
|
2016-07-11 11:44:58 -04:00
|
|
|
|
|
|
|
bool has_turn_penalty_function;
|
|
|
|
bool has_node_function;
|
|
|
|
bool has_way_function;
|
|
|
|
bool has_segment_function;
|
2016-12-01 17:10:56 -05:00
|
|
|
|
2017-06-12 12:40:17 -04:00
|
|
|
sol::function turn_function;
|
|
|
|
sol::function way_function;
|
|
|
|
sol::function node_function;
|
|
|
|
sol::function segment_function;
|
|
|
|
|
2016-12-01 17:10:56 -05:00
|
|
|
int api_version;
|
2017-05-18 08:27:28 -04:00
|
|
|
sol::table profile_table;
|
2017-10-03 08:17:45 -04:00
|
|
|
|
|
|
|
// Reference to immutable location dependent data and locations memo
|
2017-08-15 07:57:44 -04:00
|
|
|
const LocationDependentData &location_dependent_data;
|
2017-10-03 08:17:45 -04:00
|
|
|
LocationDependentData::point_t last_location_point;
|
|
|
|
std::vector<std::size_t> last_location_indexes;
|
2016-07-11 11:44:58 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a lua context and binds osmium way, node and relation objects and
|
|
|
|
* ExtractionWay and ExtractionNode to lua objects.
|
|
|
|
*
|
|
|
|
* Each thread has its own lua state which is implemented with thread specific
|
|
|
|
* storage from TBB.
|
|
|
|
*/
|
2016-10-25 16:22:06 -04:00
|
|
|
class Sol2ScriptingEnvironment final : public ScriptingEnvironment
|
2016-07-11 11:44:58 -04:00
|
|
|
{
|
|
|
|
public:
|
2016-12-01 17:10:56 -05:00
|
|
|
static const constexpr int SUPPORTED_MIN_API_VERSION = 0;
|
2017-11-03 13:08:11 -04:00
|
|
|
static const constexpr int SUPPORTED_MAX_API_VERSION = 4;
|
2016-12-01 17:10:56 -05:00
|
|
|
|
2017-08-18 09:27:49 -04:00
|
|
|
explicit Sol2ScriptingEnvironment(
|
|
|
|
const std::string &file_name,
|
|
|
|
const std::vector<boost::filesystem::path> &location_dependent_data_paths);
|
2016-10-25 16:22:06 -04:00
|
|
|
~Sol2ScriptingEnvironment() override = default;
|
2016-07-11 11:44:58 -04:00
|
|
|
|
2016-07-26 09:00:58 -04:00
|
|
|
const ProfileProperties &GetProfileProperties() override;
|
2016-07-11 11:44:58 -04:00
|
|
|
|
2017-08-16 16:21:19 -04:00
|
|
|
std::vector<std::vector<std::string>> GetExcludableClasses() override;
|
2016-07-11 11:44:58 -04:00
|
|
|
std::vector<std::string> GetNameSuffixList() override;
|
2017-08-14 18:18:57 -04:00
|
|
|
std::vector<std::string> GetClassNames() override;
|
2016-09-09 06:34:04 -04:00
|
|
|
std::vector<std::string> GetRestrictions() override;
|
2017-09-27 12:05:05 -04:00
|
|
|
std::vector<std::string> GetRelations() override;
|
2016-05-12 12:50:10 -04:00
|
|
|
void ProcessTurn(ExtractionTurn &turn) override;
|
|
|
|
void ProcessSegment(ExtractionSegment &segment) override;
|
|
|
|
|
2017-10-04 10:31:15 -04:00
|
|
|
void
|
|
|
|
ProcessElements(const osmium::memory::Buffer &buffer,
|
|
|
|
const RestrictionParser &restriction_parser,
|
2018-02-09 13:32:09 -05:00
|
|
|
const ManeuverOverrideRelationParser &maneuver_override_parser,
|
2017-10-04 10:31:15 -04:00
|
|
|
const ExtractionRelationContainer &relations,
|
|
|
|
std::vector<std::pair<const osmium::Node &, ExtractionNode>> &resulting_nodes,
|
|
|
|
std::vector<std::pair<const osmium::Way &, ExtractionWay>> &resulting_ways,
|
2018-02-09 13:32:09 -05:00
|
|
|
std::vector<InputConditionalTurnRestriction> &resulting_restrictions,
|
|
|
|
std::vector<InputManeuverOverride> &resulting_maneuver_overrides) override;
|
2016-07-11 11:44:58 -04:00
|
|
|
|
2017-09-25 09:37:11 -04:00
|
|
|
bool HasLocationDependentData() const override { return !location_dependent_data.empty(); }
|
2017-09-22 11:33:06 -04:00
|
|
|
|
2016-07-11 11:44:58 -04:00
|
|
|
private:
|
2017-07-18 17:05:37 -04:00
|
|
|
LuaScriptingContext &GetSol2Context();
|
|
|
|
|
|
|
|
std::vector<std::string> GetStringListFromTable(const std::string &table_name);
|
|
|
|
std::vector<std::vector<std::string>> GetStringListsFromTable(const std::string &table_name);
|
|
|
|
std::vector<std::string> GetStringListFromFunction(const std::string &function_name);
|
|
|
|
|
2016-12-07 17:02:09 -05:00
|
|
|
void InitContext(LuaScriptingContext &context);
|
2016-07-11 11:44:58 -04:00
|
|
|
std::mutex init_mutex;
|
|
|
|
std::string file_name;
|
2016-12-07 17:02:09 -05:00
|
|
|
tbb::enumerable_thread_specific<std::unique_ptr<LuaScriptingContext>> script_contexts;
|
2017-08-15 07:57:44 -04:00
|
|
|
const LocationDependentData location_dependent_data;
|
2016-07-11 11:44:58 -04:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-07 17:02:09 -05:00
|
|
|
#endif /* SCRIPTING_ENVIRONMENT_LUA_HPP */
|