\r
include_directories(SYSTEM 3rdparty/json)\r
\r
-find_package(Boost REQUIRED COMPONENTS program_options filesystem system)\r
-if(Boost_FOUND)\r
- add_definitions(${Boost_LIB_DIAGNOSTIC_DEFINITIONS})\r
- include_directories(SYSTEM ${Boost_INCLUDE_DIRS})\r
+add_executable(can-config-generator\r
+ src/main.cpp\r
+ src/openxc/message_set.cpp\r
+ src/openxc/can_bus.cpp\r
+ src/openxc/can_message.cpp\r
+ src/openxc/command.cpp\r
+ src/openxc/diagnostic_message.cpp\r
+ src/openxc/mapping.cpp\r
+ src/openxc/signal.cpp)\r
\r
- add_executable(can-config-generator\r
- src/main.cpp\r
- src/openxc/message_set.cpp\r
- src/openxc/can_bus.cpp\r
- src/openxc/can_message.cpp\r
- src/openxc/command.cpp\r
- src/openxc/diagnostic_message.cpp\r
- src/openxc/mapping.cpp\r
- src/openxc/signal.cpp)\r
-\r
- target_link_libraries(can-config-generator ${Boost_LIBRARIES})\r
- target_compile_features(can-config-generator PRIVATE cxx_range_for cxx_constexpr cxx_nullptr)\r
-endif()\r
+target_link_libraries(can-config-generator)\r
+target_compile_features(can-config-generator PRIVATE cxx_range_for cxx_constexpr cxx_nullptr)\r
+/*\r
+ * Copyright (C) 2015, 2016 "IoT.bzh"\r
+ * Author "Loïc Collignon" <loic.collignon@iot.bzh>\r
+ * Author "Romain Forlot" <romain.forlot@iot.bzh>\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+#include <unistd.h>\r
+#include <stdlib.h>\r
+#include <libgen.h>\r
#include <exception>\r
#include <fstream>\r
#include <iostream>\r
#include <string>\r
#include <numeric>\r
#include <iterator>\r
-#include <boost/program_options.hpp>\r
-#include <boost/filesystem.hpp>\r
#include <json.hpp>\r
#include "openxc/message_set.hpp"\r
\r
throw std::runtime_error(ss.str());\r
}\r
\r
+// function that show the help information\r
+void showhelpinfo(char *s)\r
+{\r
+std::cout<<"Usage: "<<s<<" <-m inpout.json> [-o configuration-generated.cpp]"<< std::endl;\r
+std::cout<<"option: "<<"-m input.json : JSON file describing CAN messages and signals"<< std::endl;\r
+std::cout<<" "<<"-h header.cpp : header source file insert at the beginning of generated file"<< std::endl;\r
+std::cout<<" "<<"-f footer.cpp : footer source file append to generated file."<< std::endl;\r
+std::cout<<" "<<"-o configuration-generated.cpp : output source file. Name has to be configuration-generated.cpp"<< std::endl;\r
+}\r
+\r
/// @brief Entry point.\r
/// @param[in] argc Argument's count.\r
/// @param[in] argv Argument's array.\r
/// @return Exit code, zero if success.\r
-int main(int argc, char** argv)\r
+int main(int argc, char *argv[])\r
{\r
- //std::ios::sync_with_stdio(false);\r
- \r
try\r
{\r
- std::string appName = boost::filesystem::basename(argv[0]);\r
+ std::string appName = argv[0];\r
std::string message_set_file;\r
std::string output_file;\r
std::string header_file;\r
std::string footer_file;\r
\r
- namespace bpo = boost::program_options;\r
- bpo::options_description desc("Options");\r
- desc.add_options()\r
- ("help,h", "Display this help.")\r
- ("message-set,m", bpo::value<std::string>(&message_set_file)->required(), "The message set definition file.")\r
- ("output,o", bpo::value<std::string>(&output_file), "An output file, if not specified stdout is used.")\r
- ("header,h", bpo::value<std::string>(&header_file), "A file to copy at the top of the generated output.")\r
- ("footer,f", bpo::value<std::string>(&footer_file), "A file to copy at the end of the generated output.");\r
-\r
- bpo::variables_map vm;\r
- try\r
+ char tmp;\r
+ /*if the program is ran witout options ,it will show the usgage and exit*/\r
+ if(argc == 1)\r
{\r
- bpo::store(bpo::parse_command_line(argc, argv, desc), vm);\r
-\r
- if (vm.count("help"))\r
+ showhelpinfo(argv[0]);\r
+ exit(1);\r
+ }\r
+ /*use function getopt to get the arguments with option."hu:p:s:v" indicate \r
+ that option h,v are the options without arguments while u,p,s are the\r
+ options with arguments*/\r
+ while((tmp=getopt(argc,argv,"m:h:f:o:"))!=-1)\r
+ {\r
+ switch(tmp)\r
{\r
- std::cout << desc << std::endl;\r
- return EXIT_SUCCESS;\r
+ case 'h':\r
+ header_file = optarg;\r
+ break;\r
+ case 'f':\r
+ footer_file = optarg;\r
+ break;\r
+ case 'm':\r
+ message_set_file = optarg;\r
+ break;\r
+ case 'o':\r
+ output_file = optarg;\r
+ break;\r
+ default:\r
+ showhelpinfo(argv[0]);\r
+ break;\r
}\r
+ }\r
\r
- bpo::notify(vm);\r
-\r
- std::stringstream header;\r
- header << read_file(header_file);\r
- \r
- std::string footer = read_file(footer_file);\r
- openxc::message_set message_set;\r
- message_set.from_json(read_json(message_set_file));\r
-\r
- boost::filesystem::path message_set_path(message_set_file);\r
- message_set_path.remove_filename();\r
- for(const auto& s : message_set.extra_sources())\r
- {\r
- boost::filesystem::path extra_source(s);\r
- if (!extra_source.is_complete()) extra_source = message_set_path / extra_source;\r
- header << "\n// >>>>> " << s << " >>>>>\n" << read_file(extra_source.string()) << "\n// <<<<< " << s << " <<<<<\n";\r
- }\r
+ std::stringstream header;\r
+ header << read_file(header_file);\r
\r
- std::ofstream out;\r
- if (output_file.size())\r
- {\r
- out.open(output_file);\r
- if(!out)\r
- {\r
- std::stringstream ss;\r
- ss << "Can't open the ouput file (" << output_file << ") for writing!";\r
- throw std::runtime_error(ss.str());\r
- }\r
- }\r
- \r
- generate(header.str(), footer, message_set, output_file.size() ? out : std::cout); \r
+ std::string footer = read_file(footer_file);\r
+ openxc::message_set message_set;\r
+ message_set.from_json(read_json(message_set_file));\r
\r
- }\r
- catch (bpo::required_option& e)\r
+ std::string message_set_path = dirname(strdup(message_set_file.c_str()));\r
+ for(const auto& s : message_set.extra_sources())\r
{\r
- std::cerr << "ERROR: Argument required - " << e.what() << std::endl;\r
- std::cout << desc << std::endl;\r
- return EXIT_COMMAND_LINE_ERROR;\r
+ std::string extra_source = s;\r
+ extra_source = message_set_path + "/" + extra_source;\r
+ header << "\n// >>>>> " << s << " >>>>>\n" << read_file(extra_source) << "\n// <<<<< " << s << " <<<<<\n";\r
}\r
- catch (bpo::error& e)\r
- {\r
- std::cerr << "ERROR: Command line error - " << e.what() << std::endl;\r
- std::cout << desc << std::endl;\r
- return EXIT_COMMAND_LINE_ERROR;\r
- }\r
- catch(std::exception& e)\r
+\r
+ std::ofstream out;\r
+ if (output_file.size())\r
{\r
- std::cerr << "ERROR: " << e.what() << std::endl;\r
- return EXIT_PROGRAM_ERROR;\r
+ out.open(output_file);\r
+ if(!out)\r
+ {\r
+ std::stringstream ss;\r
+ ss << "Can't open the ouput file (" << output_file << ") for writing!";\r
+ throw std::runtime_error(ss.str());\r
+ }\r
}\r
+ generate(header.str(), footer, message_set, output_file.size() ? out : std::cout); \r
}\r
catch (std::exception& e)\r
{\r
std::cerr << "ERROR: Unhandled exception - " << e.what() << std::endl;\r
return EXIT_UNKNOWN_ERROR;\r
}\r
-\r
return EXIT_SUCCESS;\r
}\r
--- /dev/null
+/*
+ * 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