1 /* 2 * Copyright 2012 Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Paweł Dziepak, pdziepak@quarnos.org 7 */ 8 9 10 #include "RPCReply.h" 11 12 #include <util/kernel_cpp.h> 13 14 #include "RPCDefs.h" 15 16 17 using namespace RPC; 18 19 20 Reply::Reply(void* buffer, int size) 21 : 22 fError(B_OK), 23 fStream(buffer, size), 24 fBuffer(buffer) 25 { 26 fXID = fStream.GetUInt(); 27 if (fStream.GetInt() != REPLY) { 28 fError = B_BAD_VALUE; 29 return; 30 } 31 32 if (fStream.GetInt() == MSG_ACCEPTED) { 33 fStream.GetInt(); 34 fStream.GetOpaque(NULL); 35 36 switch (fStream.GetInt()) { 37 case SUCCESS: 38 return; 39 case PROG_UNAVAIL: 40 case PROG_MISMATCH: 41 case PROC_UNAVAIL: 42 fError = B_DEVICE_NOT_FOUND; 43 return; 44 case GARBAGE_ARGS: 45 fError = B_MISMATCHED_VALUES; 46 return; 47 case SYSTEM_ERR: 48 fError = B_ERROR; 49 return; 50 default: 51 fError = B_BAD_VALUE; 52 return; 53 } 54 } else { // MSG_DENIED 55 if (fStream.GetInt() == RPC_MISMATCH) { 56 fError = B_DEVICE_NOT_FOUND; 57 return; 58 } else { // AUTH_ERROR 59 fError = B_PERMISSION_DENIED; 60 return; 61 } 62 } 63 } 64 65 66 Reply::~Reply() 67 { 68 free(fBuffer); 69 } 70 71