aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-04-11 15:47:26 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2017-04-11 15:47:26 +0200
commitb7591d16c2686214d5d8dcc0739a233f15aee5db (patch)
treee89fbc60a99800697c2de2b2876c73de91177e9e
parentad366bd680d5ce0bef49242cf6b3902fe46e0141 (diff)
Remove boost library dependency.
Use a simple optarg parser. Change-Id: If0cd9da9db24a7889573e32f6b8ace33702c2c35 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
-rw-r--r--CMakeLists.txt28
-rw-r--r--README.md10
-rw-r--r--src/main.cpp149
-rw-r--r--src/main.hpp55
4 files changed, 148 insertions, 94 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index a2f5bf2f..8eb40d55 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -13,21 +13,15 @@ endif ()
include_directories(SYSTEM 3rdparty/json)
-find_package(Boost REQUIRED COMPONENTS program_options filesystem system)
-if(Boost_FOUND)
- add_definitions(${Boost_LIB_DIAGNOSTIC_DEFINITIONS})
- include_directories(SYSTEM ${Boost_INCLUDE_DIRS})
+add_executable(can-config-generator
+ src/main.cpp
+ src/openxc/message_set.cpp
+ src/openxc/can_bus.cpp
+ src/openxc/can_message.cpp
+ src/openxc/command.cpp
+ src/openxc/diagnostic_message.cpp
+ src/openxc/mapping.cpp
+ src/openxc/signal.cpp)
- add_executable(can-config-generator
- src/main.cpp
- src/openxc/message_set.cpp
- src/openxc/can_bus.cpp
- src/openxc/can_message.cpp
- src/openxc/command.cpp
- src/openxc/diagnostic_message.cpp
- src/openxc/mapping.cpp
- src/openxc/signal.cpp)
-
- target_link_libraries(can-config-generator ${Boost_LIBRARIES})
- target_compile_features(can-config-generator PRIVATE cxx_range_for cxx_constexpr cxx_nullptr)
-endif()
+target_link_libraries(can-config-generator)
+target_compile_features(can-config-generator PRIVATE cxx_range_for cxx_constexpr cxx_nullptr)
diff --git a/README.md b/README.md
index d24ce07e..d4127b8a 100644
--- a/README.md
+++ b/README.md
@@ -13,16 +13,6 @@ The reference documentation of the JSON file can be found [here](https://github.
* CMake version 3.0 or later
* G++, Clang++ or any C++11 complient compiler.
-* Boost
- * filesystem
- * program_options
- * system
-
-You can install any of these using your package manager. For instance, inside the iotbzh's docker image, you must enter this command :
-
- sudo apt-get install libboost-system-dev libboost-filesystem-dev libboost-program-options-dev
-
-You may want to install `libboost-all-dev` to get all boost components even if it's not required.
* Make sure you already set up the AGL SDK using the following [SDK Quick Setup Guide](http://docs.iot.bzh/docs/getting_started/en/dev/reference/setup-sdk-environment.html). Alternatively, please refer to official guides available on [AGL Developer Site](http://docs.automotivelinux.org/docs/devguides/en/dev/#guides).
diff --git a/src/main.cpp b/src/main.cpp
index 55f956ef..cfefed84 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,11 +1,30 @@
+/*
+ * Copyright (C) 2015, 2016 "IoT.bzh"
+ * Author "Loïc Collignon" <loic.collignon@iot.bzh>
+ * Author "Romain Forlot" <romain.forlot@iot.bzh>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <libgen.h>
#include <exception>
#include <fstream>
#include <iostream>
#include <string>
#include <numeric>
#include <iterator>
-#include <boost/program_options.hpp>
-#include <boost/filesystem.hpp>
#include <json.hpp>
#include "openxc/message_set.hpp"
@@ -286,98 +305,94 @@ nlohmann::json read_json(const std::string& file)
throw std::runtime_error(ss.str());
}
+// function that show the help information
+void showhelpinfo(char *s)
+{
+std::cout<<"Usage: "<<s<<" <-m inpout.json> [-o configuration-generated.cpp]"<< std::endl;
+std::cout<<"option: "<<"-m input.json : JSON file describing CAN messages and signals"<< std::endl;
+std::cout<<" "<<"-h header.cpp : header source file insert at the beginning of generated file"<< std::endl;
+std::cout<<" "<<"-f footer.cpp : footer source file append to generated file."<< std::endl;
+std::cout<<" "<<"-o configuration-generated.cpp : output source file. Name has to be configuration-generated.cpp"<< std::endl;
+}
+
/// @brief Entry point.
/// @param[in] argc Argument's count.
/// @param[in] argv Argument's array.
/// @return Exit code, zero if success.
-int main(int argc, char** argv)
+int main(int argc, char *argv[])
{
- //std::ios::sync_with_stdio(false);
-
try
{
- std::string appName = boost::filesystem::basename(argv[0]);
+ std::string appName = argv[0];
std::string message_set_file;
std::string output_file;
std::string header_file;
std::string footer_file;
- namespace bpo = boost::program_options;
- bpo::options_description desc("Options");
- desc.add_options()
- ("help,h", "Display this help.")
- ("message-set,m", bpo::value<std::string>(&message_set_file)->required(), "The message set definition file.")
- ("output,o", bpo::value<std::string>(&output_file), "An output file, if not specified stdout is used.")
- ("header,h", bpo::value<std::string>(&header_file), "A file to copy at the top of the generated output.")
- ("footer,f", bpo::value<std::string>(&footer_file), "A file to copy at the end of the generated output.");
-
- bpo::variables_map vm;
- try
+ char tmp;
+ /*if the program is ran witout options ,it will show the usgage and exit*/
+ if(argc == 1)
{
- bpo::store(bpo::parse_command_line(argc, argv, desc), vm);
-
- if (vm.count("help"))
+ showhelpinfo(argv[0]);
+ exit(1);
+ }
+ /*use function getopt to get the arguments with option."hu:p:s:v" indicate
+ that option h,v are the options without arguments while u,p,s are the
+ options with arguments*/
+ while((tmp=getopt(argc,argv,"m:h:f:o:"))!=-1)
+ {
+ switch(tmp)
{
- std::cout << desc << std::endl;
- return EXIT_SUCCESS;
+ case 'h':
+ header_file = optarg;
+ break;
+ case 'f':
+ footer_file = optarg;
+ break;
+ case 'm':
+ message_set_file = optarg;
+ break;
+ case 'o':
+ output_file = optarg;
+ break;
+ default:
+ showhelpinfo(argv[0]);
+ break;
}
+ }
- bpo::notify(vm);
-
- std::stringstream header;
- header << read_file(header_file);
-
- std::string footer = read_file(footer_file);
- openxc::message_set message_set;
- message_set.from_json(read_json(message_set_file));
-
- boost::filesystem::path message_set_path(message_set_file);
- message_set_path.remove_filename();
- for(const auto& s : message_set.extra_sources())
- {
- boost::filesystem::path extra_source(s);
- if (!extra_source.is_complete()) extra_source = message_set_path / extra_source;
- header << "\n// >>>>> " << s << " >>>>>\n" << read_file(extra_source.string()) << "\n// <<<<< " << s << " <<<<<\n";
- }
+ std::stringstream header;
+ header << read_file(header_file);
- std::ofstream out;
- if (output_file.size())
- {
- out.open(output_file);
- if(!out)
- {
- std::stringstream ss;
- ss << "Can't open the ouput file (" << output_file << ") for writing!";
- throw std::runtime_error(ss.str());
- }
- }
-
- generate(header.str(), footer, message_set, output_file.size() ? out : std::cout);
+ std::string footer = read_file(footer_file);
+ openxc::message_set message_set;
+ message_set.from_json(read_json(message_set_file));
- }
- catch (bpo::required_option& e)
+ std::string message_set_path = dirname(strdup(message_set_file.c_str()));
+ for(const auto& s : message_set.extra_sources())
{
- std::cerr << "ERROR: Argument required - " << e.what() << std::endl;
- std::cout << desc << std::endl;
- return EXIT_COMMAND_LINE_ERROR;
+ std::string extra_source = s;
+ extra_source = message_set_path + "/" + extra_source;
+ header << "\n// >>>>> " << s << " >>>>>\n" << read_file(extra_source) << "\n// <<<<< " << s << " <<<<<\n";
}
- catch (bpo::error& e)
- {
- std::cerr << "ERROR: Command line error - " << e.what() << std::endl;
- std::cout << desc << std::endl;
- return EXIT_COMMAND_LINE_ERROR;
- }
- catch(std::exception& e)
+
+ std::ofstream out;
+ if (output_file.size())
{
- std::cerr << "ERROR: " << e.what() << std::endl;
- return EXIT_PROGRAM_ERROR;
+ out.open(output_file);
+ if(!out)
+ {
+ std::stringstream ss;
+ ss << "Can't open the ouput file (" << output_file << ") for writing!";
+ throw std::runtime_error(ss.str());
+ }
}
+ generate(header.str(), footer, message_set, output_file.size() ? out : std::cout);
}
catch (std::exception& e)
{
std::cerr << "ERROR: Unhandled exception - " << e.what() << std::endl;
return EXIT_UNKNOWN_ERROR;
}
-
return EXIT_SUCCESS;
}
diff --git a/src/main.hpp b/src/main.hpp
new file mode 100644
index 00000000..cf08e1a4
--- /dev/null
+++ b/src/main.hpp
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2015, 20"IoT.bzh"
+ * Author "Romain Forlot" <romain.forlot@iot.bzh>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+struct afb_config_list {
+ struct afb_config_list *next;
+ char *value;
+};
+
+// main config structure
+struct afb_config {
+ char *console; // console device name (can be a file or a tty)
+ char *rootdir; // base dir for files
+ char *roothttp; // directory for http files
+ char *rootbase; // Angular HTML5 base URL
+ char *rootapi; // Base URL for REST APIs
+ char *workdir; // where to run the program
+ char *uploaddir; // where to store transient files
+ char *token; // initial authentication token [default NULL no session]
+
+ struct afb_config_list *aliases;
+ struct afb_config_list *dbus_clients;
+ struct afb_config_list *dbus_servers;
+ struct afb_config_list *ws_clients;
+ struct afb_config_list *ws_servers;
+ struct afb_config_list *so_bindings;
+ struct afb_config_list *ldpaths;
+
+ char **exec;
+
+ int httpdPort;
+ int background; // run in backround mode
+ int cacheTimeout;
+ int apiTimeout;
+ int cntxTimeout; // Client Session Context timeout
+ int nbSessionMax; // max count of sessions
+ int mode; // mode of listening
+ int tracereq;
+ int noHttpd;
+};
+
+extern struct afb_config *parse_arguments(int argc, char **argv); \ No newline at end of file