Changeset 85318 in vbox for trunk/include
- Timestamp:
- Jul 13, 2020 9:07:41 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/HostServices/Service.h
r85121 r85318 30 30 #endif 31 31 32 #include <memory> /* for auto_ptr */33 34 32 #include <VBox/log.h> 35 33 #include <VBox/hgcmsvc.h> … … 39 37 #include <iprt/cpp/utils.h> 40 38 39 #include <new> 40 41 41 42 42 namespace HGCM … … 50 50 /** HGCM helper functions. */ 51 51 PVBOXHGCMSVCHELPERS pHelpers; 52 /* 52 /** 53 53 * Callback function supplied by the host for notification of updates 54 54 * to properties. … … 65 65 { 66 66 public: 67 68 67 Message(void); 69 70 68 Message(uint32_t uMsg, uint32_t cParms, VBOXHGCMSVCPARM aParms[]); 71 72 69 virtual ~Message(void); 73 70 74 uint32_t GetParamCount(void) const; 75 76 int GetData(uint32_t uMsg, uint32_t cParms, VBOXHGCMSVCPARM aParms[]) const; 77 78 int GetParmU32(uint32_t uParm, uint32_t *pu32Info) const; 79 80 int GetParmU64(uint32_t uParm, uint64_t *pu64Info) const; 81 82 int GetParmPtr(uint32_t uParm, void **ppvAddr, uint32_t *pcbSize) const; 83 84 uint32_t GetType(void) const; 85 86 public: 87 88 static int CopyParms(PVBOXHGCMSVCPARM paParmsDst, uint32_t cParmsDst, 89 PVBOXHGCMSVCPARM paParmsSrc, uint32_t cParmsSrc, 90 bool fDeepCopy); 91 92 protected: 93 94 int initData(uint32_t uMsg, uint32_t cParms, VBOXHGCMSVCPARM aParms[]); 95 96 void reset(); 71 uint32_t GetParamCount(void) const RT_NOEXCEPT; 72 int GetData(uint32_t uMsg, uint32_t cParms, VBOXHGCMSVCPARM aParms[]) const RT_NOEXCEPT; 73 int GetParmU32(uint32_t uParm, uint32_t *pu32Info) const RT_NOEXCEPT; 74 int GetParmU64(uint32_t uParm, uint64_t *pu64Info) const RT_NOEXCEPT; 75 int GetParmPtr(uint32_t uParm, void **ppvAddr, uint32_t *pcbSize) const RT_NOEXCEPT; 76 uint32_t GetType(void) const RT_NOEXCEPT; 77 78 public: 79 static int CopyParms(PVBOXHGCMSVCPARM paParmsDst, uint32_t cParmsDst, 80 PVBOXHGCMSVCPARM paParmsSrc, uint32_t cParmsSrc, 81 bool fDeepCopy) RT_NOEXCEPT; 82 83 protected: 84 int initData(uint32_t uMsg, uint32_t cParms, VBOXHGCMSVCPARM aParms[]) RT_NOEXCEPT; 85 void reset() RT_NOEXCEPT; 97 86 98 87 protected: … … 112 101 { 113 102 public: 114 115 Client(uint32_t uClientID); 116 103 Client(uint32_t idClient); 117 104 virtual ~Client(void); 118 105 119 106 public: 120 121 int Complete(VBOXHGCMCALLHANDLE hHandle, int rcOp = VINF_SUCCESS); 122 123 int CompleteDeferred(int rcOp = VINF_SUCCESS); 124 125 uint32_t GetClientID(void) const; 126 127 VBOXHGCMCALLHANDLE GetHandle(void) const; 128 129 uint32_t GetMsgType(void) const; 130 131 uint32_t GetMsgParamCount(void) const; 132 133 uint32_t GetProtocolVer(void) const; 134 135 bool IsDeferred(void) const; 136 137 void SetDeferred(VBOXHGCMCALLHANDLE hHandle, uint32_t u32Function, uint32_t cParms, VBOXHGCMSVCPARM paParms[]); 138 139 void SetProtocolVer(uint32_t uVersion); 140 141 void SetSvcContext(const VBOXHGCMSVCTX &SvcCtx); 142 143 public: 144 145 int SetDeferredMsgInfo(uint32_t uMsg, uint32_t cParms); 146 147 int SetDeferredMsgInfo(const Message *pMessage); 148 149 protected: 150 151 int completeInternal(VBOXHGCMCALLHANDLE hHandle, int rcOp); 152 153 void reset(void); 154 155 protected: 156 107 int Complete(VBOXHGCMCALLHANDLE hHandle, int rcOp = VINF_SUCCESS) RT_NOEXCEPT; 108 int CompleteDeferred(int rcOp = VINF_SUCCESS) RT_NOEXCEPT; 109 uint32_t GetClientID(void) const RT_NOEXCEPT; 110 VBOXHGCMCALLHANDLE GetHandle(void) const RT_NOEXCEPT; 111 uint32_t GetMsgType(void) const RT_NOEXCEPT; 112 uint32_t GetMsgParamCount(void) const RT_NOEXCEPT; 113 uint32_t GetProtocolVer(void) const RT_NOEXCEPT; 114 bool IsDeferred(void) const RT_NOEXCEPT; 115 void SetDeferred(VBOXHGCMCALLHANDLE hHandle, uint32_t u32Function, uint32_t cParms, VBOXHGCMSVCPARM paParms[]) RT_NOEXCEPT; 116 void SetProtocolVer(uint32_t uVersion) RT_NOEXCEPT; 117 void SetSvcContext(const VBOXHGCMSVCTX &SvcCtx) RT_NOEXCEPT; 118 119 public: 120 int SetDeferredMsgInfo(uint32_t uMsg, uint32_t cParms) RT_NOEXCEPT; 121 int SetDeferredMsgInfo(const Message *pMessage) RT_NOEXCEPT; 122 123 protected: 124 int completeInternal(VBOXHGCMCALLHANDLE hHandle, int rcOp) RT_NOEXCEPT; 125 void reset(void) RT_NOEXCEPT; 126 127 protected: 157 128 /** The client's HGCM client ID. */ 158 uint32_t m_uClientID; 159 /** Optional protocol version the client uses. Set to 0 by default. */ 129 uint32_t m_idClient; 130 /** Optional protocol version the client uses. Set to 0 by default. 131 * @todo r=bird: This does not belong here. Whether a service has a "protocol 132 * version" isn't given and I've argued that it's an inflexible bad idea. */ 160 133 uint32_t m_uProtocolVer; 161 134 /** The HGCM service context this client is bound to. */ … … 172 145 /** The client's HGCM call handle. Needed for completing a deferred call. */ 173 146 VBOXHGCMCALLHANDLE hHandle; 174 /** Message type (function number) to use when completing the deferred call. */ 147 /** Message type (function number) to use when completing the deferred call. 148 * @todo r=bird: uType or uMsg? Make up your mind (Message::m_uMsg). */ 175 149 uint32_t uType; 176 150 /** Parameter count to use when completing the deferred call. */ … … 204 178 else 205 179 { 206 RT_GCC_NO_WARN_DEPRECATED_BEGIN 207 std::auto_ptr<AbstractService> apService; 208 /* No exceptions may propagate outside. */ 209 try 210 { 211 apService = std::auto_ptr<AbstractService>(new T(pTable->pHelpers)); 212 } catch (int rcThrown) 213 { 214 rc = rcThrown; 215 } catch (...) 216 { 217 rc = VERR_UNRESOLVED_ERROR; 218 } 219 RT_GCC_NO_WARN_DEPRECATED_END 180 AbstractService *pService = NULL; 181 /* No exceptions may propagate outside (callbacks like this one are nothrow/noexcept). */ 182 try { pService = new T(pTable->pHelpers); } 183 catch (std::bad_alloc &) { rc = VERR_NO_MEMORY; } 184 catch (...) { rc = VERR_UNEXPECTED_EXCEPTION; } 220 185 if (RT_SUCCESS(rc)) 221 186 { 222 /* 223 * We don't need an additional client data area on the host, 224 * because we're a class which can have members for that :-). 225 */ 226 pTable->cbClient = 0; 187 /* We don't need an additional client data area on the host, 188 because we're a class which can have members for that :-). */ 189 pTable->cbClient = 0; 227 190 228 191 /* These functions are mandatory */ … … 238 201 239 202 /* Let the service itself initialize. */ 240 rc = apService->init(pTable); 241 242 /* Only on success stop the auto release of the auto_ptr. */ 203 rc = pService->init(pTable); 243 204 if (RT_SUCCESS(rc)) 244 pTable->pvService = apService.release(); 205 pTable->pvService = pService; 206 else 207 delete pService; 245 208 } 246 209 } … … 258 221 m_SvcCtx.pHelpers = pHelpers; 259 222 } 260 virtual int init(VBOXHGCMSVCFNTABLE *ptable) { RT_NOREF1(ptable); return VINF_SUCCESS; } 261 virtual int uninit() { return VINF_SUCCESS; } 262 virtual int clientConnect(uint32_t u32ClientID, void *pvClient) = 0; 263 virtual int clientDisconnect(uint32_t u32ClientID, void *pvClient) = 0; 264 virtual void guestCall(VBOXHGCMCALLHANDLE callHandle, uint32_t u32ClientID, void *pvClient, uint32_t eFunction, uint32_t cParms, VBOXHGCMSVCPARM paParms[]) = 0; 265 virtual int hostCall(uint32_t eFunction, uint32_t cParms, VBOXHGCMSVCPARM paParms[]) 223 virtual int init(VBOXHGCMSVCFNTABLE *ptable) RT_NOEXCEPT 224 { RT_NOREF1(ptable); return VINF_SUCCESS; } 225 virtual int uninit() RT_NOEXCEPT 226 { return VINF_SUCCESS; } 227 virtual int clientConnect(uint32_t idClient, void *pvClient) RT_NOEXCEPT = 0; 228 virtual int clientDisconnect(uint32_t idClient, void *pvClient) RT_NOEXCEPT = 0; 229 virtual void guestCall(VBOXHGCMCALLHANDLE callHandle, uint32_t idClient, void *pvClient, uint32_t eFunction, 230 uint32_t cParms, VBOXHGCMSVCPARM paParms[]) RT_NOEXCEPT = 0; 231 virtual int hostCall(uint32_t eFunction, uint32_t cParms, VBOXHGCMSVCPARM paParms[]) RT_NOEXCEPT 266 232 { RT_NOREF3(eFunction, cParms, paParms); return VINF_SUCCESS; } 267 233 … … 291 257 */ 292 258 static DECLCALLBACK(int) svcConnect(void *pvService, 293 uint32_t u32ClientID,259 uint32_t idClient, 294 260 void *pvClient, 295 261 uint32_t fRequestor, … … 298 264 RT_NOREF(fRequestor, fRestoring); 299 265 AssertLogRelReturn(VALID_PTR(pvService), VERR_INVALID_PARAMETER); 300 LogFlowFunc(("pvService=%p, u32ClientID=%u, pvClient=%p\n", pvService, u32ClientID, pvClient));301 SELF *pSelf = reinterpret_cast<SELF *>(pvService); 302 int rc = pSelf->clientConnect( u32ClientID, pvClient);266 LogFlowFunc(("pvService=%p, idClient=%u, pvClient=%p\n", pvService, idClient, pvClient)); 267 SELF *pSelf = reinterpret_cast<SELF *>(pvService); 268 int rc = pSelf->clientConnect(idClient, pvClient); 303 269 LogFlowFunc(("rc=%Rrc\n", rc)); 304 270 return rc; … … 310 276 */ 311 277 static DECLCALLBACK(int) svcDisconnect(void *pvService, 312 uint32_t u32ClientID,278 uint32_t idClient, 313 279 void *pvClient) 314 280 { 315 281 AssertLogRelReturn(VALID_PTR(pvService), VERR_INVALID_PARAMETER); 316 LogFlowFunc(("pvService=%p, u32ClientID=%u, pvClient=%p\n", pvService, u32ClientID, pvClient));317 SELF *pSelf = reinterpret_cast<SELF *>(pvService); 318 int rc = pSelf->clientDisconnect( u32ClientID, pvClient);282 LogFlowFunc(("pvService=%p, idClient=%u, pvClient=%p\n", pvService, idClient, pvClient)); 283 SELF *pSelf = reinterpret_cast<SELF *>(pvService); 284 int rc = pSelf->clientDisconnect(idClient, pvClient); 319 285 LogFlowFunc(("rc=%Rrc\n", rc)); 320 286 return rc; … … 325 291 * Wraps to the call member function 326 292 */ 327 static DECLCALLBACK(void) svcCall(void * 293 static DECLCALLBACK(void) svcCall(void *pvService, 328 294 VBOXHGCMCALLHANDLE callHandle, 329 uint32_t u32ClientID,295 uint32_t idClient, 330 296 void *pvClient, 331 297 uint32_t u32Function, … … 335 301 { 336 302 AssertLogRelReturnVoid(VALID_PTR(pvService)); 337 LogFlowFunc(("pvService=%p, callHandle=%p, u32ClientID=%u, pvClient=%p, u32Function=%u, cParms=%u, paParms=%p\n", pvService, callHandle, u32ClientID, pvClient, u32Function, cParms, paParms)); 338 SELF *pSelf = reinterpret_cast<SELF *>(pvService); 339 pSelf->guestCall(callHandle, u32ClientID, pvClient, u32Function, cParms, paParms); 303 LogFlowFunc(("pvService=%p, callHandle=%p, idClient=%u, pvClient=%p, u32Function=%u, cParms=%u, paParms=%p\n", 304 pvService, callHandle, idClient, pvClient, u32Function, cParms, paParms)); 305 SELF *pSelf = reinterpret_cast<SELF *>(pvService); 306 pSelf->guestCall(callHandle, idClient, pvClient, u32Function, cParms, paParms); 340 307 LogFlowFunc(("returning\n")); 341 308 RT_NOREF_PV(tsArrival);
Note:
See TracChangeset
for help on using the changeset viewer.