blob: d2659e935cf2e09e44410d53190c744e7d4c1f4f [file] [log] [blame]
Paul Stewartc2350ee2011-10-19 12:28:40 -07001// 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 Chanc45688b2014-07-02 23:50:45 -07005#ifndef SHILL_SHILL_ARES_H_
6#define SHILL_SHILL_ARES_H_
Paul Stewartc2350ee2011-10-19 12:28:40 -07007
8#include <ares.h>
9
10#include <base/lazy_instance.h>
11
12namespace shill {
13
14// A "ares.h" abstraction allowing mocking in tests.
15class Ares {
16 public:
17 virtual ~Ares();
18
Paul Stewart1a212a62015-06-16 13:13:10 -070019 static Ares* GetInstance();
Paul Stewartc2350ee2011-10-19 12:28:40 -070020
21 // ares_destroy
22 virtual void Destroy(ares_channel channel);
23
24 // ares_gethostbyname
25 virtual void GetHostByName(ares_channel channel,
Paul Stewart1a212a62015-06-16 13:13:10 -070026 const char* hostname,
Paul Stewartc2350ee2011-10-19 12:28:40 -070027 int family,
28 ares_host_callback callback,
Paul Stewart1a212a62015-06-16 13:13:10 -070029 void* arg);
Paul Stewartc2350ee2011-10-19 12:28:40 -070030
31 // ares_getsock
32 virtual int GetSock(ares_channel channel,
Paul Stewart1a212a62015-06-16 13:13:10 -070033 ares_socket_t* socks,
Paul Stewartc2350ee2011-10-19 12:28:40 -070034 int numsocks);
35
36 // ares_init_options
Paul Stewart1a212a62015-06-16 13:13:10 -070037 virtual int InitOptions(ares_channel* channelptr,
38 struct ares_options* options,
Paul Stewartc2350ee2011-10-19 12:28:40 -070039 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 Stewart1a212a62015-06-16 13:13:10 -070047 virtual void SetLocalDev(ares_channel channel, const char* local_dev_name);
Paul Stewartc2350ee2011-10-19 12:28:40 -070048
49 // ares_timeout
Paul Stewart1a212a62015-06-16 13:13:10 -070050 virtual struct timeval* Timeout(ares_channel channel,
51 struct timeval* maxtv,
52 struct timeval* tv);
Paul Stewartc2350ee2011-10-19 12:28:40 -070053
Peter Qiuf3a8f902014-08-20 10:05:42 -070054 // ares_set_servers_csv
Paul Stewart1a212a62015-06-16 13:13:10 -070055 virtual int SetServersCsv(ares_channel channel, const char* servers);
Peter Qiuf3a8f902014-08-20 10:05:42 -070056
Paul Stewartc2350ee2011-10-19 12:28:40 -070057 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 Chanc45688b2014-07-02 23:50:45 -070068#endif // SHILL_SHILL_ARES_H_