1d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley// Copyright 2016 The Android Open Source Project 2d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley// 3d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley// Licensed under the Apache License, Version 2.0 (the "License"); 4d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley// you may not use this file except in compliance with the License. 5d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley// You may obtain a copy of the License at 6d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley// 7d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley// http://www.apache.org/licenses/LICENSE-2.0 8d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley// 9d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley// Unless required by applicable law or agreed to in writing, software 10d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley// distributed under the License is distributed on an "AS IS" BASIS, 11d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley// See the License for the specific language governing permissions and 13d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley// limitations under the License. 14d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley 15d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley#ifndef WEBSERVER_LIBWEBSERV_BINDER_SERVER_H_ 16d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley#define WEBSERVER_LIBWEBSERV_BINDER_SERVER_H_ 17d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley 18d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley#include <map> 19d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley#include <memory> 20d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley#include <string> 21d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley#include <vector> 22d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley 23d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley#include <brillo/message_loops/message_loop.h> 24d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley#include <base/bind.h> 25d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley#include <base/macros.h> 26d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley#include <base/memory/weak_ptr.h> 27d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley 28d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley#include <binderwrapper/binder_wrapper.h> 29d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley#include <utils/StrongPointer.h> 30d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley#include <binder/IBinder.h> 31d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley 32d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley#include "android/webservd/IProtocolHandler.h" 33d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley#include "android/webservd/IServer.h" 34d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley#include "libwebserv/server.h" 35d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley 36d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wileynamespace libwebserv { 37d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley 38d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wileyclass ProtocolHandler; 39d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wileyclass BinderPHGroup; 40d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley 41d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wileyclass LIBWEBSERV_PRIVATE BinderServer : public Server { 42d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley public: 43d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley BinderServer(brillo::MessageLoop* message_loop, 44d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley const base::Closure& on_server_online, 45d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley const base::Closure& on_server_offline, 46d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley android::BinderWrapper* binder_wrapper); 47d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley ~BinderServer() override = default; 48d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley 49d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley ProtocolHandler* GetDefaultHttpHandler() override; 50d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley ProtocolHandler* GetDefaultHttpsHandler() override; 51d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley ProtocolHandler* GetProtocolHandler(const std::string& name) override; 52d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley 53d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley bool IsConnected() const override; 54d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley 55d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley void OnProtocolHandlerConnected( 56d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley const base::Callback<void(ProtocolHandler*)>& callback) override; 57d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley void OnProtocolHandlerDisconnected( 58d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley const base::Callback<void(ProtocolHandler*)>& callback) override; 59d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley 60d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley base::TimeDelta GetDefaultRequestTimeout() const override; 61d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley 62d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley private: 63d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley using RemoteServer = android::webservd::IServer; 64d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley using RemoteProtocolHandler = android::webservd::IProtocolHandler; 65d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley 66d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley void TryConnecting(); 67d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley void ClearLocalState(); 68d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley bool BuildLocalState(android::sp<android::IBinder> server); 69d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley 70d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley // Used to poll for webservd availability and notify the user of changes 71d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley brillo::MessageLoop* message_loop_; 72d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley base::Closure on_server_online_; 73d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley base::Closure on_server_offline_; 74d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley android::BinderWrapper* binder_wrapper_; 75d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley 76d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley android::sp<RemoteServer> remote_server_; 77d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley //std::map<std::string, std::unique_ptr<BinderPHGroup>> 78d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley // local_protocol_handlers_; 79d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley 80d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley base::WeakPtrFactory<BinderServer> weak_ptr_factory_{this}; 81d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley DISALLOW_COPY_AND_ASSIGN(BinderServer); 82d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley}; 83d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley 84d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley} // namespace libwebserv 85d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley 86d6197ec257b6ae5233e99f775cfeb2f368bb9391Christopher Wiley#endif // WEBSERVER_LIBWEBSERV_BINDER_SERVER_H_ 87