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 #ifndef REQUESTBUILDER_H 9 #define REQUESTBUILDER_H 10 11 12 #include <SupportDefs.h> 13 14 #include "FileInfo.h" 15 #include "NFS4Defs.h" 16 #include "ReplyInterpreter.h" 17 #include "RPCCall.h" 18 #include "RPCServer.h" 19 #include "XDR.h" 20 21 22 struct OpenState; 23 struct LockInfo; 24 struct LockOwner; 25 26 class RequestBuilder { 27 public: 28 RequestBuilder(Procedure p = ProcCompound); 29 ~RequestBuilder(); 30 31 inline void Reset(Procedure proc = ProcCompound); 32 33 status_t Access(); 34 status_t Close(uint32 seq, const uint32* id, 35 uint32 stateSeq); 36 status_t Commit(uint64 offset, uint32 count); 37 status_t Create(FileType type, const char* name, 38 AttrValue* attr, uint32 count, 39 const char* path = NULL); 40 status_t DelegReturn(const uint32* id, uint32 seq); 41 status_t GetAttr(Attribute* attrs, uint32 count); 42 status_t GetFH(); 43 status_t Link(const char* name); 44 status_t Lock(OpenState* state, LockInfo* lock, 45 uint32* sequence, bool reclaim = false); 46 status_t LockT(LockType type, uint64 pos, 47 uint64 len, OpenState* state); 48 status_t LockU(LockInfo* lock); 49 status_t LookUp(const char* name); 50 status_t LookUpUp(); 51 status_t Nverify(AttrValue* attr, uint32 count); 52 status_t Open(OpenClaim claim, uint32 seq, 53 uint32 access, uint64 id, OpenCreate oc, 54 uint64 ownerId, const char* name, 55 AttrValue* attr = NULL, 56 uint32 count = 0, bool excl = false, 57 OpenDelegation delegType 58 = OPEN_DELEGATE_NONE); 59 status_t OpenAttrDir(bool create); 60 status_t OpenConfirm(uint32 seq, const uint32* id, 61 uint32 stateSeq); 62 status_t PutFH(const FileHandle& fh); 63 status_t PutRootFH(); 64 status_t Read(const uint32* id, uint32 stateSeq, 65 uint64 pos, uint32 len); 66 status_t ReadDir(uint64 cookie, uint64 cookieVerf, 67 Attribute* attrs, uint32 attrCount); 68 status_t ReadLink(); 69 status_t Remove(const char* file); 70 status_t Rename(const char* from, const char* to); 71 status_t Renew(uint64 clientId); 72 status_t SaveFH(); 73 status_t SetAttr(const uint32* id, uint32 stateSeq, 74 AttrValue* attr, uint32 count); 75 status_t SetClientID(RPC::Server* server); 76 status_t SetClientIDConfirm(uint64 id, uint64 ver); 77 status_t Verify(AttrValue* attr, uint32 count); 78 status_t Write(const uint32* id, uint32 stateSeq, 79 const void* buffer, uint64 pos, 80 uint32 len, bool stable = false); 81 status_t ReleaseLockOwner(OpenState* state, 82 LockOwner* owner); 83 84 RPC::Call* Request(); 85 86 private: 87 void _InitHeader(); 88 89 void _GenerateLockOwner(XDR::WriteStream& stream, 90 OpenState* state, LockOwner* owner); 91 status_t _GenerateClientId(XDR::WriteStream& stream, 92 const RPC::Server* server); 93 94 void _EncodeAttrs(XDR::WriteStream& stream, 95 AttrValue* attr, uint32 count); 96 void _AttrBitmap(XDR::WriteStream& stream, 97 Attribute* attrs, uint32 count); 98 99 uint32 fOpCount; 100 XDR::Stream::Position fOpCountPosition; 101 102 Procedure fProcedure; 103 104 RPC::Call* fRequest; 105 }; 106 107 108 inline void 109 RequestBuilder::Reset(Procedure proc) 110 { 111 fRequest->Stream().Clear(); 112 fOpCount = 0; 113 fProcedure = proc; 114 delete fRequest; 115 116 _InitHeader(); 117 } 118 119 120 #endif // REQUESTBUILDER_H 121 122