diff options
Diffstat (limited to 'gentoobrowse-api/client')
-rw-r--r-- | gentoobrowse-api/client/helpers.h | 13 | ||||
-rw-r--r-- | gentoobrowse-api/client/main.cpp | 17 | ||||
-rw-r--r-- | gentoobrowse-api/client/main.h | 9 | ||||
-rw-r--r-- | gentoobrowse-api/client/search.cpp | 31 |
4 files changed, 33 insertions, 37 deletions
diff --git a/gentoobrowse-api/client/helpers.h b/gentoobrowse-api/client/helpers.h index 76f8148..96399d2 100644 --- a/gentoobrowse-api/client/helpers.h +++ b/gentoobrowse-api/client/helpers.h @@ -1,14 +1,15 @@ #ifndef GENTOOBROWSE_CLIENT_HELPERS_H #define GENTOOBROWSE_CLIENT_HELPERS_H -#include <map> #include <Ice/AsyncResult.h> +#include <Ice/ObjectAdapter.h> +#include <future> +#include <map> #include <mutex> template<typename Key, typename Target, typename Collection, typename Proxy> std::map<Key, Target> -asyncMapRelated(const Collection & collection, const Proxy & p, - Key Collection::value_type::element_type::* member, +asyncMapRelated(const Collection & collection, const Proxy & p, Key Collection::value_type::element_type::*member, std::future<Target> (Proxy::element_type::*b)(Key, const ::Ice::Context &)) { std::map<Key, Target> rtn; @@ -16,15 +17,13 @@ asyncMapRelated(const Collection & collection, const Proxy & p, for (const auto & item : collection) { Key v = item.get()->*member; if (jobs.find(v) == jobs.end()) { - jobs.insert({ v, (p.get()->*b)(v, Ice::noExplicitContext) }); + jobs.insert({v, (p.get()->*b)(v, Ice::noExplicitContext)}); } } for (auto & j : jobs) { - rtn.insert({ j.first, j.second.get() }); + rtn.insert({j.first, j.second.get()}); } return rtn; } - #endif - diff --git a/gentoobrowse-api/client/main.cpp b/gentoobrowse-api/client/main.cpp index d542188..56f0a4b 100644 --- a/gentoobrowse-api/client/main.cpp +++ b/gentoobrowse-api/client/main.cpp @@ -1,9 +1,9 @@ -#include "stdio.h" #include "main.h" -#include <portage.h> -#include <plugins.impl.h> +#include "stdio.h" #include <Ice/Ice.h> #include <boost/program_options.hpp> +#include <plugins.impl.h> +#include <portage.h> namespace po = boost::program_options; INSTANTIATEPLUGINOF(Module); @@ -15,12 +15,10 @@ main(int c, char ** v) std::string module; std::vector<std::string> args; po::options_description opts("Gentoo Browse Client options"); - opts.add_options() - ("endpoint", po::value(&endpoint)->default_value("tcp -h gentoobrowse.randomdan.homeip.net -p 9001"), "Service endpoint") - ("module", po::value(&module), "Module") - ("args", po::value(&args), "Module options") - ("help,h", "Show help") - ; + opts.add_options()("endpoint", + po::value(&endpoint)->default_value("tcp -h gentoobrowse.randomdan.homeip.net -p 9001"), + "Service endpoint")("module", po::value(&module), "Module")("args", po::value(&args), "Module options")( + "help,h", "Show help"); po::positional_options_description pod; pod.add("module", 1).add("args", -1); po::variables_map vm; @@ -41,4 +39,3 @@ main(int c, char ** v) ic->destroy(); return 0; } - diff --git a/gentoobrowse-api/client/main.h b/gentoobrowse-api/client/main.h index 1f88081..9c7ccef 100644 --- a/gentoobrowse-api/client/main.h +++ b/gentoobrowse-api/client/main.h @@ -1,15 +1,14 @@ #ifndef GENTOO_MAIN_H #define GENTOO_MAIN_H -#include <vector> -#include <string> #include <plugins.h> #include <portage.h> +#include <string> +#include <vector> class Module : public AdHoc::AbstractPluginImplementation { - public: - virtual void run(const Gentoo::PortagePrxPtr &, const std::vector<std::string> &) const = 0; +public: + virtual void run(const Gentoo::PortagePrxPtr &, const std::vector<std::string> &) const = 0; }; #endif - diff --git a/gentoobrowse-api/client/search.cpp b/gentoobrowse-api/client/search.cpp index 448643b..9d1c7b4 100644 --- a/gentoobrowse-api/client/search.cpp +++ b/gentoobrowse-api/client/search.cpp @@ -1,22 +1,23 @@ -#include <plugins.h> -#include <fprintbf.h> -#include <boost/algorithm/string/join.hpp> -#include "main.h" #include "helpers.h" +#include "main.h" +#include <boost/algorithm/string/join.hpp> +#include <fprintbf.h> +#include <plugins.h> class search : public Module { - public: - void run(const Gentoo::PortagePrxPtr & p, const std::vector<std::string> & a) const override - { - auto pkgs = p->getPackagesSearch(boost::algorithm::join(a, " ")); - auto cats = asyncMapRelated(pkgs, p, &Gentoo::Package::categoryid, - (std::future<Gentoo::CategoryPtr> (Gentoo::PortagePrx::*)(Ice::Int, const ::Ice::Context &))&Gentoo::PortagePrx::getCategoryAsync); - fprintbf(stdout, "Found %d packages:\n", pkgs.size()); - for (const auto & pkg : pkgs) { - fprintbf(stdout, "%s / %s\n\t%s\n", cats[pkg->categoryid]->name, pkg->name, pkg->description); - } +public: + void + run(const Gentoo::PortagePrxPtr & p, const std::vector<std::string> & a) const override + { + auto pkgs = p->getPackagesSearch(boost::algorithm::join(a, " ")); + auto cats = asyncMapRelated(pkgs, p, &Gentoo::Package::categoryid, + (std::future<Gentoo::CategoryPtr>(Gentoo::PortagePrx::*)(Ice::Int, const ::Ice::Context &)) + & Gentoo::PortagePrx::getCategoryAsync); + fprintbf(stdout, "Found %d packages:\n", pkgs.size()); + for (const auto & pkg : pkgs) { + fprintbf(stdout, "%s / %s\n\t%s\n", cats[pkg->categoryid]->name, pkg->name, pkg->description); } + } }; PLUGIN(search, Module); - |