summaryrefslogtreecommitdiffstats
path: root/src
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 /src
parentad366bd680d5ce0bef49242cf6b3902fe46e0141 (diff)
Remove boost library dependency.
Use a simple optarg parser. Change-Id: If0cd9da9db24a7889573e32f6b8ace33702c2c35 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp149
-rw-r--r--src/main.hpp55
2 files changed, 137 insertions, 67 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 55f956e..cfefed8 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 0000000..cf08e1a
--- /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