call.hpp
1 /** 2 * This file is part of Darling. 3 * 4 * Copyright (C) 2021 Darling developers 5 * 6 * Darling is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * Darling is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with Darling. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 #ifndef _DARLINGSERVER_CALL_HPP_ 21 #define _DARLINGSERVER_CALL_HPP_ 22 23 #include <darlingserver/rpc.h> 24 #include <darlingserver/rpc.internal.h> 25 26 #include <darlingserver/message.hpp> 27 #include <darlingserver/registry.hpp> 28 #include <darlingserver/logging.hpp> 29 30 #include <memory> 31 32 #include <unistd.h> 33 34 namespace DarlingServer { 35 class CallWithReply; 36 37 class Call { 38 public: 39 enum class Number: unsigned int { 40 Invalid = dserver_callnum_invalid, 41 DSERVER_ENUM_VALUES 42 }; 43 44 static inline const char* callNumberToString(Number number) { 45 return dserver_callnum_to_string(static_cast<dserver_callnum_t>(number)); 46 }; 47 48 protected: 49 std::weak_ptr<Thread> _thread; 50 Address _replyAddress; 51 dserver_rpc_callhdr_t _header; 52 53 static DarlingServer::Log rpcReplyLog; 54 55 static void sendReply(Message&& reply); 56 57 public: 58 Call(std::shared_ptr<Thread> thread, Address replyAddress, dserver_rpc_callhdr_t* callHeader); 59 virtual ~Call(); 60 61 static std::shared_ptr<Call> callFromMessage(Message&& requestMessage); 62 63 virtual Number number() const = 0; 64 std::shared_ptr<Thread> thread() const; 65 66 virtual void processCall() = 0; 67 68 virtual void sendBasicReply(int resultCode); 69 // FIXME: this should actually be in a "BSD" subclass with BSD traps inheriting from it 70 virtual void sendBSDReply(int resultCode, uint32_t returnValue); 71 72 virtual bool isXNUTrap() const; 73 virtual bool isBSDTrap() const; 74 75 DSERVER_CLASS_DECLS; 76 }; 77 78 DSERVER_CLASS_DEFS; 79 }; 80 81 #endif // _DARLINGSERVER_CALL_HPP_