summaryrefslogtreecommitdiffstats
path: root/example/asio-example.cpp
Commit message (Collapse)AuthorAgeFilesLines
* asio: Allow mutable lambdas + small cleanupJames Feist2019-06-041-3/+6
| | | | | | | | | | | | | | | | There are many cases in which we want to have a mutable capture so that the lambda takes over the parameter and we can modify it after the async callback. By making the top level lambda mutable, the users callback can be mutable. Also remove a couple references to experimental and a copy that I saw when I was fixing this issue. Tested: Added test and made sure that refish which uses many async_method_calls still worked fine Change-Id: Ifb1f9d8b9217187799e2defe429e76a937297ca1 Signed-off-by: James Feist <james.feist@linux.intel.com>
* Change async_method_call to be no-throwVernon Mauery2019-05-161-10/+51
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The async_method_call() would throw despite the inferred promise that it would not, because the handler would be passed an error_code object. But that would only protect from the dbus method call itself. When it came time to unpack the response, the read_into_tuple(...) method call would throw if the received types did not match the expected types. And because this throw would happen in a separate boost::asio context, the throw would always be fatal. Now, any exception during the D-Bus call or unpacking of parameters will result in an error_code getting passed into the handler so it can take appropriate action. This also updates the example to remove try/catch statements around the async_method_call and yield_method_call examples and shows what happens if the method calls fail because of different types of errors (api/function does not exist vs. incorrect unpack types). Tested-by: run asio-example to see that it works as expected: # /tmp/asio-example voidBar() -> 42 fooYield(yield, 41)... async_send callback error with async_send ipmiInterface:execute(61) async_method_call callback /org/openbmc/control/bmc0 /org/openbmc/control/flash/bmc fooYield(yield, 41)... ipmi call returns OK! foo(41) -> 42 async_method_call callback async_method_call expected failure: generic:foo(41) -> 42 yielding call to foo OK! (-> 42) 22 async call to Properties.Get serialized via yield OK! TestYieldFunction return 42 yielding call to foo OK! (-> 42) yielding call to TestYieldFunction serialized via yield OK! fooYield(yield, 41)... foo(41) -> 42 async call to Properties.Get serialized via yield OK! yielding call to foo OK! (-> 42) TestYieldFunction expected error: generic:22 TestYieldFunctionNotExits expected error: generic:53 *** tick *** *** tock *** *** tick *** *** tick *** *** tick *** Change-Id: I53c91484ed496556342b3ed0a58b690872a2d676 Signed-off-by: Vernon Mauery <vernon.mauery@linux.intel.com> stuff Change-Id: I48da27be7ba8c63f44c12a8b79fffb8f3e085648 Signed-off-by: Vernon Mauery <vernon.mauery@linux.intel.com>
* Change yield_method_call to be no-throwVernon Mauery2019-05-101-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The yield_method_call() would throw despite the inferred promise that it would not, because the caller could attach an error_code to the yield object. But that would only protect from the dbus method call itself. When it came time to unpack the response, the read(...) method call would throw if the received types did not match the expected types. Now, the method forces you to pass in an error_code and it will always return the appropriate error instead of throw. Tested-by: run asio-example to see that it works as expected: # /tmp/asio-example voidBar() -> 42 async_send callback error with async_send async_method_call callback /org/openbmc/control/bmc0 /org/openbmc/control/flash/bmc fooYield(yield, 41)... ipmiInterface:execute(61) ipmi call returns OK! fooYield(yield, 41)... foo(41) -> 42 async call to Properties.Get serialized via yield OK! foo(41) -> 42 yielding call to foo OK! (-> 42) TestYieldFunction return 42 yielding call to foo OK! (-> 42) yielding call to TestYieldFunction serialized via yield OK! async call to Properties.Get serialized via yield OK! *** tick *** *** tock *** *** tick *** *** tick *** *** tick *** *** tick *** *** tick *** Change-Id: Iea43acd432107b4149f8e549310cfce2518cbc1d Signed-off-by: Vernon Mauery <vernon.mauery@linux.intel.com>
* std::variant: Remove uses of the variant_nsWilliam A. Kennington III2019-04-051-9/+6
| | | | | | | | | | | Now that we are using std::variant we should reference it directly instead of using our own namespace alias. Tested: Built and ran through unit tests. Change-Id: Ic3fd62ea74cf808b85ad7b7ffcce8c0a0bfb125d Signed-off-by: William A. Kennington III <wak@google.com>
* Move asio interfaces away from deprecated namesEd Tanous2019-01-121-2/+2
| | | | | | | | | | | | | | | The intent of this commit is to allow building asio based event loops in applications with BOOST_ASIO_NO_DEPRECATED flag set. This change is largely a sed replace of io_service with io_context. This will allow us to move to the networking TS at such time that it is mature. Details on depreated interfaces are available here for reference: https://www.boost.org/doc/libs/1_69_0/doc/html/boost_asio/net_ts.html Change-Id: Ie3cc699effcf855a649dee5bfce2f6616109429b Signed-off-by: Ed Tanous <ed.tanous@intel.com>
* asio: Update variant usageYong Li2018-12-131-4/+8
| | | | | | | | | | | | | After the below change in sdbusplus, the variant usage needs to be switched to std::variant https://github.com/openbmc/sdbusplus/commit/90778b430290c9ec8c33fb77b03e2552d9dd6905 Tested: ./configure --enable-boost make Change-Id: Ic1d156ad379eb56822f75e8046f83fa45f4ad56d Signed-off-by: Yong Li <yong.b.li@linux.intel.com>
* Add sdbusplus::asio coroutine method handlingVernon Mauery2018-10-241-61/+223
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Adding the server-side of the coroutine path allows yielding asynchronous method handling via coroutines. This means that a method handler can call a yielding dbus call (or other asio-based asynchronous call) without blocking the rest of the process. The call path might look something like this: service.thing/object/path/interface.my-method() - do something - yield_method_call(other.service, /other/path, other.interface, other-method) <yields to other coroutine> execute other code in another context <returns some time later with dbus call's response> - use response from other method <- return my-method response This also changes the asio-example, pulling it apart into a client/server model so it is more clear about how to use the yielding async method handling and yielding async method calls. Change-Id: I23ccf7a9a8dff787be78929959c1f018280a0392 Signed-off-by: Vernon Mauery <vernon.mauery@linux.intel.com>
* Add coroutine support for sdbusplus::asio method callsVernon Mauery2018-10-121-1/+74
| | | | | | | | | | | | | | | | | Using a coroutine to asynchronously execute method calls gives the best of both worlds: 1) better readability because the code reads like synchronous code 2) better throughput because it is actually asynchronous When passed in a boost::asio::yield_context, the sdbusplus::asio dbus connection members async_send and async_method_call will execute asynchronously using coroutines. This also adds an example of how this works in the example/asio-example.cpp file. Change-Id: Ifb71b2c757ecbfd16b3be95bdefc45a701ca0d51 Signed-off-by: Vernon Mauery <vernon.mauery@linux.intel.com>
* sdbus::asio: service sd_event loop upon requestVernon Mauery2018-09-171-0/+11
| | | | | | | | | | | | | If requested, add in an asynchronous sd_event servicing mechanism so sd_events can be used in conjunction with boost::asio events. Code throughout the openbmc repositories use sd_events, especially for timers. In some cases, we may want to add boost::asio event handling for superior asynchronous eventing, but not want to rewrite all the existing sd_event code. This gives us the best of both worlds, with a low-overhead mechanism to handle the sd_events. Change-Id: I3f8e2aafa3f733439e1494253698d17c2f3a2321 Signed-off-by: Vernon Mauery <vernon.mauery@linux.intel.com>
* sdbusplus::asio: fix callback with void args specializationVernon Mauery2018-09-051-0/+7
| | | | | | | | | | | | | | | Callbacks with no arguments failed to build due to an error in the utility::get_first_arg template. It failed to provide a type member for the void specialization. With this fix, it is possible to have a handler that has no arguments. Tested by: Added a new callback to the asio-example.cpp. Without the template change, this caused the build to fail as expected. After adding the template change, the build succeeds and the example runs as expected. Change-Id: Ib09b58c76df8cba57dc093ab37a4c1b68ea11ad3 Signed-off-by: Vernon Mauery <vernon.mauery@linux.intel.com>
* update .clang-format header inclusion orderPatrick Venture2018-08-311-5/+5
| | | | | | | | Added the header inclusion order to the .clang-format file generated these changes. Change-Id: Ia31b21d7ea451cac0309828006bc17c27cbd5bd5 Signed-off-by: Patrick Venture <venture@google.com>
* Allow callback raw access to messageVernon Mauery2018-08-281-1/+7
| | | | | | | | | | | | | | | | | | | | | In some cases, the callback may care where the message came from. Allow the callback to receive the raw sdbusplus::message along with the automatically extracted arguments. This means that the registration mechanism as well as the callback mechanism need to be aware of a 'message as a first parameter' situation and behave accordingly. The registration needs to strip the message parameter off in order to expose a correct DBus signature. The callback mechanism needs to strip of the message parameter in order to properly unpack the message, but add it back in before calling apply to execute the function. Tested: Added an example to example/asio-example.cpp and checked to see that it builds. Was able to extract sender from message passed into the IPMI handler. Change-Id: I520e494d3baad34271e748465f30274353554728 Signed-off-by: Vernon Mauery <vernon.mauery@linux.intel.com>
* Add sbusplus properties serverJames Feist2018-06-271-0/+58
| | | | | | | | | | | | | | | | | Add properties server similar to boost-dbus that allows for creating dbus interfaces during runtime. This adds support for creating methods and get / set properties. Get / set property callbacks are stored in flat_maps of std::function allowing custom get / set functions. Methods are also stored in this way allowing for creating of interfaces without using any yaml. There is one C level callback for properties get, properties set, and method calls that lookup the correct std::function in the flat_map to call. Tested: Ran asio-example on bmc, and updated fru-device. Change-Id: I19881049f4307fe9c68f78df8854f14afdd6c362 Signed-off-by: James Feist <james.feist@linux.intel.com>
* Add boost asio async connectionJames Feist2018-06-271-0/+65
Add an async connection and example of usage. This connection inherits the bus object and allows async method calls using boost asio. Most of these concepts are from boost-dbus. Change-Id: I33b5349d543c9ff4b6ee1ce15346c709c052e1ae Tested: Compiled and ran asio-example on bmc. Signed-off-by: James Feist <james.feist@linux.intel.com>
OpenPOWER on IntegriCloud