ilewis | f1fa93d | 2015-11-09 09:01:11 -0800 | [diff] [blame] | 1 | // Copyright 2015 The Weave Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef LIBWEAVE_EXAMPLES_PROVIDER_EVENT_DELETER_H |
| 6 | #define LIBWEAVE_EXAMPLES_PROVIDER_EVENT_DELETER_H |
| 7 | |
| 8 | #include <memory> |
| 9 | |
| 10 | #include <third_party/include/event2/event.h> |
| 11 | #include <third_party/include/event2/event_struct.h> |
| 12 | #include <third_party/include/event2/http.h> |
| 13 | |
| 14 | namespace weave { |
| 15 | namespace examples { |
| 16 | |
| 17 | // Defines overloaded deletion methods for various event_ objects |
| 18 | // so we can use one unique_ptr definition for all of them |
| 19 | class EventDeleter { |
| 20 | public: |
| 21 | void operator()(evhttp_uri* http_uri) { evhttp_uri_free(http_uri); } |
| 22 | void operator()(evhttp_connection* conn) { evhttp_connection_free(conn); } |
| 23 | void operator()(evhttp_request* req) { evhttp_request_free(req); } |
| 24 | void operator()(event_base* base) { event_base_free(base); } |
| 25 | void operator()(event* ev) { |
| 26 | event_del(ev); |
| 27 | event_free(ev); |
| 28 | } |
| 29 | }; |
| 30 | |
| 31 | template <typename T> |
| 32 | using EventPtr = std::unique_ptr<T, EventDeleter>; |
| 33 | |
| 34 | } // namespace examples |
| 35 | } // namespace weave |
| 36 | |
| 37 | #endif // LIBWEAVE_EXAMPLES_PROVIDER_EVENT_DELETER_H |