예제 #1
0
/* This is: php/Zend/configure.in

	This is going to be different from FLTK, mainly, since we have to be a tard bit different.
	Noamlly, Zend is configured within php's main configure.in. We are doing this independently, 
	so that we can do a components based build.
	
	Files that need to be generated:
		- php/zend/zend_config.h
		
	Notes:
		- Zend obviously has windows optimized files (.d/.dsp)!
		- It has some head-breaking checks. All added now, cDetect however might wants to adopt the dlsym check.
*/
int main(int argc, char** argv) {
	config_begin();
	ac_register();

	// We register some options here.
	// cachefile is very neccessary for our caching...
   	config_option_register_group("cDetect extra");
	config_option_register("cache",0,"cache.txt",0,"cDetect cache file to use.");
	config_option_register("out",0,"php/Zend/_zend_config.h",0,"Output config.h.");
	
	// Zend options
	config_option_register_group("Zend Engine");
	config_option_register(
		"with-zend-vm",0,"CALL",0,
		"Set virtual machine dispatch method. "
		"Type is one of \"CALL\", \"SWITCH\" or \"GOTO\""
	);
	config_option_register("enable-maintainer-zts",0,"no","yes","Enable thread safety - for code maintainers only!!");
	config_option_register("disable-inline-optimization",0,"no","yes","If building zend_execute.lo fails, try this switch");
	config_option_register("enable-debug",0,"no","yes","If building zend_execute.lo fails, try this switch");

	config_option_register("enable-zend-signals",0,"no","yes","Use zend signal handling");
	config_option_register("enable-debug",0,"no","yes","If building zend_execute.lo fails, try this switch");
	
	if(config_options(argc, argv)) {
	// Build stuff
	config_build_register("util/zend_config.h.in","php/Zend/zend_config.h");

		// The main logic happens here, just as always.
		zend_config_process();
		
		// Zend defines a top part, we define it too.
		// NOTE: It is obvious, that it wants to define this stuff if we are NOT on microsoft!
		// This check could be made simpler by FAR...
		config_tool_define(
			"ZEND_TOP",
			"#if defined(__GNUC__) && __GNUC__ >= 4\n"
			"# define ZEND_API __attribute__ ((visibility(\"default\")))\n"
			"# define ZEND_DLEXPORT __attribute__ ((visibility(\"default\")))\n"
			"#else\n"
			"# define ZEND_API\n"
			"# define ZEND_DLEXPORT\n"
			"#endif\n"
			"\n"
			"#define ZEND_DLIMPORT\n"
			"\n"
			"/* Define if you want to enable memory limit support */\n"
			"#define MEMORY_LIMIT 0\n"
		);
		
		// Aaaand of course, a bottom.
		// Again, this could be simplified.
		config_tool_define(
			"ZEND_BOTTOM",
			"#ifndef ZEND_ACCONFIG_H_NO_C_PROTOS\n"
			"\n"
			"#ifdef HAVE_STDLIB_H\n"
			"# include <stdlib.h>\n"
			"#endif\n"
			"\n"
			"#ifdef HAVE_SYS_TYPES_H\n"
			"# include <sys/types.h>\n"
			"#endif\n"
			"\n"
			"#ifdef HAVE_SYS_SELECT_H\n"
			"#include <sys/select.h>\n"
			"#endif\n"
			"\n"
			"#ifdef HAVE_IEEEFP_H\n"
			"# include <ieeefp.h>\n"
			"#endif\n"
			"\n"
			"#ifdef HAVE_STRING_H\n"
			"# include <string.h>\n"
			"#else\n"
			"# include <strings.h>\n"
			"#endif\n"
			"\n"
			"#if ZEND_BROKEN_SPRINTF\n"
			"int zend_sprintf(char *buffer, const char *format, ...);\n"
			"#else\n"
			"# define zend_sprintf sprintf\n"
			"#endif\n"
			"\n"
			"#include <math.h>\n"
			"\n"
			"/* To enable the is_nan, is_infinite and is_finite PHP functions */\n"
			"#ifdef NETWARE\n"
			"	#define HAVE_ISNAN 1\n"
			"	#define HAVE_ISINF 1\n"
			"	#define HAVE_ISFINITE 1\n"
			"#endif\n"
			"\n"
			"#ifndef zend_isnan\n"
			"#ifdef HAVE_ISNAN\n"
			"#define zend_isnan(a) isnan(a)\n"
			"#elif defined(HAVE_FPCLASS)\n"
			"#define zend_isnan(a) ((fpclass(a) == FP_SNAN) || (fpclass(a) == FP_QNAN))\n"
			"#else\n"
			"#define zend_isnan(a) 0\n"
			"#endif\n"
			"#endif\n"
			"\n"
			"#ifdef HAVE_ISINF\n"
			"#define zend_isinf(a) isinf(a)\n"
			"#elif defined(INFINITY)\n"
			"/* Might not work, but is required by ISO C99 */\n"
			"#define zend_isinf(a) (((a)==INFINITY)?1:0)\n"
			"#elif defined(HAVE_FPCLASS)\n"
			"#define zend_isinf(a) ((fpclass(a) == FP_PINF) || (fpclass(a) == FP_NINF))\n"
			"#else\n"
			"#define zend_isinf(a) 0\n"
			"#endif\n"
			"\n"
			"#ifdef HAVE_FINITE\n"
			"#define zend_finite(a) finite(a)\n"
			"#elif defined(HAVE_ISFINITE) || defined(isfinite)\n"
			"#define zend_finite(a) isfinite(a)\n"
			"#elif defined(fpclassify)\n"
			"#define zend_finite(a) ((fpclassify((a))!=FP_INFINITE&&fpclassify((a))!=FP_NAN)?1:0)\n"
			"#else\n"
			"#define zend_finite(a) (zend_isnan(a) ? 0 : zend_isinf(a) ? 0 : 1)\n"
			"#endif\n"
			"\n"
			"#endif /* ifndef ZEND_ACCONFIG_H_NO_C_PROTOS */\n"
			"\n"
			"#ifdef NETWARE\n"
			"#ifdef USE_WINSOCK\n"
			"#/*This detection against winsock is of no use*/ undef HAVE_SOCKLEN_T\n"
			"#/*This detection against winsock is of no use*/ undef HAVE_SYS_SOCKET_H\n"
			"#endif\n"
			"#endif\n"
		);
		
		// Do some checks
		ac_header_stdc();
		zend_mature_stdc();
		ac_type_size_t();
		zend_type_checks();
		ac_header_mmap_anonymous();
		ac_header_dirent();
		
		config_function_check_library("dlopen", "dl");
		config_function_check("vprintf");
		config_function_check("memcmp");
		config_function_check("alloca");
		config_function_check("memcpy");
		config_function_check("strdup");
		config_function_check("getpid");
		config_function_check("kill");
		config_function_check("strtod");
		config_function_check("strtol");
		config_function_check("finite");
		config_function_check("fpclass");
		config_function_check("sigsetjmp");
		config_function_check("finite");
		config_function_check("isfinite");
		config_function_check("isinf");
		config_function_check("isnan");
		config_function_check("sigaction");
		
		// An OS check.
		#if __APPLE__ || __DARWIN__
		config_macro_define("DARWIN","1");
		#endif
		
		// Complex checks
		zend_dlsym_check();
		zend_mm_test();
		zend_mmap_zero();
	}
	config_end();
}
예제 #2
0
파일: prepare.cpp 프로젝트: fredj/osrm
int main(int argc, char *argv[])
{
    try
    {
        LogPolicy::GetInstance().Unmute();
        TIMER_START(preparing);
        TIMER_START(expansion);

        boost::filesystem::path config_file_path, input_path, restrictions_path, profile_path;
        unsigned int requested_num_threads;
        bool use_elevation;

        // declare a group of options that will be allowed only on command line
        boost::program_options::options_description generic_options("Options");
        generic_options.add_options()("version,v", "Show version")("help,h",
                                                                   "Show this help message")(
            "config,c",
            boost::program_options::value<boost::filesystem::path>(&config_file_path)
                ->default_value("contractor.ini"),
            "Path to a configuration file.");

        // declare a group of options that will be allowed both on command line and in config file
        boost::program_options::options_description config_options("Configuration");
        config_options.add_options()(
            "restrictions,r",
            boost::program_options::value<boost::filesystem::path>(&restrictions_path),
            "Restrictions file in .osrm.restrictions format")(
            "profile,p",
            boost::program_options::value<boost::filesystem::path>(&profile_path)
                ->default_value("profile.lua"),"Path to LUA routing profile")(
            "elevation,e", boost::program_options::value<bool>(&use_elevation)->default_value(true),
                "Process node elevations")(
            "threads,t",
            boost::program_options::value<unsigned int>(&requested_num_threads)->default_value(tbb::task_scheduler_init::default_num_threads()),
            "Number of threads to use");

        // hidden options, will be allowed both on command line and in config file, but will not be
        // shown to the user
        boost::program_options::options_description hidden_options("Hidden options");
        hidden_options.add_options()(
            "input,i",
            boost::program_options::value<boost::filesystem::path>(&input_path),
            "Input file in .osm, .osm.bz2 or .osm.pbf format");

        // positional option
        boost::program_options::positional_options_description positional_options;
        positional_options.add("input", 1);

        // combine above options for parsing
        boost::program_options::options_description cmdline_options;
        cmdline_options.add(generic_options).add(config_options).add(hidden_options);

        boost::program_options::options_description config_file_options;
        config_file_options.add(config_options).add(hidden_options);

        boost::program_options::options_description visible_options(
            "Usage: " + boost::filesystem::basename(argv[0]) + " <input.osrm> [options]");
        visible_options.add(generic_options).add(config_options);

        // parse command line options
        boost::program_options::variables_map option_variables;
        boost::program_options::store(boost::program_options::command_line_parser(argc, argv)
                                          .options(cmdline_options)
                                          .positional(positional_options)
                                          .run(),
                                      option_variables);

        if (option_variables.count("version"))
        {
            SimpleLogger().Write() << g_GIT_DESCRIPTION;
            return 0;
        }

        if (option_variables.count("help"))
        {
            SimpleLogger().Write() << "\n" << visible_options;
            return 0;
        }

        boost::program_options::notify(option_variables);

        if (!option_variables.count("restrictions"))
        {
            restrictions_path = std::string(input_path.string() + ".restrictions");
        }

        if (!option_variables.count("input"))
        {
            SimpleLogger().Write() << "\n" << visible_options;
            return 0;
        }

        if (!boost::filesystem::is_regular_file(input_path))
        {
            SimpleLogger().Write(logWARNING) << "Input file " << input_path.string()
                                             << " not found!";
            return 1;
        }

        if (!boost::filesystem::is_regular_file(profile_path))
        {
            SimpleLogger().Write(logWARNING) << "Profile " << profile_path.string()
                                             << " not found!";
            return 1;
        }

        if (1 > requested_num_threads)
        {
            SimpleLogger().Write(logWARNING) << "Number of threads must be 1 or larger";
            return 1;
        }

        const unsigned recommended_num_threads = tbb::task_scheduler_init::default_num_threads();

        SimpleLogger().Write() << "Input file: " << input_path.filename().string();
        SimpleLogger().Write() << "Restrictions file: " << restrictions_path.filename().string();
        SimpleLogger().Write() << "Profile: " << profile_path.filename().string();
        SimpleLogger().Write() << "Using elevation: " << use_elevation;
        SimpleLogger().Write() << "Threads: " << requested_num_threads;
        if (recommended_num_threads != requested_num_threads)
        {
            SimpleLogger().Write(logWARNING) << "The recommended number of threads is "
                                             << recommended_num_threads
                                             << "! This setting may have performance side-effects.";
        }

        tbb::task_scheduler_init init(requested_num_threads);

        LogPolicy::GetInstance().Unmute();
        boost::filesystem::ifstream restriction_stream(restrictions_path, std::ios::binary);
        TurnRestriction restriction;
        FingerPrint fingerprint_loaded, fingerprint_orig;
        unsigned number_of_usable_restrictions = 0;
        restriction_stream.read((char *)&fingerprint_loaded, sizeof(FingerPrint));
        if (!fingerprint_loaded.TestPrepare(fingerprint_orig))
        {
            SimpleLogger().Write(logWARNING) << ".restrictions was prepared with different build.\n"
                                                "Reprocess to get rid of this warning.";
        }

        restriction_stream.read((char *)&number_of_usable_restrictions, sizeof(unsigned));
        restriction_list.resize(number_of_usable_restrictions);
        if (number_of_usable_restrictions > 0)
        {
            restriction_stream.read((char *)&(restriction_list[0]),
                                number_of_usable_restrictions * sizeof(TurnRestriction));
        }
        restriction_stream.close();

        boost::filesystem::ifstream in;
        in.open(input_path, std::ios::in | std::ios::binary);

        const std::string node_filename = input_path.string() + ".nodes";
        const std::string edge_out = input_path.string() + ".edges";
        const std::string geometry_filename = input_path.string() + ".geometry";
        const std::string graphOut = input_path.string() + ".hsgr";
        const std::string rtree_nodes_path = input_path.string() + ".ramIndex";
        const std::string rtree_leafs_path = input_path.string() + ".fileIndex";

        /*** Setup Scripting Environment ***/

        // Create a new lua state
        lua_State *lua_state = luaL_newstate();

        // Connect LuaBind to this lua state
        luabind::open(lua_state);

        // open utility libraries string library;
        luaL_openlibs(lua_state);

        // adjust lua load path
        luaAddScriptFolderToLoadPath(lua_state, profile_path.string().c_str());

        // Now call our function in a lua script
        if (0 != luaL_dofile(lua_state, profile_path.string().c_str()))
        {
            std::cerr << lua_tostring(lua_state, -1) << " occured in scripting block" << std::endl;
            return 1;
        }

        EdgeBasedGraphFactory::SpeedProfileProperties speed_profile;

        if (0 != luaL_dostring(lua_state, "return traffic_signal_penalty\n"))
        {
            std::cerr << lua_tostring(lua_state, -1) << " occured in scripting block" << std::endl;
            return 1;
        }
        speed_profile.trafficSignalPenalty = 10 * lua_tointeger(lua_state, -1);
        SimpleLogger().Write(logDEBUG)
            << "traffic_signal_penalty: " << speed_profile.trafficSignalPenalty;

        if (0 != luaL_dostring(lua_state, "return u_turn_penalty\n"))
        {
            std::cerr << lua_tostring(lua_state, -1) << " occured in scripting block" << std::endl;
            return 1;
        }
        speed_profile.uTurnPenalty = 10 * lua_tointeger(lua_state, -1);

        speed_profile.has_turn_penalty_function = lua_function_exists(lua_state, "turn_function");

        #ifdef WIN32
        #pragma message ("Memory consumption on Windows can be higher due to memory alignment")
        #else
        static_assert(sizeof(ImportEdge) == 20,
                      "changing ImportEdge type has influence on memory consumption!");
        #endif
        std::vector<ImportEdge> edge_list;
        NodeID number_of_node_based_nodes =
            readBinaryOSRMGraphFromStream(in,
                                          edge_list,
                                          barrier_node_list,
                                          traffic_light_list,
                                          &internal_to_external_node_map,
                                          restriction_list,
                                          use_elevation);
        in.close();

        if (edge_list.empty())
        {
            SimpleLogger().Write(logWARNING) << "The input data is empty, exiting.";
            return 1;
        }

        SimpleLogger().Write() << restriction_list.size() << " restrictions, "
                               << barrier_node_list.size() << " bollard nodes, "
                               << traffic_light_list.size() << " traffic lights";

        /***
         * Building an edge-expanded graph from node-based input and turn restrictions
         */

        SimpleLogger().Write() << "Generating edge-expanded graph representation";
        std::shared_ptr<NodeBasedDynamicGraph> node_based_graph =
            NodeBasedDynamicGraphFromImportEdges(number_of_node_based_nodes, edge_list);
        std::unique_ptr<RestrictionMap> restriction_map =
            std::unique_ptr<RestrictionMap>(new RestrictionMap(node_based_graph, restriction_list));
        EdgeBasedGraphFactory *edge_based_graph_factor =
            new EdgeBasedGraphFactory(node_based_graph,
                                      std::move(restriction_map),
                                      barrier_node_list,
                                      traffic_light_list,
                                      internal_to_external_node_map,
                                      speed_profile);
        edge_list.clear();
        edge_list.shrink_to_fit();

        edge_based_graph_factor->Run(edge_out, geometry_filename, lua_state);

        restriction_list.clear();
        restriction_list.shrink_to_fit();
        barrier_node_list.clear();
        barrier_node_list.shrink_to_fit();
        traffic_light_list.clear();
        traffic_light_list.shrink_to_fit();

        unsigned number_of_edge_based_nodes = edge_based_graph_factor->GetNumberOfEdgeBasedNodes();
        BOOST_ASSERT(number_of_edge_based_nodes != std::numeric_limits<unsigned>::max());
        DeallocatingVector<EdgeBasedEdge> edgeBasedEdgeList;
        #ifndef WIN32
        static_assert(sizeof(EdgeBasedEdge) == 16,
                      "changing ImportEdge type has influence on memory consumption!");
        #endif

        edge_based_graph_factor->GetEdgeBasedEdges(edgeBasedEdgeList);
        std::vector<EdgeBasedNode> node_based_edge_list;
        edge_based_graph_factor->GetEdgeBasedNodes(node_based_edge_list);
        delete edge_based_graph_factor;

        // TODO actually use scoping: Split this up in subfunctions
        node_based_graph.reset();

        TIMER_STOP(expansion);

        // Building grid-like nearest-neighbor data structure
        SimpleLogger().Write() << "building r-tree ...";
        StaticRTree<EdgeBasedNode> *rtree =
            new StaticRTree<EdgeBasedNode>(node_based_edge_list,
                                           rtree_nodes_path.c_str(),
                                           rtree_leafs_path.c_str(),
                                           internal_to_external_node_map);
        delete rtree;
        IteratorbasedCRC32<std::vector<EdgeBasedNode>> crc32;
        unsigned node_based_edge_list_CRC32 =
            crc32(node_based_edge_list.begin(), node_based_edge_list.end());
        node_based_edge_list.clear();
        node_based_edge_list.shrink_to_fit();
        SimpleLogger().Write() << "CRC32: " << node_based_edge_list_CRC32;

        /***
         * Writing info on original (node-based) nodes
         */

        SimpleLogger().Write() << "writing node map ...";
        boost::filesystem::ofstream node_stream(node_filename, std::ios::binary);
        const unsigned size_of_mapping = internal_to_external_node_map.size();
        node_stream.write((char *)&size_of_mapping, sizeof(unsigned));
        if (size_of_mapping > 0)
        {
            node_stream.write((char *)&(internal_to_external_node_map[0]),
                          size_of_mapping * sizeof(NodeInfo));
        }
        node_stream.close();
        internal_to_external_node_map.clear();
        internal_to_external_node_map.shrink_to_fit();

        /***
         * Contracting the edge-expanded graph
         */

        SimpleLogger().Write() << "initializing contractor";
        Contractor *contractor = new Contractor(number_of_edge_based_nodes, edgeBasedEdgeList);

        TIMER_START(contraction);
        contractor->Run();
        TIMER_STOP(contraction);

        SimpleLogger().Write() << "Contraction took " << TIMER_SEC(contraction) << " sec";

        DeallocatingVector<QueryEdge> contracted_edge_list;
        contractor->GetEdges(contracted_edge_list);
        delete contractor;

        /***
         * Sorting contracted edges in a way that the static query graph can read some in in-place.
         */

        std::sort(contracted_edge_list.begin(), contracted_edge_list.end());
        unsigned max_used_node_id = 0;
        unsigned contracted_edge_count = contracted_edge_list.size();
        SimpleLogger().Write() << "Serializing compacted graph of " << contracted_edge_count
                               << " edges";

        boost::filesystem::ofstream hsgr_output_stream(graphOut, std::ios::binary);
        hsgr_output_stream.write((char *)&fingerprint_orig, sizeof(FingerPrint));
        for (const QueryEdge &edge : contracted_edge_list)
        {
            BOOST_ASSERT(UINT_MAX != edge.source);
            BOOST_ASSERT(UINT_MAX != edge.target);

            max_used_node_id = std::max(max_used_node_id, edge.source);
            max_used_node_id = std::max(max_used_node_id, edge.target);
        }
        SimpleLogger().Write(logDEBUG) << "input graph has " << number_of_edge_based_nodes
                                       << " nodes";
        SimpleLogger().Write(logDEBUG) << "contracted graph has " << max_used_node_id << " nodes";
        max_used_node_id += 1;

        std::vector<StaticGraph<EdgeData>::NodeArrayEntry> node_array;
        node_array.resize(number_of_edge_based_nodes + 1);

        SimpleLogger().Write() << "Building node array";
        StaticGraph<EdgeData>::EdgeIterator edge = 0;
        StaticGraph<EdgeData>::EdgeIterator position = 0;
        StaticGraph<EdgeData>::EdgeIterator last_edge = edge;

        for (StaticGraph<EdgeData>::NodeIterator node = 0; node < max_used_node_id; ++node)
        {
            last_edge = edge;
            while ((edge < contracted_edge_count) && (contracted_edge_list[edge].source == node))
            {
                ++edge;
            }
            node_array[node].first_edge = position; //=edge
            position += edge - last_edge;           // remove
        }

        for (unsigned sentinel_counter = max_used_node_id; sentinel_counter != node_array.size();
             ++sentinel_counter)
        {
            // sentinel element, guarded against underflow
            node_array[sentinel_counter].first_edge = contracted_edge_count;
        }

        unsigned node_array_size = node_array.size();
        // serialize crc32, aka checksum
        hsgr_output_stream.write((char *)&node_based_edge_list_CRC32, sizeof(unsigned));
        // serialize number of nodes
        hsgr_output_stream.write((char *)&node_array_size, sizeof(unsigned));
        // serialize number of edges
        hsgr_output_stream.write((char *)&contracted_edge_count, sizeof(unsigned));
        // serialize all nodes
        if (node_array_size > 0)
        {
            hsgr_output_stream.write((char *)&node_array[0],
                                 sizeof(StaticGraph<EdgeData>::NodeArrayEntry) * node_array_size);
        }
        // serialize all edges

        SimpleLogger().Write() << "Building edge array";
        edge = 0;
        int number_of_used_edges = 0;

        StaticGraph<EdgeData>::EdgeArrayEntry current_edge;
        for (unsigned edge = 0; edge < contracted_edge_list.size(); ++edge)
        {
            // no eigen loops
            BOOST_ASSERT(contracted_edge_list[edge].source != contracted_edge_list[edge].target);
            current_edge.target = contracted_edge_list[edge].target;
            current_edge.data = contracted_edge_list[edge].data;

            // every target needs to be valid
            BOOST_ASSERT(current_edge.target < max_used_node_id);
#ifndef NDEBUG
            if (current_edge.data.distance <= 0)
            {
                SimpleLogger().Write(logWARNING)
                    << "Edge: " << edge << ",source: " << contracted_edge_list[edge].source
                    << ", target: " << contracted_edge_list[edge].target
                    << ", dist: " << current_edge.data.distance;

                SimpleLogger().Write(logWARNING) << "Failed at adjacency list of node "
                                                 << contracted_edge_list[edge].source << "/"
                                                 << node_array.size() - 1;
                return 1;
            }
#endif
            hsgr_output_stream.write((char *)&current_edge,
                                     sizeof(StaticGraph<EdgeData>::EdgeArrayEntry));
            ++number_of_used_edges;
        }
        hsgr_output_stream.close();

        TIMER_STOP(preparing);

        SimpleLogger().Write() << "Preprocessing : " << TIMER_SEC(preparing) << " seconds";
        SimpleLogger().Write() << "Expansion  : "
                               << (number_of_node_based_nodes / TIMER_SEC(expansion))
                               << " nodes/sec and "
                               << (number_of_edge_based_nodes / TIMER_SEC(expansion))
                               << " edges/sec";

        SimpleLogger().Write() << "Contraction: "
                               << (number_of_edge_based_nodes / TIMER_SEC(contraction))
                               << " nodes/sec and "
                               << number_of_used_edges / TIMER_SEC(contraction)
                               << " edges/sec";

        node_array.clear();
        SimpleLogger().Write() << "finished preprocessing";
    }
    catch (boost::program_options::too_many_positional_options_error &)
    {
        SimpleLogger().Write(logWARNING) << "Only one file can be specified";
        return 1;
    }
    catch (boost::program_options::error &e)
    {
        SimpleLogger().Write(logWARNING) << e.what();
        return 1;
    }
    catch (const std::exception &e)
    {
        SimpleLogger().Write(logWARNING) << "Exception occured: " << e.what() << std::endl;
        return 1;
    }
    return 0;
}
예제 #3
0
// generate boost::program_options object for the routing part
inline unsigned GenerateServerProgramOptions(const int argc,
                                             const char *argv[],
                                             ServerPaths &paths,
                                             std::string &ip_address,
                                             int &ip_port,
                                             int &requested_num_threads,
                                             bool &use_shared_memory,
                                             bool &trial,
                                             int &max_locations_distance_table,
                                             int &max_locations_map_matching)
{
    // declare a group of options that will be allowed only on command line
    boost::program_options::options_description generic_options("Options");
    generic_options.add_options()("version,v", "Show version")("help,h", "Show this help message")(
        "config,c", boost::program_options::value<boost::filesystem::path>(&paths["config"])
                        ->default_value("server.ini"),
        "Path to a configuration file")(
        "trial", boost::program_options::value<bool>(&trial)->implicit_value(true),
        "Quit after initialization");

    // declare a group of options that will be allowed both on command line
    // as well as in a config file
    boost::program_options::options_description config_options("Configuration");
    config_options.add_options()(
        "hsgrdata", boost::program_options::value<boost::filesystem::path>(&paths["hsgrdata"]),
        ".hsgr file")("nodesdata",
                      boost::program_options::value<boost::filesystem::path>(&paths["nodesdata"]),
                      ".nodes file")(
        "edgesdata", boost::program_options::value<boost::filesystem::path>(&paths["edgesdata"]),
        ".edges file")("geometry",
                       boost::program_options::value<boost::filesystem::path>(&paths["geometries"]),
                       ".geometry file")(
        "ramindex", boost::program_options::value<boost::filesystem::path>(&paths["ramindex"]),
        ".ramIndex file")(
        "fileindex", boost::program_options::value<boost::filesystem::path>(&paths["fileindex"]),
        "File index file")(
        "namesdata", boost::program_options::value<boost::filesystem::path>(&paths["namesdata"]),
        ".names file")("timestamp",
                       boost::program_options::value<boost::filesystem::path>(&paths["timestamp"]),
                       ".timestamp file")(
        "ip,i", boost::program_options::value<std::string>(&ip_address)->default_value("0.0.0.0"),
        "IP address")("port,p", boost::program_options::value<int>(&ip_port)->default_value(5000),
                      "TCP/IP port")(
        "threads,t", boost::program_options::value<int>(&requested_num_threads)->default_value(8),
        "Number of threads to use")(
        "shared-memory,s",
        boost::program_options::value<bool>(&use_shared_memory)->implicit_value(true),
        "Load data from shared memory")(
        "max-table-size,m",
        boost::program_options::value<int>(&max_locations_distance_table)->default_value(1000000),
        "Max. locations supported in distance table query")(
        "max-matching-size,m",
        boost::program_options::value<int>(&max_locations_map_matching)->default_value(2),
        "Max. locations supported in map matching query");

    // hidden options, will be allowed both on command line and in config
    // file, but will not be shown to the user
    boost::program_options::options_description hidden_options("Hidden options");
    hidden_options.add_options()(
        "base,b", boost::program_options::value<boost::filesystem::path>(&paths["base"]),
        "base path to .osrm file");

    // positional option
    boost::program_options::positional_options_description positional_options;
    positional_options.add("base", 1);

    // combine above options for parsing
    boost::program_options::options_description cmdline_options;
    cmdline_options.add(generic_options).add(config_options).add(hidden_options);

    boost::program_options::options_description config_file_options;
    config_file_options.add(config_options).add(hidden_options);

    boost::program_options::options_description visible_options(
        boost::filesystem::basename(argv[0]) + " <base.osrm> [<options>]");
    visible_options.add(generic_options).add(config_options);

    // parse command line options
    boost::program_options::variables_map option_variables;
    boost::program_options::store(boost::program_options::command_line_parser(argc, argv)
                                      .options(cmdline_options)
                                      .positional(positional_options)
                                      .run(),
                                  option_variables);

    if (option_variables.count("version"))
    {
        SimpleLogger().Write() << g_GIT_DESCRIPTION;
        return INIT_OK_DO_NOT_START_ENGINE;
    }

    if (option_variables.count("help"))
    {
        SimpleLogger().Write() << visible_options;
        return INIT_OK_DO_NOT_START_ENGINE;
    }

    boost::program_options::notify(option_variables);

    // parse config file
    auto path_iterator = paths.find("config");
    if (path_iterator != paths.end() && boost::filesystem::is_regular_file(path_iterator->second) &&
        !option_variables.count("base"))
    {
        SimpleLogger().Write() << "Reading options from: " << path_iterator->second.string();
        std::string ini_file_contents = read_file_lower_content(path_iterator->second);
        std::stringstream config_stream(ini_file_contents);
        boost::program_options::store(parse_config_file(config_stream, config_file_options),
                                      option_variables);
        boost::program_options::notify(option_variables);
        return INIT_OK_START_ENGINE;
    }

    if (1 > requested_num_threads)
    {
        throw osrm::exception("Number of threads must be a positive number");
    }

    if (!use_shared_memory && option_variables.count("base"))
    {
        return INIT_OK_START_ENGINE;
    }
    if (use_shared_memory && !option_variables.count("base"))
    {
        return INIT_OK_START_ENGINE;
    }
    if (1 > max_locations_distance_table)
    {
        throw osrm::exception("Max location for distance table must be a positive number");
    }
    if (2 > max_locations_map_matching)
    {
        throw osrm::exception("Max location for map matching must be at least two");
    }

    SimpleLogger().Write() << visible_options;
    return INIT_OK_DO_NOT_START_ENGINE;
}
return_code
ExtractorOptions::ParseArguments(int argc, char *argv[], ExtractorConfig &extractor_config)
{
    // declare a group of options that will be allowed only on command line
    boost::program_options::options_description generic_options("Options");
    generic_options.add_options()("version,v", "Show version")("help,h", "Show this help message")(
        "config,c", boost::program_options::value<boost::filesystem::path>(
                        &extractor_config.config_file_path)->default_value("extractor.ini"),
        "Path to a configuration file.");

    // declare a group of options that will be allowed both on command line and in config file
    boost::program_options::options_description config_options("Configuration");
    config_options.add_options()("profile,p",
                                 boost::program_options::value<boost::filesystem::path>(
                                     &extractor_config.profile_path)->default_value("profile.lua"),
                                 "Path to LUA routing profile")(
        "threads,t",
        boost::program_options::value<unsigned int>(&extractor_config.requested_num_threads)
            ->default_value(tbb::task_scheduler_init::default_num_threads()),
        "Number of threads to use");

    // hidden options, will be allowed both on command line and in config file, but will not be
    // shown to the user
    boost::program_options::options_description hidden_options("Hidden options");
    hidden_options.add_options()("input,i", boost::program_options::value<boost::filesystem::path>(
                                                &extractor_config.input_path),
                                 "Input file in .osm, .osm.bz2 or .osm.pbf format");

    // positional option
    boost::program_options::positional_options_description positional_options;
    positional_options.add("input", 1);

    // combine above options for parsing
    boost::program_options::options_description cmdline_options;
    cmdline_options.add(generic_options).add(config_options).add(hidden_options);

    boost::program_options::options_description config_file_options;
    config_file_options.add(config_options).add(hidden_options);

    boost::program_options::options_description visible_options(
        boost::filesystem::basename(argv[0]) + " <input.osm/.osm.bz2/.osm.pbf> [options]");
    visible_options.add(generic_options).add(config_options);

    // parse command line options
    try
    {
        boost::program_options::variables_map option_variables;
        boost::program_options::store(boost::program_options::command_line_parser(argc, argv)
                                          .options(cmdline_options)
                                          .positional(positional_options)
                                          .run(),
                                      option_variables);
        if (option_variables.count("version"))
        {
            SimpleLogger().Write() << g_GIT_DESCRIPTION;
            return return_code::exit;
        }

        if (option_variables.count("help"))
        {
            SimpleLogger().Write() << visible_options;
            return return_code::exit;
        }

        boost::program_options::notify(option_variables);

        // parse config file
        if (boost::filesystem::is_regular_file(extractor_config.config_file_path))
        {
            SimpleLogger().Write()
                << "Reading options from: " << extractor_config.config_file_path.string();
            std::string ini_file_contents =
                read_file_lower_content(extractor_config.config_file_path);
            std::stringstream config_stream(ini_file_contents);
            boost::program_options::store(parse_config_file(config_stream, config_file_options),
                                          option_variables);
            boost::program_options::notify(option_variables);
        }

        if (!option_variables.count("input"))
        {
            SimpleLogger().Write() << visible_options;
            return return_code::exit;
        }
    }
    catch (std::exception &e)
    {
        SimpleLogger().Write(logWARNING) << e.what();
        return return_code::fail;
    }

    return return_code::ok;
}
예제 #5
0
// Cool. TSRM is uber-easy. Lets take advantage of this ~100 configure.in.
// Generate: php/TSRM/tsrm_config.h
int main(int argc, char** argv){
	config_begin();
	ac_register();
	
   	config_option_register_group("cDetect extra");
	config_option_register("cache",0,"cache.txt",0,"cDetect cache file to use.");
	config_option_register("out",0,"php/TSRM/_tsrm_config.h",0,"Output config.h.");
	
	// TSRM options
	config_option_register_group("TSRM: ThreadSafe Resource Management");
	config_option_register("with-tsrm-pth",0,"no",0,"Use GNU Pth (supply PATH or \"yes\")");
	config_option_register("with-tsrm-st",0,"no",0,"Use SGI's State Threads (supply PATH or \"yes\")");
	config_option_register("with-tsrm-pthreads",0,"no","yes","Use POSIX pthreads (Default)");
	config_option_register("with-tsrm-zts",0,"no","yes","Use POSIX pthreads (Default)");
	
	if(config_options(argc, argv)) {
		// And encore!
		config_cache_register( config_option_get("cache") );
		config_header_register( config_option_get("out") );
		
		// options.
		if( // If neither of these are set, use the default.
			config_equal( config_option_get("with-tsrm-pth"), "no" )
			|| config_equal( config_option_get("with-tsrm-st"), "no" )
		) {
			config_option_set("with-tsrm-pthreads","yes");
			config_macro_define("PTHREADS","1");
		}
		if(config_equal( config_option_get("with-tsrm-zts"), "yes" )) {
			config_macro_define("ZTS","1");
		}
		
		// Header
		ac_header_stdc();
		ac_header_dirent();
		config_header_check("utime.h");
		config_header_check("dirent.h");
		config_header_check("stdarg.h");
		config_header_check("alloca.h");
		config_header_check("unistd.h");
		config_header_check("limits.h");
		config_header_check("stdlib.h");
		config_header_check("stdarg.h");
		config_header_check("string.h");
		config_header_check("float.h");
		config_header_check("st.h");
		
		// Function
		config_function_check("sigprocmask");
		
		// Customs
		config_function_check_library("pthread_create","pthread")
			|| config_macro_define("PTHREADS","1");
		
		// Write a bit of extra chunk...
		char* tsrm_config_h = "php/TSRM/tsrm_config.h";
		config_report("Writing %s\n", tsrm_config_h);
		cdetect_string_t src = cdetect_string_format(
			"#include \"_tsrm_config.h\"\n"
			"#ifdef HAVE_STDLIB_H\n"
			"#include <stdlib.h>\n"
			"#endif\n"
		);
		cdetect_bool_t sc = cdetect_file_overwrite(tsrm_config_h, src);
		if(sc != CDETECT_TRUE) {
			config_report("!! Error: Could not write php/TSRM/tsrm_config.h!\n");
			config_abort();
		}
		cdetect_string_destroy(src);
	}
	config_end();
}
return_code
ContractorOptions::ParseArguments(int argc, char *argv[], ContractorConfig &contractor_config)
{
    // declare a group of options that will be allowed only on command line
    boost::program_options::options_description generic_options("Options");
    generic_options.add_options()("version,v", "Show version")("help,h", "Show this help message")(
        "config,c", boost::program_options::value<boost::filesystem::path>(&contractor_config.config_file_path)
                        ->default_value("contractor.ini"),
        "Path to a configuration file.");

    // declare a group of options that will be allowed both on command line and in config file
    boost::program_options::options_description config_options("Configuration");
    config_options.add_options()(
        "restrictions,r",
        boost::program_options::value<boost::filesystem::path>(&contractor_config.restrictions_path),
        "Restrictions file in .osrm.restrictions format")(
        "profile,p", boost::program_options::value<boost::filesystem::path>(&contractor_config.profile_path)
                         ->default_value("profile.lua"),
        "Path to LUA routing profile")(
        "threads,t", boost::program_options::value<unsigned int>(&contractor_config.requested_num_threads)
                         ->default_value(tbb::task_scheduler_init::default_num_threads()),
        "Number of threads to use");

    // hidden options, will be allowed both on command line and in config file, but will not be
    // shown to the user
    boost::program_options::options_description hidden_options("Hidden options");
    hidden_options.add_options()(
        "input,i", boost::program_options::value<boost::filesystem::path>(&contractor_config.osrm_input_path),
        "Input file in .osm, .osm.bz2 or .osm.pbf format");

    // positional option
    boost::program_options::positional_options_description positional_options;
    positional_options.add("input", 1);

    // combine above options for parsing
    boost::program_options::options_description cmdline_options;
    cmdline_options.add(generic_options).add(config_options).add(hidden_options);

    boost::program_options::options_description config_file_options;
    config_file_options.add(config_options).add(hidden_options);

    boost::program_options::options_description visible_options(
        "Usage: " + boost::filesystem::basename(argv[0]) + " <input.osrm> [options]");
    visible_options.add(generic_options).add(config_options);

    // parse command line options
    boost::program_options::variables_map option_variables;
    boost::program_options::store(boost::program_options::command_line_parser(argc, argv)
                                      .options(cmdline_options)
                                      .positional(positional_options)
                                      .run(),
                                  option_variables);

    const auto &temp_config_path = option_variables["config"].as<boost::filesystem::path>();
    if (boost::filesystem::is_regular_file(temp_config_path))
    {
        boost::program_options::store(boost::program_options::parse_config_file<char>(
                                          temp_config_path.string().c_str(), cmdline_options, true),
                                      option_variables);
    }

    if (option_variables.count("version"))
    {
        SimpleLogger().Write() << g_GIT_DESCRIPTION;
        return return_code::exit;
    }

    if (option_variables.count("help"))
    {
        SimpleLogger().Write() << "\n" << visible_options;
        return return_code::exit;
    }

    boost::program_options::notify(option_variables);

    if (!option_variables.count("restrictions"))
    {
        contractor_config.restrictions_path = contractor_config.osrm_input_path.string() + ".restrictions";
    }

    if (!option_variables.count("input"))
    {
        SimpleLogger().Write() << "\n" << visible_options;
        return return_code::fail;
    }

    return return_code::ok;
}
예제 #7
0
int main (int argc, char *argv[]) {
    try {
        LogPolicy::GetInstance().Unmute();
        double startup_time = get_timestamp();

        boost::filesystem::path config_file_path, input_path, profile_path;
        int requested_num_threads;

        // declare a group of options that will be allowed only on command line
        boost::program_options::options_description generic_options("Options");
        generic_options.add_options()
            ("version,v", "Show version")
            ("help,h", "Show this help message")
            ("config,c", boost::program_options::value<boost::filesystem::path>(&config_file_path)->default_value("extractor.ini"),
                  "Path to a configuration file.");

        // declare a group of options that will be allowed both on command line and in config file
        boost::program_options::options_description config_options("Configuration");
        config_options.add_options()
            ("profile,p", boost::program_options::value<boost::filesystem::path>(&profile_path)->default_value("profile.lua"),
                "Path to LUA routing profile")
            ("threads,t", boost::program_options::value<int>(&requested_num_threads)->default_value(8),
                "Number of threads to use");

        // hidden options, will be allowed both on command line and in config file, but will not be shown to the user
        boost::program_options::options_description hidden_options("Hidden options");
        hidden_options.add_options()
            ("input,i", boost::program_options::value<boost::filesystem::path>(&input_path),
                "Input file in .osm, .osm.bz2 or .osm.pbf format");

        // positional option
        boost::program_options::positional_options_description positional_options;
        positional_options.add("input", 1);

        // combine above options for parsing
        boost::program_options::options_description cmdline_options;
        cmdline_options.add(generic_options).add(config_options).add(hidden_options);

        boost::program_options::options_description config_file_options;
        config_file_options.add(config_options).add(hidden_options);

        boost::program_options::options_description visible_options(boost::filesystem::basename(argv[0]) + " <input.osm/.osm.bz2/.osm.pbf> [options]");
        visible_options.add(generic_options).add(config_options);

        // parse command line options
        boost::program_options::variables_map option_variables;
        boost::program_options::store(boost::program_options::command_line_parser(argc, argv).
            options(cmdline_options).positional(positional_options).run(), option_variables);

        if(option_variables.count("version")) {
            SimpleLogger().Write() << g_GIT_DESCRIPTION;
            return 0;
        }

        if(option_variables.count("help")) {
            SimpleLogger().Write() << visible_options;
            return 0;
        }

        boost::program_options::notify(option_variables);

        // parse config file
        if(boost::filesystem::is_regular_file(config_file_path)) {
            SimpleLogger().Write() << "Reading options from: " << config_file_path.c_str();
            std::string config_str;
            PrepareConfigFile( config_file_path.c_str(), config_str );
            std::stringstream config_stream( config_str );
            boost::program_options::store(parse_config_file(config_stream, config_file_options), option_variables);
            boost::program_options::notify(option_variables);
        }

        if(!option_variables.count("input")) {
            SimpleLogger().Write(logWARNING) << "No input file specified";
            SimpleLogger().Write() << visible_options;
            return -1;
        }

        if(1 > requested_num_threads) {
            SimpleLogger().Write(logWARNING) << "Number of threads must be 1 or larger";
            return -1;
        }

        SimpleLogger().Write() << "Input file: " << input_path.filename().string();
        SimpleLogger().Write() << "Profile: " << profile_path.filename().string();
        SimpleLogger().Write() << "Threads: " << requested_num_threads;

        /*** Setup Scripting Environment ***/
        ScriptingEnvironment scriptingEnvironment(profile_path.c_str());

        omp_set_num_threads( std::min( omp_get_num_procs(), requested_num_threads) );

        bool file_has_pbf_format(false);
        std::string output_file_name(input_path.c_str());
        std::string restrictionsFileName(input_path.c_str());
        std::string::size_type pos = output_file_name.find(".osm.bz2");
        if(pos==std::string::npos) {
            pos = output_file_name.find(".osm.pbf");
            if(pos!=std::string::npos) {
                file_has_pbf_format = true;
            }
        }
        if(pos==std::string::npos) {
            pos = output_file_name.find(".pbf");
            if(pos!=std::string::npos) {
                file_has_pbf_format = true;
            }
        }
        if(pos!=std::string::npos) {
            output_file_name.replace(pos, 8, ".osrm");
            restrictionsFileName.replace(pos, 8, ".osrm.restrictions");
        } else {
            pos=output_file_name.find(".osm");
            if(pos!=std::string::npos) {
                output_file_name.replace(pos, 5, ".osrm");
                restrictionsFileName.replace(pos, 5, ".osrm.restrictions");
            } else {
                output_file_name.append(".osrm");
                restrictionsFileName.append(".osrm.restrictions");
            }
        }

        StringMap stringMap;
        ExtractionContainers externalMemory;

        stringMap[""] = 0;
        extractCallBacks = new ExtractorCallbacks(&externalMemory, &stringMap);
        BaseParser* parser;
        if(file_has_pbf_format) {
            parser = new PBFParser(input_path.c_str(), extractCallBacks, scriptingEnvironment);
        } else {
            parser = new XMLParser(input_path.c_str(), extractCallBacks, scriptingEnvironment);
        }

        if(!parser->ReadHeader()) {
            throw OSRMException("Parser not initialized!");
        }
        SimpleLogger().Write() << "Parsing in progress..";
        double parsing_start_time = get_timestamp();
        parser->Parse();
        SimpleLogger().Write() << "Parsing finished after " <<
            (get_timestamp() - parsing_start_time) <<
            " seconds";

        if( externalMemory.all_edges_list.empty() ) {
            SimpleLogger().Write(logWARNING) << "The input data is empty, exiting.";
            return -1;
        }

        externalMemory.PrepareData(output_file_name, restrictionsFileName);

        delete parser;
        delete extractCallBacks;

        SimpleLogger().Write() <<
            "extraction finished after " << get_timestamp() - startup_time <<
            "s";

         SimpleLogger().Write() << "To prepare the data for routing, run: "
            << "./osrm-prepare " << output_file_name << std::endl;

    } catch(boost::program_options::too_many_positional_options_error& e) {
        SimpleLogger().Write(logWARNING) << "Only one input file can be specified";
        return -1;
    } catch(boost::program_options::error& e) {
        SimpleLogger().Write(logWARNING) << e.what();
        return -1;
    } catch(std::exception & e) {
        SimpleLogger().Write(logWARNING) << "Unhandled exception: " << e.what();
        return -1;
    }
    return 0;
}