VirtualBox

Ignore:
Timestamp:
Apr 8, 2013 9:40:42 PM (12 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
84843
Message:

GuestCtrl: Implemented using (public) VirtualBox events instead of own callback mechanisms. Bugfixes for testcases (still work in progress).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/include/GuestCtrlImplPrivate.h

    r45109 r45415  
    132132    int Init(CALLBACKTYPE enmType);
    133133
    134     CALLBACKTYPE GetCallbackType(void) { return mType; }
     134    CALLBACKTYPE GetType(void) { return mType; }
    135135
    136136    const void* GetDataRaw(void) const { return pvData; }
     
    568568};
    569569
    570 /**
    571  * Pure virtual class (interface) for guest objects (processes, files, ...) --
     570class GuestBase
     571{
     572
     573public:
     574
     575    GuestBase(void);
     576    virtual ~GuestBase(void);
     577
     578public:
     579
     580    int generateContextID(uint32_t uSessionID, uint32_t uObjectID, uint32_t *puContextID);
     581
     582protected:
     583
     584    /** Pointer to the console object. Needed
     585     *  for HGCM (VMMDev) communication. */
     586    Console                 *mConsole;
     587    /** The next upcoming context ID for this object. */
     588    uint32_t                 mNextContextID;
     589};
     590
     591/**
     592 * Virtual class (interface) for guest objects (processes, files, ...) --
    572593 * contains all per-object callback management.
    573594 */
    574 class GuestObject
    575 {
    576 
    577 public:
    578 
    579     ULONG getObjectID(void) { return mObject.mObjectID; }
     595class GuestObject : public GuestBase
     596{
     597
     598public:
     599
     600    GuestObject(void);
     601    virtual ~GuestObject(void);
     602
     603public:
     604
     605    ULONG getObjectID(void) { return mObjectID; }
    580606
    581607protected:
     
    587613
    588614    int bindToSession(Console *pConsole, GuestSession *pSession, uint32_t uObjectID);
    589     int callbackAdd(GuestCtrlCallback *pCallback, uint32_t *puContextID);
    590     void callbackDelete(GuestCtrlCallback *pCallback);
    591     bool callbackExists(uint32_t uContextID);
    592     int callbackRemove(uint32_t uContextID);
    593     int callbackRemoveAll(void);
    594615    int sendCommand(uint32_t uFunction, uint32_t uParms, PVBOXHGCMSVCPARM paParms);
    595616
     
    597618
    598619    /**
    599      * Commom structure for all derived objects, when then have
     620     * Commom parameters for all derived objects, when then have
    600621     * an own mData structure to keep their specific data around.
    601622     */
    602     struct Object
    603     {
    604         /** Pointer to parent session. Per definition
    605          *  this objects *always* lives shorter than the
    606          *  parent. */
    607         GuestSession            *mSession;
    608         /** Pointer to the console object. Needed
    609          *  for HGCM (VMMDev) communication. */
    610         Console                 *mConsole;
    611         /** All related callbacks to this object. */
    612         GuestCtrlCallbacks       mCallbacks;
    613         /** The next upcoming context ID for this object. */
    614         ULONG                    mNextContextID;
    615         /** The object ID -- must be unique for each guest
    616          *  session and is encoded into the context ID. Must
    617          *  be set manually when initializing the object.
    618          *
    619          *  For guest processes this is the internal PID,
    620          *  for guest files this is the internal file ID. */
    621         uint32_t                 mObjectID;
    622     } mObject;
    623 };
    624 
    625 #if 0
    626 /*
    627  * Guest (HGCM) callbacks. All classes will throw
    628  * an exception on misuse.
    629  */
    630 
    631 /** Callback class for guest process status. */
    632 class GuestCbProcessStatus : public GuestCtrlCallback
    633 {
    634 
    635 public:
    636 
    637     int Init(uint32_t uProtocol, uint32_t uFunction,
    638              PVBOXGUESTCTRLHOSTCALLBACK pSvcCb)
    639     {
    640         AssertPtrReturn(pSvcCb, VERR_INVALID_POINTER);
    641 
    642         int rc = GuestCtrlCallback::Init();
    643         if (RT_FAILURE(rc))
    644             return rc;
    645 
    646         if (   uFunction != GUEST_EXEC_SEND_STATUS
    647             || pSvcCb->mParms < 5)
    648             return VERR_INVALID_PARAMETER;
    649 
    650         /* pSvcCb->mpaParms[0] always contains the context ID. */
    651         pSvcCb->mpaParms[1].getUInt32(&mPID);
    652         pSvcCb->mpaParms[2].getUInt32(&mStatus);
    653         pSvcCb->mpaParms[3].getUInt32(&mFlags); /* Can contain an IPRT error, which is a signed int. */
    654         pSvcCb->mpaParms[4].getPointer(&mData, &mcbData);
    655 
    656         return VINF_SUCCESS;
    657     }
    658 
    659     void Destroy(void) { }
    660 
    661     uint32_t  mPID;
    662     uint32_t  mStatus;
    663     uint32_t  mFlags;
    664     void     *mData;
    665     uint32_t  mcbData;
    666 };
    667 
    668 /** Callback class for guest process input. */
    669 class GuestCbProcessInput : public GuestCtrlCallback
    670 {
    671 
    672 public:
    673 
    674     int Init(uint32_t uProtocol, uint32_t uFunction,
    675              PVBOXGUESTCTRLHOSTCALLBACK pSvcCb)
    676     {
    677         AssertPtrReturn(pSvcCb, VERR_INVALID_POINTER);
    678 
    679         int rc = GuestCtrlCallback::Init();
    680         if (RT_FAILURE(rc))
    681             return rc;
    682 
    683         if (   uFunction != GUEST_EXEC_SEND_INPUT_STATUS
    684             || pSvcCb->mParms < 5)
    685             return VERR_INVALID_PARAMETER;
    686 
    687         /* pSvcCb->mpaParms[0] always contains the context ID. */
    688         pSvcCb->mpaParms[1].getUInt32(&mPID);
    689         /* Associated file handle. */
    690         pSvcCb->mpaParms[2].getUInt32(&mStatus);
    691         pSvcCb->mpaParms[3].getUInt32(&mFlags);
    692         pSvcCb->mpaParms[4].getUInt32(&mProcessed);
    693 
    694         return VINF_SUCCESS;
    695     }
    696 
    697     void Destroy(void) { }
    698 
    699     GuestCbProcessInput& operator=(const GuestCbProcessInput &that)
    700     {
    701         mPID = that.mPID;
    702         mStatus = that.mStatus;
    703         mFlags = that.mFlags;
    704         mProcessed = that.mProcessed;
    705         return *this;
    706     }
    707 
    708     uint32_t  mPID;
    709     uint32_t  mStatus;
    710     uint32_t  mFlags;
    711     uint32_t  mProcessed;
    712 };
    713 
    714 /** Callback class for guest process output. */
    715 class GuestCbProcessOutput : public GuestCtrlCallback
    716 {
    717 
    718 public:
    719 
    720     int Init(uint32_t uProtocol, uint32_t uFunction,
    721              PVBOXGUESTCTRLHOSTCALLBACK pSvcCb)
    722     {
    723         AssertPtrReturn(pSvcCb, VERR_INVALID_POINTER);
    724 
    725         int rc = GuestCtrlCallback::Init();
    726         if (RT_FAILURE(rc))
    727             return rc;
    728 
    729         if (   uFunction != GUEST_EXEC_SEND_OUTPUT
    730             || pSvcCb->mParms < 5)
    731             return VERR_INVALID_PARAMETER;
    732 
    733         /* pSvcCb->mpaParms[0] always contains the context ID. */
    734         pSvcCb->mpaParms[1].getUInt32(&mPID);
    735         /* Associated file handle. */
    736         pSvcCb->mpaParms[2].getUInt32(&mHandle);
    737         pSvcCb->mpaParms[3].getUInt32(&mFlags);
    738 
    739         void *pbData; uint32_t cbData;
    740         rc = pSvcCb->mpaParms[4].getPointer(&pbData, &cbData);
    741         if (RT_SUCCESS(rc))
    742         {
    743             Assert(cbData);
    744             mData = RTMemAlloc(cbData);
    745             AssertPtrReturn(mData, VERR_NO_MEMORY);
    746             memcpy(mData, pbData, cbData);
    747             mcbData = cbData;
    748         }
    749 
    750         return rc;
    751     }
    752 
    753     void Destroy(void)
    754     {
    755         if (mData)
    756         {
    757             RTMemFree(mData);
    758             mData = NULL;
    759             mcbData = 0;
    760         }
    761     }
    762 
    763     GuestCbProcessOutput& operator=(const GuestCbProcessOutput &that)
    764     {
    765         mPID = that.mPID;
    766         mHandle = that.mHandle;
    767         mFlags = that.mFlags;
    768 
    769         Destroy();
    770         if (that.mcbData)
    771         {
    772             void *pvData = RTMemAlloc(that.mcbData);
    773             if (pvData)
    774             {
    775                 AssertPtr(pvData);
    776                 memcpy(pvData, that.mData, that.mcbData);
    777                 mData = pvData;
    778                 mcbData = that.mcbData;
    779             }
    780         }
    781 
    782         return *this;
    783     }
    784 
    785     uint32_t  mPID;
    786     uint32_t  mHandle;
    787     uint32_t  mFlags;
    788     void     *mData;
    789     size_t    mcbData;
    790 };
    791 
    792 /** Callback class for guest process IO notifications. */
    793 class GuestCbProcessIO : public GuestCtrlCallback
    794 {
    795 
    796 public:
    797 
    798     int Init(uint32_t uProtocol, uint32_t uFunction,
    799              PVBOXGUESTCTRLHOSTCALLBACK pSvcCb)
    800     {
    801         AssertPtrReturn(pSvcCb, VERR_INVALID_POINTER);
    802 
    803         int rc = GuestCtrlCallback::Init();
    804         if (RT_FAILURE(rc))
    805             return rc;
    806 
    807         return VERR_NOT_IMPLEMENTED;
    808     }
    809 
    810     void Destroy(void) { GuestCtrlCallback::Destroy(); }
    811 
    812     GuestCbProcessIO& operator=(const GuestCbProcessIO &that)
    813     {
    814         return *this;
    815     }
    816 };
    817 #endif
     623
     624    /** Pointer to parent session. Per definition
     625     *  this objects *always* lives shorter than the
     626     *  parent. */
     627    GuestSession            *mSession;
     628    /** The object ID -- must be unique for each guest
     629     *  object and is encoded into the context ID. Must
     630     *  be set manually when initializing the object.
     631     *
     632     *  For guest processes this is the internal PID,
     633     *  for guest files this is the internal file ID. */
     634    uint32_t                 mObjectID;
     635};
    818636#endif // ____H_GUESTIMPLPRIVATE
    819637
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette