1 // Copyright 2015 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include <libwebserv/server.h>
16 
17 #if defined(WEBSERV_USE_DBUS)
18 #include "libwebserv/dbus_server.h"
19 #endif  // defined(WEBSERV_USE_DBUS)
20 
21 #if defined(WEBSERV_USE_BINDER)
22 #include "libwebserv/binder_server.h"
23 #endif  // defined(WEBSERV_USE_BINDER)
24 
25 using std::unique_ptr;
26 
27 namespace libwebserv {
28 
29 #if defined(WEBSERV_USE_DBUS)
ConnectToServerViaDBus(const scoped_refptr<dbus::Bus> & bus,const std::string & service_name,const brillo::dbus_utils::AsyncEventSequencer::CompletionAction & cb,const base::Closure & on_server_online,const base::Closure & on_server_offline)30 unique_ptr<Server> Server::ConnectToServerViaDBus(
31     const scoped_refptr<dbus::Bus>& bus,
32     const std::string& service_name,
33     const brillo::dbus_utils::AsyncEventSequencer::CompletionAction& cb,
34     const base::Closure& on_server_online,
35     const base::Closure& on_server_offline) {
36   DBusServer* server = new DBusServer;
37   unique_ptr<Server> ret(server);
38   server->Connect(bus, service_name, cb, on_server_online, on_server_offline);
39   return ret;
40 }
41 #endif  // defined(WEBSERV_USE_DBUS)
42 
43 #if defined(WEBSERV_USE_BINDER)
ConnectToServerViaBinder(brillo::MessageLoop * message_loop,const base::Closure & on_server_online,const base::Closure & on_server_offline)44 std::unique_ptr<Server> ConnectToServerViaBinder(
45     brillo::MessageLoop* message_loop,
46     const base::Closure& on_server_online,
47     const base::Closure& on_server_offline) {
48   return unique_ptr<Server>(new BinderServer(
49       message_loop, on_server_online, on_server_offline,
50       android::BinderWrapper::GetOrCreateInstance()));
51 }
52 #endif  // defined(WEBSERV_USE_BINDER)
53 
54 }  // namespace libwebserv
55