From 36adc76235fb0a38e7042bc751f988b71627e2a0 Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Tue, 11 Dec 2012 06:13:02 +0000 Subject: Changes to get successful C++11 based build. Code cleanup, dependency upgrades, and const + inline optimizations in components, samples, and app hosting server. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1420007 13f79535-47bb-0310-9956-ffa450edef68 --- sca-cpp/trunk/components/http/httpget.cpp | 58 ++++++++++--------------------- 1 file changed, 18 insertions(+), 40 deletions(-) (limited to 'sca-cpp/trunk/components/http/httpget.cpp') diff --git a/sca-cpp/trunk/components/http/httpget.cpp b/sca-cpp/trunk/components/http/httpget.cpp index 884dc1a6ff..b4504d939a 100644 --- a/sca-cpp/trunk/components/http/httpget.cpp +++ b/sca-cpp/trunk/components/http/httpget.cpp @@ -38,59 +38,37 @@ namespace httpget { /** * Evaluate an HTTP get. */ -const failable get(const lambda&)>& url, http::CURLSession& ch) { +const failable get(const lvvlambda& url, const http::CURLSession& ch) { debug("httpget::get"); - const value u = url(mklist("get", list())); + const value u = url(mklist("get", nilListValue)); debug(u, "httpget::get::url"); return http::get(u, ch); } /** - * Component implementation lambda function. + * Start the component. */ -class applyhttp { -public: - applyhttp(const lambda&)>& url, const perthread_ptr& ch) : url(url), ch(ch) { - } +const failable start(const list& params) { + // Create a CURL session + const lvvlambda timeout = cadr(params); + const gc_pool cp(gc_current_pool()); + const lambda()> newsession = [timeout, cp]() -> const gc_ptr { + const gc_scoped_pool sp(pool(cp)); + const int t = atoi(c_str((string)timeout(nilListValue))); + return new (gc_new()) http::CURLSession(emptyString, emptyString, emptyString, emptyString, t); + }; + const perthread_ptr ch = *(new (gc_new >()) perthread_ptr(newsession)); - const value operator()(const list& params) const { + // Return the component implementation lambda function + const lvvlambda url = car(params); + const lvvlambda applyhttp = [url, ch](const list& params) -> const value { debug(params, "httpget::applyhttp::params"); const value func(car(params)); if (func == "get") return get(url, *ch); return mkfailure(); - } - -private: - const lambda&)> url; - perthread_ptr ch; -}; - - -/** - * Create a new CURL session. - */ -class newsession { -public: - newsession(const lambda&)>& timeout) : timeout(timeout) { - } - const gc_ptr operator()() const { - const int t = atoi(c_str((string)timeout(list()))); - return new (gc_new()) http::CURLSession("", "", "", "", t); - } -private: - const lambda&)> timeout; -}; - -/** - * Start the component. - */ -const failable start(const list& params) { - // Create a CURL session - const perthread_ptr ch = perthread_ptr(lambda()>(newsession(cadr(params)))); - - // Return the component implementation lambda function - return value(lambda&)>(applyhttp(car(params), ch))); + }; + return value(applyhttp); } } -- cgit v1.2.3