Paul Stewart | c2350ee | 2011-10-19 12:28:40 -0700 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium OS 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 | |
Ben Chan | c45688b | 2014-07-02 23:50:45 -0700 | [diff] [blame] | 5 | #ifndef SHILL_SHILL_ARES_H_ |
| 6 | #define SHILL_SHILL_ARES_H_ |
Paul Stewart | c2350ee | 2011-10-19 12:28:40 -0700 | [diff] [blame] | 7 | |
| 8 | #include <ares.h> |
| 9 | |
| 10 | #include <base/lazy_instance.h> |
| 11 | |
| 12 | namespace shill { |
| 13 | |
| 14 | // A "ares.h" abstraction allowing mocking in tests. |
| 15 | class Ares { |
| 16 | public: |
| 17 | virtual ~Ares(); |
| 18 | |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 19 | static Ares* GetInstance(); |
Paul Stewart | c2350ee | 2011-10-19 12:28:40 -0700 | [diff] [blame] | 20 | |
| 21 | // ares_destroy |
| 22 | virtual void Destroy(ares_channel channel); |
| 23 | |
| 24 | // ares_gethostbyname |
| 25 | virtual void GetHostByName(ares_channel channel, |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 26 | const char* hostname, |
Paul Stewart | c2350ee | 2011-10-19 12:28:40 -0700 | [diff] [blame] | 27 | int family, |
| 28 | ares_host_callback callback, |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 29 | void* arg); |
Paul Stewart | c2350ee | 2011-10-19 12:28:40 -0700 | [diff] [blame] | 30 | |
| 31 | // ares_getsock |
| 32 | virtual int GetSock(ares_channel channel, |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 33 | ares_socket_t* socks, |
Paul Stewart | c2350ee | 2011-10-19 12:28:40 -0700 | [diff] [blame] | 34 | int numsocks); |
| 35 | |
| 36 | // ares_init_options |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 37 | virtual int InitOptions(ares_channel* channelptr, |
| 38 | struct ares_options* options, |
Paul Stewart | c2350ee | 2011-10-19 12:28:40 -0700 | [diff] [blame] | 39 | int optmask); |
| 40 | |
| 41 | // ares_process_fd |
| 42 | virtual void ProcessFd(ares_channel channel, |
| 43 | ares_socket_t read_fd, |
| 44 | ares_socket_t write_fd); |
| 45 | |
| 46 | // ares_set_local_dev |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 47 | virtual void SetLocalDev(ares_channel channel, const char* local_dev_name); |
Paul Stewart | c2350ee | 2011-10-19 12:28:40 -0700 | [diff] [blame] | 48 | |
| 49 | // ares_timeout |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 50 | virtual struct timeval* Timeout(ares_channel channel, |
| 51 | struct timeval* maxtv, |
| 52 | struct timeval* tv); |
Paul Stewart | c2350ee | 2011-10-19 12:28:40 -0700 | [diff] [blame] | 53 | |
Peter Qiu | f3a8f90 | 2014-08-20 10:05:42 -0700 | [diff] [blame] | 54 | // ares_set_servers_csv |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 55 | virtual int SetServersCsv(ares_channel channel, const char* servers); |
Peter Qiu | f3a8f90 | 2014-08-20 10:05:42 -0700 | [diff] [blame] | 56 | |
Paul Stewart | c2350ee | 2011-10-19 12:28:40 -0700 | [diff] [blame] | 57 | protected: |
| 58 | Ares(); |
| 59 | |
| 60 | private: |
| 61 | friend struct base::DefaultLazyInstanceTraits<Ares>; |
| 62 | |
| 63 | DISALLOW_COPY_AND_ASSIGN(Ares); |
| 64 | }; |
| 65 | |
| 66 | } // namespace shill |
| 67 | |
Ben Chan | c45688b | 2014-07-02 23:50:45 -0700 | [diff] [blame] | 68 | #endif // SHILL_SHILL_ARES_H_ |