• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright (C) 2011 The Android Open Source Project
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 #ifndef SHILL_SHILL_ARES_H_
18 #define SHILL_SHILL_ARES_H_
19 
20 #include <ares.h>
21 
22 #include <base/lazy_instance.h>
23 
24 namespace shill {
25 
26 // A "ares.h" abstraction allowing mocking in tests.
27 class Ares {
28  public:
29   virtual ~Ares();
30 
31   static Ares* GetInstance();
32 
33   // ares_destroy
34   virtual void Destroy(ares_channel channel);
35 
36   // ares_gethostbyname
37   virtual void GetHostByName(ares_channel channel,
38                              const char* hostname,
39                              int family,
40                              ares_host_callback callback,
41                              void* arg);
42 
43   // ares_getsock
44   virtual int GetSock(ares_channel channel,
45                       ares_socket_t* socks,
46                       int numsocks);
47 
48   // ares_init_options
49   virtual int InitOptions(ares_channel* channelptr,
50                           struct ares_options* options,
51                           int optmask);
52 
53   // ares_process_fd
54   virtual void ProcessFd(ares_channel channel,
55                          ares_socket_t read_fd,
56                          ares_socket_t write_fd);
57 
58   // ares_set_local_dev
59   virtual void SetLocalDev(ares_channel channel, const char* local_dev_name);
60 
61   // ares_timeout
62   virtual struct timeval* Timeout(ares_channel channel,
63                                   struct timeval* maxtv,
64                                   struct timeval* tv);
65 
66   // ares_set_servers_csv
67   virtual int SetServersCsv(ares_channel channel, const char* servers);
68 
69  protected:
70   Ares();
71 
72  private:
73   friend struct base::DefaultLazyInstanceTraits<Ares>;
74 
75   DISALLOW_COPY_AND_ASSIGN(Ares);
76 };
77 
78 }  // namespace shill
79 
80 #endif  // SHILL_SHILL_ARES_H_
81