- Timestamp:
- Feb 18, 2015 3:38:34 PM (10 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/doc/manual/en_US/SDKRef.xml
r52793 r54266 1217 1217 1218 1218 <para>Upon logon, the websession manager creates one instance 1219 of <xref linkend="IVirtualBox" xreflabel="IVirtualBox" /> and 1220 another object of <xref linkend="ISession" 1221 xreflabel="ISession" /> representing the web service session. 1222 This can be retrieved using <xref 1219 of <xref linkend="IVirtualBox" xreflabel="IVirtualBox" />, 1220 which can be used for directly performing calls to its 1221 methods, or used as a parameter for calling some methods of 1222 <xref linkend="IWebsessionManager" xreflabel="IWebsessionManager" />. 1223 Creating Main API session objects is performed using <xref 1223 1224 linkend="IWebsessionManager__getSessionObject" 1224 1225 xreflabel="IWebsessionManager::getSessionObject()" />.</para> … … 1226 1227 <para>(Technically, there is always only one <xref 1227 1228 linkend="IVirtualBox" xreflabel="IVirtualBox" /> object, which 1228 is shared between all sessions and clients, as it is a COM1229 is shared between all websessions and clients, as it is a COM 1229 1230 singleton. However, each session receives its own managed 1230 object reference to it. The <xref linkend="ISession" 1231 xreflabel="ISession" /> object, however, is created and 1232 destroyed for each session.)</para> 1231 object reference to it.)</para> 1233 1232 </listitem> 1234 1233 … … 1528 1527 name = "Linux" 1529 1528 mach = vbox.findMachine(name) 1530 session = mgr. mgr.getSessionObject(vbox)1529 session = mgr.getSessionObject(vbox) 1531 1530 progress = mach.launchVMProcess(session, "gui", "") 1532 1531 progress.waitForCompletion(-1) … … 1549 1548 available virtual machines in case of XPCOM), and a mechanism of 1550 1549 uniform session creation and closing 1551 (<computeroutput>mgr. mgr.getSessionObject()</computeroutput>).</para>1550 (<computeroutput>mgr.getSessionObject()</computeroutput>).</para> 1552 1551 1553 1552 <para>In case you want to use the glue layer with a different Python … … 2292 2291 xreflabel="ISession" /> interface. Each process which talks to 2293 2292 VirtualBox needs its own instance of ISession. In the web service, you 2294 cannot create such an object, but 2295 <computeroutput>vboxwebsrv</computeroutput> creates one for you when you 2296 log on, which you can obtain by calling <xref 2293 can request the creation of such an object by calling <xref 2297 2294 linkend="IWebsessionManager__getSessionObject" 2298 xreflabel="IWebsessionManager::getSessionObject()" />.</para> 2295 xreflabel="IWebsessionManager::getSessionObject()" />. More complex 2296 management tasks might need multiple instances of ISession, and each call 2297 returns a new one.</para> 2299 2298 2300 2299 <para>This session object must then be used like a mutex semaphore in … … 3908 3907 </itemizedlist></para> 3909 3908 </listitem> 3909 3910 <listitem> 3911 <para>The method <xref linkend="IWebsessionManager__getSessionObject" 3912 xreflabel="IWebsessionManager::getSessionObject()" /> now returns 3913 a new <xref linkend="ISession" xreflabel="ISession" /> instance for 3914 every invocation. This puts the behavior in line with other binding 3915 styles, which never forced the equivalent of establishing another 3916 connection and logging in again to get another instance.</para> 3917 </listitem> 3910 3918 </itemizedlist> 3911 3919 </sect1> -
trunk/src/VBox/Main/glue/tests/TestVBox.java
r46478 r54266 5 5 6 6 /* 7 * Copyright (C) 2010-201 3Oracle Corporation7 * Copyright (C) 2010-2015 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 15 15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. 16 16 */ 17 import org.virtualbox_4_ 3.*;17 import org.virtualbox_4_4.*; 18 18 import java.util.List; 19 19 import java.util.Arrays; -
trunk/src/VBox/Main/idl/VirtualBox.xidl
r53906 r54266 3 3 <!-- 4 4 5 Copyright (C) 2006-201 4Oracle Corporation5 Copyright (C) 2006-2015 Oracle Corporation 6 6 7 7 This file is part of VirtualBox Open Source Edition (OSE), as … … 18980 18980 <interface 18981 18981 name="IWebsessionManager" extends="$unknown" 18982 uuid=" dea1b4c7-2de3-418a-850d-7868617f7733"18982 uuid="930c8fea-453a-4a65-aca9-19ed9a872f88" 18983 18983 internal="yes" 18984 18984 wsmap="global" … … 19003 19003 <method name="getSessionObject"> 19004 19004 <desc> 19005 Returns a managed object reference to the internal ISession object that was created19006 for this web service session when the client logged on.19005 Returns a managed object reference to a new ISession object for every 19006 call to this method. 19007 19007 19008 19008 <see><link to="ISession"/></see> … … 19015 19015 <desc> 19016 19016 Logs off the client who has previously logged on with <link to="IWebsessionManager::logon" /> 19017 and destroys all resources associated with the session (most importantly, all 19018 managed objects created in the server while the session was active). 19017 and destroys all resources associated with the websession (most 19018 importantly, all managed objects created in the server while the 19019 websession was active). 19019 19020 </desc> 19020 19021 <param name="refIVirtualBox" type="IVirtualBox" dir="in"/> -
trunk/src/VBox/Main/webservice/vboxweb.cpp
r53186 r54266 6 6 * server, to which clients can connect. 7 7 * 8 * Copyright (C) 2007-201 4Oracle Corporation8 * Copyright (C) 2007-2015 Oracle Corporation 9 9 * 10 10 * This file is part of VirtualBox Open Source Edition (OSE), as … … 86 86 ****************************************************************************/ 87 87 88 typedef std::map<uint64_t, ManagedObjectRef*> 89 ManagedObjectsMapById; 90 typedef std::map<uint64_t, ManagedObjectRef*>::iterator 91 ManagedObjectsIteratorById; 92 typedef std::map<uintptr_t, ManagedObjectRef*> 93 ManagedObjectsMapByPtr; 94 95 typedef std::map<uint64_t, WebServiceSession*> 96 SessionsMap; 97 typedef std::map<uint64_t, WebServiceSession*>::iterator 98 SessionsMapIterator; 99 100 int fntWatchdog(RTTHREAD ThreadSelf, void *pvUser); 88 typedef std::map<uint64_t, ManagedObjectRef*> ManagedObjectsMapById; 89 typedef ManagedObjectsMapById::iterator ManagedObjectsIteratorById; 90 typedef std::map<uintptr_t, ManagedObjectRef*> ManagedObjectsMapByPtr; 91 typedef ManagedObjectsMapByPtr::iterator ManagedObjectsIteratorByPtr; 92 93 typedef std::map<uint64_t, WebServiceSession*> WebsessionsMap; 94 typedef WebsessionsMap::iterator WebsessionsMapIterator; 95 96 typedef std::map<RTTHREAD, com::Utf8Str> ThreadsMap; 97 98 static int fntWatchdog(RTTHREAD ThreadSelf, void *pvUser); 101 99 102 100 /**************************************************************************** … … 110 108 // generated strings in methodmaps.cpp 111 109 extern const char *g_pcszISession, 112 *g_pcszIVirtualBox; 110 *g_pcszIVirtualBox, 111 *g_pcszIVirtualBoxErrorInfo; 113 112 114 113 // globals for vboxweb command-line arguments 115 114 #define DEFAULT_TIMEOUT_SECS 300 116 115 #define DEFAULT_TIMEOUT_SECS_STRING "300" 117 intg_iWatchdogTimeoutSecs = DEFAULT_TIMEOUT_SECS;118 intg_iWatchdogCheckInterval = 5;119 120 const char*g_pcszBindToHost = NULL; // host; NULL = localhost121 unsigned intg_uBindToPort = 18083; // port122 unsigned intg_uBacklog = 100; // backlog = max queue size for requests116 static int g_iWatchdogTimeoutSecs = DEFAULT_TIMEOUT_SECS; 117 static int g_iWatchdogCheckInterval = 5; 118 119 static const char *g_pcszBindToHost = NULL; // host; NULL = localhost 120 static unsigned int g_uBindToPort = 18083; // port 121 static unsigned int g_uBacklog = 100; // backlog = max queue size for requests 123 122 124 123 #ifdef WITH_OPENSSL 125 boolg_fSSL = false; // if SSL is enabled126 const char*g_pcszKeyFile = NULL; // server key file127 const char*g_pcszPassword = NULL; // password for server key128 const char*g_pcszCACert = NULL; // file with trusted CA certificates129 const char*g_pcszCAPath = NULL; // directory with trusted CA certificates130 const char*g_pcszDHFile = NULL; // DH file name or DH key length in bits, NULL=use RSA131 const char*g_pcszRandFile = NULL; // file with random data seed132 const char*g_pcszSID = "vboxwebsrv"; // server ID for SSL session cache124 static bool g_fSSL = false; // if SSL is enabled 125 static const char *g_pcszKeyFile = NULL; // server key file 126 static const char *g_pcszPassword = NULL; // password for server key 127 static const char *g_pcszCACert = NULL; // file with trusted CA certificates 128 static const char *g_pcszCAPath = NULL; // directory with trusted CA certificates 129 static const char *g_pcszDHFile = NULL; // DH file name or DH key length in bits, NULL=use RSA 130 static const char *g_pcszRandFile = NULL; // file with random data seed 131 static const char *g_pcszSID = "vboxwebsrv"; // server ID for SSL session cache 133 132 #endif /* WITH_OPENSSL */ 134 133 135 unsigned intg_cMaxWorkerThreads = 100; // max. no. of worker threads136 unsigned intg_cMaxKeepAlive = 100; // maximum number of soap requests in one connection137 138 const char*g_pcszAuthentication = NULL; // web service authentication139 140 uint32_tg_cHistory = 10; // enable log rotation, 10 files141 uint32_tg_uHistoryFileTime = RT_SEC_1DAY; // max 1 day per file142 uint64_tg_uHistoryFileSize = 100 * _1M; // max 100MB per file134 static unsigned int g_cMaxWorkerThreads = 100; // max. no. of worker threads 135 static unsigned int g_cMaxKeepAlive = 100; // maximum number of soap requests in one connection 136 137 static const char *g_pcszAuthentication = NULL; // web service authentication 138 139 static uint32_t g_cHistory = 10; // enable log rotation, 10 files 140 static uint32_t g_uHistoryFileTime = RT_SEC_1DAY; // max 1 day per file 141 static uint64_t g_uHistoryFileSize = 100 * _1M; // max 100MB per file 143 142 bool g_fVerbose = false; // be verbose 144 143 145 boolg_fDaemonize = false; // run in background.144 static bool g_fDaemonize = false; // run in background. 146 145 147 146 const WSDLT_ID g_EmptyWSDLID; // for NULL MORs … … 155 154 // The one global SOAP queue created by main(). 156 155 class SoapQ; 157 SoapQ*g_pSoapQ = NULL;156 static SoapQ *g_pSoapQ = NULL; 158 157 159 158 // this mutex protects the auth lib and authentication 160 util::WriteLockHandle*g_pAuthLibLockHandle;159 static util::WriteLockHandle *g_pAuthLibLockHandle; 161 160 162 161 // this mutex protects the global VirtualBox reference below 163 static util::RWLockHandle *g_pVirtualBoxLockHandle;164 165 static ComPtr<IVirtualBox> g_pVirtualBox = NULL;162 static util::RWLockHandle *g_pVirtualBoxLockHandle; 163 164 static ComPtr<IVirtualBox> g_pVirtualBox = NULL; 166 165 167 166 // this mutex protects all of the below 168 util::WriteLockHandle *g_pSessionsLockHandle; 169 170 SessionsMap g_mapSessions; 171 ULONG64 g_iMaxManagedObjectID = 0; 172 ULONG64 g_cManagedObjects = 0; 167 util::WriteLockHandle *g_pWebsessionsLockHandle; 168 169 static WebsessionsMap g_mapWebsessions; 170 static ULONG64 g_cManagedObjects = 0; 173 171 174 172 // this mutex protects g_mapThreads 175 util::RWLockHandle *g_pThreadsLockHandle; 176 177 // this mutex synchronizes logging 178 util::WriteLockHandle *g_pWebLogLockHandle; 173 static util::RWLockHandle *g_pThreadsLockHandle; 179 174 180 175 // Threads map, so we can quickly map an RTTHREAD struct to a logger prefix 181 typedef std::map<RTTHREAD, com::Utf8Str> ThreadsMap; 182 ThreadsMap g_mapThreads; 176 static ThreadsMap g_mapThreads; 183 177 184 178 /**************************************************************************** … … 218 212 }; 219 213 220 void DisplayHelp()214 static void DisplayHelp() 221 215 { 222 216 RTStrmPrintf(g_pStdErr, "\nUsage: vboxwebsrv [options]\n\nSupported options (default values in brackets):\n"); … … 640 634 } 641 635 { 642 // we're messing with sessions, so lock them643 util::AutoWriteLock lock(g_p SessionsLockHandle COMMA_LOCKVAL_SRC_POS);644 WEBDEBUG(("SVC unavailable: deleting %d sessions\n", g_mapSessions.size()));645 646 SessionsMap::iterator it = g_mapSessions.begin(),647 itEnd = g_mapSessions.end();636 // we're messing with websessions, so lock them 637 util::AutoWriteLock lock(g_pWebsessionsLockHandle COMMA_LOCKVAL_SRC_POS); 638 WEBDEBUG(("SVC unavailable: deleting %d websessions\n", g_mapWebsessions.size())); 639 640 WebsessionsMapIterator it = g_mapWebsessions.begin(), 641 itEnd = g_mapWebsessions.end(); 648 642 while (it != itEnd) 649 643 { 650 WebServiceSession *p Session = it->second;651 WEBDEBUG(("SVC unavailable: Session %llX stale, deleting\n", pSession->getID()));652 delete p Session;653 it = g_map Sessions.begin();644 WebServiceSession *pWebsession = it->second; 645 WEBDEBUG(("SVC unavailable: websession %#llx stale, deleting\n", pWebsession->getID())); 646 delete pWebsession; 647 it = g_mapWebsessions.begin(); 654 648 } 655 649 } … … 829 823 ****************************************************************************/ 830 824 831 void doQueuesLoop()825 static void doQueuesLoop() 832 826 { 833 827 #ifdef WITH_OPENSSL … … 909 903 * SOAP queue worker threads. 910 904 */ 911 int fntQPumper(RTTHREAD ThreadSelf, void *pvUser)905 static int fntQPumper(RTTHREAD ThreadSelf, void *pvUser) 912 906 { 913 907 // store a log prefix for this thread … … 1202 1196 g_pAuthLibLockHandle = new util::WriteLockHandle(util::LOCKCLASS_WEBSERVICE); 1203 1197 g_pVirtualBoxLockHandle = new util::RWLockHandle(util::LOCKCLASS_WEBSERVICE); 1204 g_p SessionsLockHandle = new util::WriteLockHandle(util::LOCKCLASS_WEBSERVICE);1198 g_pWebsessionsLockHandle = new util::WriteLockHandle(util::LOCKCLASS_WEBSERVICE); 1205 1199 g_pThreadsLockHandle = new util::RWLockHandle(util::LOCKCLASS_OBJECTSTATE); 1206 g_pWebLogLockHandle = new util::WriteLockHandle(util::LOCKCLASS_WEBSERVICE);1207 1200 1208 1201 // SOAP queue pumper thread … … 1266 1259 * Watchdog thread, runs in the background while the webservice is alive. 1267 1260 * 1268 * This gets started by main() and runs in the background to check all sessions1261 * This gets started by main() and runs in the background to check all websessions 1269 1262 * for whether they have been no requests in a configurable timeout period. In 1270 * that case, the session is automatically logged off. 1271 */ 1263 * that case, the websession is automatically logged off. 1264 */ 1265 /* static */ 1272 1266 int fntWatchdog(RTTHREAD ThreadSelf, void *pvUser) 1273 1267 { … … 1287 1281 time(&tNow); 1288 1282 1289 // we're messing with sessions, so lock them1290 util::AutoWriteLock lock(g_p SessionsLockHandle COMMA_LOCKVAL_SRC_POS);1291 WEBDEBUG(("Watchdog: checking %d sessions\n", g_mapSessions.size()));1292 1293 SessionsMap::iterator it = g_mapSessions.begin(),1294 itEnd = g_mapSessions.end();1283 // we're messing with websessions, so lock them 1284 util::AutoWriteLock lock(g_pWebsessionsLockHandle COMMA_LOCKVAL_SRC_POS); 1285 WEBDEBUG(("Watchdog: checking %d websessions\n", g_mapWebsessions.size())); 1286 1287 WebsessionsMapIterator it = g_mapWebsessions.begin(), 1288 itEnd = g_mapWebsessions.end(); 1295 1289 while (it != itEnd) 1296 1290 { 1297 WebServiceSession *pSession = it->second; 1298 WEBDEBUG(("Watchdog: tNow: %d, session timestamp: %d\n", tNow, pSession->getLastObjectLookup())); 1299 if ( tNow 1300 > pSession->getLastObjectLookup() + g_iWatchdogTimeoutSecs 1301 ) 1291 WebServiceSession *pWebsession = it->second; 1292 WEBDEBUG(("Watchdog: tNow: %d, websession timestamp: %d\n", tNow, pWebsession->getLastObjectLookup())); 1293 if (tNow > pWebsession->getLastObjectLookup() + g_iWatchdogTimeoutSecs) 1302 1294 { 1303 WEBDEBUG(("Watchdog: Session %llX timed out, deleting\n", pSession->getID()));1304 delete p Session;1305 it = g_map Sessions.begin();1295 WEBDEBUG(("Watchdog: websession %#llx timed out, deleting\n", pWebsession->getID())); 1296 delete pWebsession; 1297 it = g_mapWebsessions.begin(); 1306 1298 } 1307 1299 else … … 1338 1330 * @param ex 1339 1331 */ 1340 void RaiseSoapFault(struct soap *soap,1341 const char *pcsz,1342 int extype,1343 void *ex)1332 static void RaiseSoapFault(struct soap *soap, 1333 const char *pcsz, 1334 int extype, 1335 void *ex) 1344 1336 { 1345 1337 // raise the fault … … 1515 1507 info.getVirtualBoxErrorInfo(pVirtualBoxErrorInfo); 1516 1508 ex->resultCode = apirc; 1517 ex->returnval = createOrFindRefFromComPtr(idThis, "IVirtualBoxErrorInfo", pVirtualBoxErrorInfo);1509 ex->returnval = createOrFindRefFromComPtr(idThis, g_pcszIVirtualBoxErrorInfo, pVirtualBoxErrorInfo); 1518 1510 1519 1511 RaiseSoapFault(soap, … … 1529 1521 ****************************************************************************/ 1530 1522 1531 uint64_t str2ulonglong(const char *pcsz) 1532 { 1533 uint64_t u = 0; 1534 RTStrToUInt64Full(pcsz, 16, &u); 1535 return u; 1536 } 1537 1538 /** 1539 * Splits a managed object reference (in string form, as 1540 * passed in from a SOAP method call) into two integers for 1541 * session and object IDs, respectively. 1523 /** 1524 * Splits a managed object reference (in string form, as passed in from a SOAP 1525 * method call) into two integers for websession and object IDs, respectively. 1542 1526 * 1543 1527 * @param id 1544 * @param sessid1545 * @param objid1528 * @param pWebsessId 1529 * @param pObjId 1546 1530 * @return 1547 1531 */ 1548 bool SplitManagedObjectRef(const WSDLT_ID &id,1549 uint64_t *pSessid,1550 uint64_t *pObjid)1532 static bool SplitManagedObjectRef(const WSDLT_ID &id, 1533 uint64_t *pWebsessId, 1534 uint64_t *pObjId) 1551 1535 { 1552 1536 // 64-bit numbers in hex have 16 digits; hence … … 1560 1544 memcpy(psz, id.c_str(), 34); 1561 1545 psz[16] = '\0'; 1562 if (p Sessid)1563 *pSessid = str2ulonglong(psz);1564 if (pObj id)1565 *pObjid = str2ulonglong(psz + 17);1546 if (pWebsessId) 1547 RTStrToUInt64Full(psz, 16, pWebsessId); 1548 if (pObjId) 1549 RTStrToUInt64Full(psz + 17, 16, pObjId); 1566 1550 return true; 1567 1551 } … … 1572 1556 /** 1573 1557 * Creates a managed object reference (in string form) from 1574 * two integers representing a session and object ID, respectively.1558 * two integers representing a websession and object ID, respectively. 1575 1559 * 1576 1560 * @param sz Buffer with at least 34 bytes space to receive MOR string. 1577 * @param sessid1578 * @param obj id1561 * @param websessId 1562 * @param objId 1579 1563 * @return 1580 1564 */ 1581 void MakeManagedObjectRef(char *sz,1582 uint64_t &sessid,1583 uint64_t &objid)1584 { 1585 RTStrFormatNumber(sz, sessid, 16, 16, 0, RTSTR_F_64BIT | RTSTR_F_ZEROPAD);1565 static void MakeManagedObjectRef(char *sz, 1566 uint64_t websessId, 1567 uint64_t objId) 1568 { 1569 RTStrFormatNumber(sz, websessId, 16, 16, 0, RTSTR_F_64BIT | RTSTR_F_ZEROPAD); 1586 1570 sz[16] = '-'; 1587 RTStrFormatNumber(sz + 17, obj id, 16, 16, 0, RTSTR_F_64BIT | RTSTR_F_ZEROPAD);1571 RTStrFormatNumber(sz + 17, objId, 16, 16, 0, RTSTR_F_64BIT | RTSTR_F_ZEROPAD); 1588 1572 } 1589 1573 … … 1602 1586 1603 1587 /** 1604 * Constructor for the session object.1605 * 1606 * Preconditions: Caller must have locked g_p SessionsLockHandle.1588 * Constructor for the websession object. 1589 * 1590 * Preconditions: Caller must have locked g_pWebsessionsLockHandle. 1607 1591 * 1608 1592 * @param username … … 1610 1594 */ 1611 1595 WebServiceSession::WebServiceSession() 1612 : _ fDestructing(false),1613 _ pISession(NULL),1596 : _uNextObjectID(1), // avoid 0 for no real reason 1597 _fDestructing(false), 1614 1598 _tLastObjectLookup(0) 1615 1599 { 1616 1600 _pp = new WebServiceSessionPrivate; 1617 _u SessionID = RTRandU64();1618 1619 // register this session globally1620 Assert(g_p SessionsLockHandle->isWriteLockOnCurrentThread());1621 g_map Sessions[_uSessionID] = this;1601 _uWebsessionID = RTRandU64(); 1602 1603 // register this websession globally 1604 Assert(g_pWebsessionsLockHandle->isWriteLockOnCurrentThread()); 1605 g_mapWebsessions[_uWebsessionID] = this; 1622 1606 } 1623 1607 … … 1625 1609 * Destructor. Cleans up and destroys all contained managed object references on the way. 1626 1610 * 1627 * Preconditions: Caller must have locked g_p SessionsLockHandle.1611 * Preconditions: Caller must have locked g_pWebsessionsLockHandle. 1628 1612 */ 1629 1613 WebServiceSession::~WebServiceSession() … … 1631 1615 // delete us from global map first so we can't be found 1632 1616 // any more while we're cleaning up 1633 Assert(g_p SessionsLockHandle->isWriteLockOnCurrentThread());1634 g_map Sessions.erase(_uSessionID);1617 Assert(g_pWebsessionsLockHandle->isWriteLockOnCurrentThread()); 1618 g_mapWebsessions.erase(_uWebsessionID); 1635 1619 1636 1620 // notify ManagedObjectRef destructor so it won't … … 1639 1623 _fDestructing = true; 1640 1624 1641 // if (_pISession) 1642 // { 1643 // delete _pISession; 1644 // _pISession = NULL; 1645 // } 1646 1647 ManagedObjectsMapById::iterator it, 1648 end = _pp->_mapManagedObjectsById.end(); 1625 ManagedObjectsIteratorById it, 1626 end = _pp->_mapManagedObjectsById.end(); 1649 1627 for (it = _pp->_mapManagedObjectsById.begin(); 1650 1628 it != end; … … 1771 1749 lock.release(); 1772 1750 1773 if (!rc)1774 {1775 do1776 {1777 // now create the ISession object that this webservice session can use1778 // (and of which IWebsessionManager::getSessionObject returns a managed object reference)1779 ComPtr<ISession> session;1780 rc = g_pVirtualBoxClient->COMGETTER(Session)(session.asOutParam());1781 if (FAILED(rc))1782 {1783 WEBDEBUG(("ERROR: cannot create session object!"));1784 break;1785 }1786 1787 ComPtr<IUnknown> p2 = session;1788 _pISession = new ManagedObjectRef(*this,1789 p2, // IUnknown *pobjUnknown1790 session, // void *pobjInterface1791 com::Guid(COM_IIDOF(ISession)),1792 g_pcszISession);1793 1794 if (g_fVerbose)1795 {1796 ISession *p = session;1797 WEBDEBUG((" * %s: created session object with comptr %#p, MOR = %s\n", __FUNCTION__, p, _pISession->getWSDLID().c_str()));1798 }1799 } while (0);1800 }1801 1802 1751 return rc; 1803 1752 } 1804 1753 1805 1754 /** 1806 * Look up, in this session, whether a ManagedObjectRef has already been1755 * Look up, in this websession, whether a ManagedObjectRef has already been 1807 1756 * created for the given COM pointer. 1808 1757 * … … 1813 1762 * our private hash table, we must search for one too. 1814 1763 * 1815 * Preconditions: Caller must have locked g_p SessionsLockHandle.1764 * Preconditions: Caller must have locked g_pWebsessionsLockHandle. 1816 1765 * 1817 1766 * @param pcu pointer to a COM object. … … 1820 1769 ManagedObjectRef* WebServiceSession::findRefFromPtr(const IUnknown *pObject) 1821 1770 { 1822 Assert(g_p SessionsLockHandle->isWriteLockOnCurrentThread());1771 Assert(g_pWebsessionsLockHandle->isWriteLockOnCurrentThread()); 1823 1772 1824 1773 uintptr_t ulp = (uintptr_t)pObject; 1825 1774 // WEBDEBUG((" %s: looking up %#lx\n", __FUNCTION__, ulp)); 1826 ManagedObjects MapByPtr::iterator it = _pp->_mapManagedObjectsByPtr.find(ulp);1775 ManagedObjectsIteratorByPtr it = _pp->_mapManagedObjectsByPtr.find(ulp); 1827 1776 if (it != _pp->_mapManagedObjectsByPtr.end()) 1828 1777 { … … 1836 1785 1837 1786 /** 1838 * Static method which attempts to find the session for which the given managed1839 * object reference was created, by splitting the reference into the session and1840 * object IDs and then looking up the session object for that session ID.1841 * 1842 * Preconditions: Caller must have locked g_p SessionsLockHandle in read mode.1843 * 1844 * @param id Managed object reference (with combined session and object IDs).1787 * Static method which attempts to find the websession for which the given 1788 * managed object reference was created, by splitting the reference into the 1789 * websession and object IDs and then looking up the websession object. 1790 * 1791 * Preconditions: Caller must have locked g_pWebsessionsLockHandle in read mode. 1792 * 1793 * @param id Managed object reference (with combined websession and object IDs). 1845 1794 * @return 1846 1795 */ 1847 WebServiceSession * WebServiceSession::findSessionFromRef(const WSDLT_ID &id)1848 { 1849 Assert(g_p SessionsLockHandle->isWriteLockOnCurrentThread());1850 1851 WebServiceSession *p Session = NULL;1852 uint64_t sessid;1796 WebServiceSession *WebServiceSession::findWebsessionFromRef(const WSDLT_ID &id) 1797 { 1798 Assert(g_pWebsessionsLockHandle->isWriteLockOnCurrentThread()); 1799 1800 WebServiceSession *pWebsession = NULL; 1801 uint64_t websessId; 1853 1802 if (SplitManagedObjectRef(id, 1854 & sessid,1803 &websessId, 1855 1804 NULL)) 1856 1805 { 1857 SessionsMapIterator it = g_mapSessions.find(sessid); 1858 if (it != g_mapSessions.end()) 1859 pSession = it->second; 1860 } 1861 return pSession; 1862 } 1863 1864 /** 1865 * 1866 */ 1867 const WSDLT_ID& WebServiceSession::getSessionWSDLID() const 1868 { 1869 return _pISession->getWSDLID(); 1870 } 1871 1872 /** 1873 * Touches the webservice session to prevent it from timing out. 1874 * 1875 * Each webservice session has an internal timestamp that records 1876 * the last request made to it from the client that started it. 1877 * If no request was made within a configurable timeframe, then 1878 * the client is logged off automatically, 1806 WebsessionsMapIterator it = g_mapWebsessions.find(websessId); 1807 if (it != g_mapWebsessions.end()) 1808 pWebsession = it->second; 1809 } 1810 return pWebsession; 1811 } 1812 1813 /** 1814 * Touches the websession to prevent it from timing out. 1815 * 1816 * Each websession has an internal timestamp that records the last request made 1817 * to it from the client that started it. If no request was made within a 1818 * configurable timeframe, then the client is logged off automatically, 1879 1819 * by calling IWebsessionManager::logoff() 1880 1820 */ … … 1893 1833 /** 1894 1834 * Constructor, which assigns a unique ID to this managed object 1895 * reference and stores it two global hashes: 1896 * 1897 * a) G_mapManagedObjectsById, which maps ManagedObjectID's to 1835 * reference and stores it in two hashes (living in the associated 1836 * WebServiceSession object): 1837 * 1838 * a) _mapManagedObjectsById, which maps ManagedObjectID's to 1898 1839 * instances of this class; this hash is then used by the 1899 1840 * findObjectFromRef() template function in vboxweb.h … … 1903 1844 * a managed object ID); 1904 1845 * 1905 * b) G_mapManagedObjectsByComPtr, which maps COM pointers to1846 * b) _mapManagedObjectsByPtr, which maps COM pointers to 1906 1847 * instances of this class; this hash is used by 1907 1848 * createRefFromObject() to quickly figure out whether an … … 1922 1863 * does perform that check. 1923 1864 * 1924 * Preconditions: Caller must have locked g_p SessionsLockHandle.1925 * 1926 * @param session Session to which the MOR will be added.1865 * Preconditions: Caller must have locked g_pWebsessionsLockHandle. 1866 * 1867 * @param websession Websession to which the MOR will be added. 1927 1868 * @param pobjUnknown Pointer to IUnknown* interface for the COM object; this will be used in the hashes. 1928 1869 * @param pobjInterface Pointer to a specific interface for the COM object, described by guidInterface. … … 1930 1871 * @param pcszInterface String representation of that interface (e.g. "IMachine") for readability and logging. 1931 1872 */ 1932 ManagedObjectRef::ManagedObjectRef(WebServiceSession & session,1873 ManagedObjectRef::ManagedObjectRef(WebServiceSession &websession, 1933 1874 IUnknown *pobjUnknown, 1934 1875 void *pobjInterface, 1935 1876 const com::Guid &guidInterface, 1936 1877 const char *pcszInterface) 1937 : _ session(session),1878 : _websession(websession), 1938 1879 _pobjUnknown(pobjUnknown), 1939 1880 _pobjInterface(pobjInterface), … … 1949 1890 _ulp = (uintptr_t)pobjUnknown; 1950 1891 1951 Assert(g_p SessionsLockHandle->isWriteLockOnCurrentThread());1952 _id = ++g_iMaxManagedObjectID;1892 Assert(g_pWebsessionsLockHandle->isWriteLockOnCurrentThread()); 1893 _id = websession.createObjectID(); 1953 1894 // and count globally 1954 1895 ULONG64 cTotal = ++g_cManagedObjects; // raise global count and make a copy for the debug message below 1955 1896 1956 1897 char sz[34]; 1957 MakeManagedObjectRef(sz, session._uSessionID, _id);1898 MakeManagedObjectRef(sz, websession._uWebsessionID, _id); 1958 1899 _strID = sz; 1959 1900 1960 session._pp->_mapManagedObjectsById[_id] = this;1961 session._pp->_mapManagedObjectsByPtr[_ulp] = this;1962 1963 session.touch();1964 1965 WEBDEBUG((" * %s: MOR created for %s*=%#p (IUnknown*=%#p; COM refcount now %RI32/%RI32), new ID is % llX; now %lld objects total\n",1901 websession._pp->_mapManagedObjectsById[_id] = this; 1902 websession._pp->_mapManagedObjectsByPtr[_ulp] = this; 1903 1904 websession.touch(); 1905 1906 WEBDEBUG((" * %s: MOR created for %s*=%#p (IUnknown*=%#p; COM refcount now %RI32/%RI32), new ID is %#llx; now %lld objects total\n", 1966 1907 __FUNCTION__, 1967 1908 pcszInterface, … … 1978 1919 * managed objects. Calls Release() on the contained COM object. 1979 1920 * 1980 * Preconditions: Caller must have locked g_p SessionsLockHandle.1921 * Preconditions: Caller must have locked g_pWebsessionsLockHandle. 1981 1922 */ 1982 1923 ManagedObjectRef::~ManagedObjectRef() 1983 1924 { 1984 Assert(g_p SessionsLockHandle->isWriteLockOnCurrentThread());1925 Assert(g_pWebsessionsLockHandle->isWriteLockOnCurrentThread()); 1985 1926 ULONG64 cTotal = --g_cManagedObjects; 1986 1927 … … 1992 1933 uint32_t cRefs2 = ((IUnknown*)_pobjInterface)->Release(); 1993 1934 uint32_t cRefs1 = _pobjUnknown->Release(); 1994 WEBDEBUG((" * %s: deleting MOR for ID % llX(%s; COM refcount now %RI32/%RI32); now %lld objects total\n", __FUNCTION__, _id, _pcszInterface, cRefs1, cRefs2, cTotal));1995 1996 // if we're being destroyed from the session's destructor,1935 WEBDEBUG((" * %s: deleting MOR for ID %#llx (%s; COM refcount now %RI32/%RI32); now %lld objects total\n", __FUNCTION__, _id, _pcszInterface, cRefs1, cRefs2, cTotal)); 1936 1937 // if we're being destroyed from the websession's destructor, 1997 1938 // then that destructor is iterating over the maps, so 1998 1939 // don't remove us there! (data integrity + speed) 1999 if (!_ session._fDestructing)2000 { 2001 WEBDEBUG((" * %s: removing from session maps\n", __FUNCTION__));2002 _ session._pp->_mapManagedObjectsById.erase(_id);2003 if (_ session._pp->_mapManagedObjectsByPtr.erase(_ulp) != 1)2004 WEBDEBUG((" WARNING: could not find % llXin _mapManagedObjectsByPtr\n", _ulp));1940 if (!_websession._fDestructing) 1941 { 1942 WEBDEBUG((" * %s: removing from websession maps\n", __FUNCTION__)); 1943 _websession._pp->_mapManagedObjectsById.erase(_id); 1944 if (_websession._pp->_mapManagedObjectsByPtr.erase(_ulp) != 1) 1945 WEBDEBUG((" WARNING: could not find %#llx in _mapManagedObjectsByPtr\n", _ulp)); 2005 1946 } 2006 1947 } … … 2013 1954 * code bloat as we have the actual STL map lookup only in this function. 2014 1955 * 2015 * This also "touches" the timestamp in the session whose ID is encoded2016 * in the given integer ID, in order to prevent the session from timing1956 * This also "touches" the timestamp in the websession whose ID is encoded 1957 * in the given integer ID, in order to prevent the websession from timing 2017 1958 * out. 2018 1959 * 2019 * Preconditions: Caller must have locked g_ mutexSessions.1960 * Preconditions: Caller must have locked g_pWebsessionsLockHandle. 2020 1961 * 2021 1962 * @param strId … … 2038 1979 } 2039 1980 2040 uint64_t sessid;2041 uint64_t obj id;1981 uint64_t websessId; 1982 uint64_t objId; 2042 1983 WEBDEBUG((" %s(): looking up objref %s\n", __FUNCTION__, id.c_str())); 2043 1984 if (!SplitManagedObjectRef(id, 2044 & sessid,2045 &obj id))1985 &websessId, 1986 &objId)) 2046 1987 { 2047 1988 rc = VERR_WEB_INVALID_MANAGED_OBJECT_REFERENCE; … … 2049 1990 } 2050 1991 2051 SessionsMapIterator it = g_mapSessions.find(sessid);2052 if (it == g_map Sessions.end())1992 WebsessionsMapIterator it = g_mapWebsessions.find(websessId); 1993 if (it == g_mapWebsessions.end()) 2053 1994 { 2054 WEBDEBUG((" %s: cannot find session for objref %s\n", __FUNCTION__, id.c_str()));1995 WEBDEBUG((" %s: cannot find websession for objref %s\n", __FUNCTION__, id.c_str())); 2055 1996 rc = VERR_WEB_INVALID_SESSION_ID; 2056 1997 break; 2057 1998 } 2058 1999 2059 WebServiceSession *p Sess= it->second;2060 // "touch" session to prevent it from timing out2061 p Sess->touch();2062 2063 ManagedObjectsIteratorById iter = p Sess->_pp->_mapManagedObjectsById.find(objid);2064 if (iter == p Sess->_pp->_mapManagedObjectsById.end())2000 WebServiceSession *pWebsession = it->second; 2001 // "touch" websession to prevent it from timing out 2002 pWebsession->touch(); 2003 2004 ManagedObjectsIteratorById iter = pWebsession->_pp->_mapManagedObjectsById.find(objId); 2005 if (iter == pWebsession->_pp->_mapManagedObjectsById.end()) 2065 2006 { 2066 2007 WEBDEBUG((" %s: cannot find comobj for objref %s\n", __FUNCTION__, id.c_str())); … … 2104 2045 { 2105 2046 // findRefFromId require the lock 2106 util::AutoWriteLock lock(g_p SessionsLockHandle COMMA_LOCKVAL_SRC_POS);2047 util::AutoWriteLock lock(g_pWebsessionsLockHandle COMMA_LOCKVAL_SRC_POS); 2107 2048 2108 2049 ManagedObjectRef *pRef; … … 2139 2080 { 2140 2081 // findRefFromId and the delete call below require the lock 2141 util::AutoWriteLock lock(g_p SessionsLockHandle COMMA_LOCKVAL_SRC_POS);2082 util::AutoWriteLock lock(g_pWebsessionsLockHandle COMMA_LOCKVAL_SRC_POS); 2142 2083 2143 2084 ManagedObjectRef *pRef; … … 2174 2115 * 2175 2116 * This returns a managed object reference to the global IVirtualBox object; into this 2176 * reference a session ID is encoded which remains constant with all managed object2117 * reference a websession ID is encoded which remains constant with all managed object 2177 2118 * references returned by other methods. 2178 *2179 * This also creates an instance of ISession, which is stored internally with the2180 * webservice session and can be retrieved with IWebsessionManager::getSessionObject2181 * (__vbox__IWebsessionManager_USCOREgetSessionObject). In order for the2182 * VirtualBox web service to do anything useful, one usually needs both a2183 * VirtualBox and an ISession object, for which these two methods are designed.2184 2119 * 2185 2120 * When the webservice client is done, it should call IWebsessionManager::logoff. This … … 2210 2145 { 2211 2146 // WebServiceSession constructor tinkers with global MOR map and requires a write lock 2212 util::AutoWriteLock lock(g_p SessionsLockHandle COMMA_LOCKVAL_SRC_POS);2213 2214 // create new session; the constructor stores the newsession2147 util::AutoWriteLock lock(g_pWebsessionsLockHandle COMMA_LOCKVAL_SRC_POS); 2148 2149 // create new websession; the constructor stores the new websession 2215 2150 // in the global map automatically 2216 WebServiceSession *p Session = new WebServiceSession();2151 WebServiceSession *pWebsession = new WebServiceSession(); 2217 2152 ComPtr<IVirtualBox> pVirtualBox; 2218 2153 2219 2154 // authenticate the user 2220 if (!(p Session->authenticate(req->username.c_str(),2221 req->password.c_str(),2222 pVirtualBox.asOutParam())))2155 if (!(pWebsession->authenticate(req->username.c_str(), 2156 req->password.c_str(), 2157 pVirtualBox.asOutParam()))) 2223 2158 { 2224 // in the new session, create a managed object reference (MOR) for the 2225 // global VirtualBox object; this encodes the session ID in the MOR so 2159 // fake up a "root" MOR for this websession 2160 char sz[34]; 2161 MakeManagedObjectRef(sz, pWebsession->getID(), 0ULL); 2162 WSDLT_ID id = sz; 2163 2164 // in the new websession, create a managed object reference (MOR) for the 2165 // global VirtualBox object; this encodes the websession ID in the MOR so 2226 2166 // that it will be implicitly be included in all future requests of this 2227 2167 // webservice client 2228 ComPtr<IUnknown> p2 = pVirtualBox; 2229 if (pVirtualBox.isNull() || p2.isNull()) 2230 { 2231 rc = E_FAIL; 2232 break; 2233 } 2234 ManagedObjectRef *pRef = new ManagedObjectRef(*pSession, 2235 p2, // IUnknown *pobjUnknown 2236 pVirtualBox, // void *pobjInterface 2237 COM_IIDOF(IVirtualBox), 2238 g_pcszIVirtualBox); 2239 resp->returnval = pRef->getWSDLID(); 2168 resp->returnval = createOrFindRefFromComPtr(id, g_pcszIVirtualBox, pVirtualBox); 2240 2169 WEBDEBUG(("VirtualBox object ref is %s\n", resp->returnval.c_str())); 2241 2170 } … … 2251 2180 2252 2181 /** 2253 * Returns the ISession object that was created for the webservice client 2254 * on logon. 2182 * Returns a new ISession object every time. 2183 * 2184 * No longer connected in any way to logons, one websession can easily 2185 * handle multiple sessions. 2255 2186 */ 2256 2187 int __vbox__IWebsessionManager_USCOREgetSessionObject( … … 2264 2195 do 2265 2196 { 2266 // findSessionFromRef needs lock 2267 util::AutoWriteLock lock(g_pSessionsLockHandle COMMA_LOCKVAL_SRC_POS); 2268 2269 WebServiceSession* pSession; 2270 if ((pSession = WebServiceSession::findSessionFromRef(req->refIVirtualBox))) 2271 resp->returnval = pSession->getSessionWSDLID(); 2272 2197 // create a new ISession object 2198 ComPtr<ISession> pSession; 2199 rc = g_pVirtualBoxClient->COMGETTER(Session)(pSession.asOutParam()); 2200 if (FAILED(rc)) 2201 { 2202 WEBDEBUG(("ERROR: cannot create session object!")); 2203 break; 2204 } 2205 2206 // return its MOR 2207 resp->returnval = createOrFindRefFromComPtr(req->refIVirtualBox, g_pcszISession, pSession); 2208 WEBDEBUG(("Session object ref is %s\n", resp->returnval.c_str())); 2273 2209 } while (0); 2274 2210 … … 2297 2233 do 2298 2234 { 2299 // find SessionFromRef and thesession destructor require the lock2300 util::AutoWriteLock lock(g_p SessionsLockHandle COMMA_LOCKVAL_SRC_POS);2301 2302 WebServiceSession* p Session;2303 if ((p Session = WebServiceSession::findSessionFromRef(req->refIVirtualBox)))2235 // findWebsessionFromRef and the websession destructor require the lock 2236 util::AutoWriteLock lock(g_pWebsessionsLockHandle COMMA_LOCKVAL_SRC_POS); 2237 2238 WebServiceSession* pWebsession; 2239 if ((pWebsession = WebServiceSession::findWebsessionFromRef(req->refIVirtualBox))) 2304 2240 { 2305 delete pSession; 2241 WEBDEBUG(("websession logoff, deleting websession %#llx\n", pWebsession->getID())); 2242 delete pWebsession; 2306 2243 // destructor cleans up 2307 2244 2308 WEBDEBUG((" session destroyed, %d sessions left open\n", g_mapSessions.size()));2245 WEBDEBUG(("websession destroyed, %d websessions left open\n", g_mapWebsessions.size())); 2309 2246 } 2310 2247 } while (0); -
trunk/src/VBox/Main/webservice/vboxweb.h
r46478 r54266 3 3 * header file for "real" web server code. 4 4 * 5 * Copyright (C) 2006-201 3Oracle Corporation5 * Copyright (C) 2006-2015 Oracle Corporation 6 6 * 7 7 * This file is part of VirtualBox Open Source Edition (OSE), as … … 14 14 */ 15 15 16 /****************************************************************************17 *18 * debug macro19 *20 ****************************************************************************/21 22 void WebLog(const char *pszFormat, ...);23 24 #define WEBDEBUG(a) do { if (g_fVerbose) { WebLog a; } } while (0)25 26 16 #ifdef DEBUG 27 17 #define LOG_GROUP LOG_GROUP_WEBSERVICE … … 35 25 #include <VBox/err.h> 36 26 37 #include <iprt/ stream.h>27 #include <iprt/asm.h> 38 28 39 29 #include <string> … … 41 31 /**************************************************************************** 42 32 * 33 * debug macro 34 * 35 ****************************************************************************/ 36 37 RT_C_DECLS_BEGIN 38 extern void WebLog(const char *pszFormat, ...); 39 RT_C_DECLS_END 40 41 #define WEBDEBUG(a) do { if (g_fVerbose) { WebLog a; } } while (0) 42 43 /**************************************************************************** 44 * 43 45 * typedefs 44 46 * … … 46 48 47 49 // type used by gSOAP-generated code 48 typedef std::string WSDLT_ID; // combined managed object ref ( session ID plus object ID)50 typedef std::string WSDLT_ID; // combined managed object ref (websession ID plus object ID) 49 51 typedef std::string vbox__uuid; 50 52 … … 57 59 extern bool g_fVerbose; 58 60 59 extern PRTSTREAM g_pstrLog; 60 61 extern util::WriteLockHandle *g_pAuthLibLockHandle; 62 extern util::WriteLockHandle *g_pSessionsLockHandle; 61 extern util::WriteLockHandle *g_pWebsessionsLockHandle; 63 62 64 63 extern const WSDLT_ID g_EmptyWSDLID; … … 70 69 ****************************************************************************/ 71 70 72 void RaiseSoapInvalidObjectFault(struct soap *soap, WSDLT_ID obj);73 74 void RaiseSoapRuntimeFault(struct soap *soap, const WSDLT_ID &idThis, const char *pcszMethodName, HRESULT apirc, IUnknown *pObj, const com::Guid &iid);71 extern void RaiseSoapInvalidObjectFault(struct soap *soap, WSDLT_ID obj); 72 73 extern void RaiseSoapRuntimeFault(struct soap *soap, const WSDLT_ID &idThis, const char *pcszMethodName, HRESULT apirc, IUnknown *pObj, const com::Guid &iid); 75 74 76 75 /**************************************************************************** … … 80 79 ****************************************************************************/ 81 80 82 std::string ConvertComString(const com::Bstr &bstr); 83 84 std::string ConvertComString(const com::Guid &bstr); 85 86 std::string Base64EncodeByteArray(ComSafeArrayIn(BYTE, aData)); 87 88 void Base64DecodeByteArray(struct soap *soap, const std::string& aStr, ComSafeArrayOut(BYTE, aData), const WSDLT_ID &idThis, const char *pszMethodName, IUnknown *pObj, const com::Guid &iid); 81 extern std::string ConvertComString(const com::Bstr &bstr); 82 83 extern std::string ConvertComString(const com::Guid &bstr); 84 85 extern std::string Base64EncodeByteArray(ComSafeArrayIn(BYTE, aData)); 86 87 extern void Base64DecodeByteArray(struct soap *soap, const std::string& aStr, ComSafeArrayOut(BYTE, aData), const WSDLT_ID &idThis, const char *pszMethodName, IUnknown *pObj, const com::Guid &iid); 88 89 89 /**************************************************************************** 90 90 * … … 99 99 * An instance of this gets created for every client that logs onto the 100 100 * webservice (via the special IWebsessionManager::logon() SOAP API) and 101 * maintains the managed object references for that session.101 * maintains the managed object references for that websession. 102 102 */ 103 103 class WebServiceSession … … 106 106 107 107 private: 108 uint64_t _uSessionID; 108 uint64_t _uWebsessionID; 109 uint64_t _uNextObjectID; 109 110 WebServiceSessionPrivate *_pp; // opaque data struct (defined in vboxweb.cpp) 110 111 bool _fDestructing; 111 112 ManagedObjectRef *_pISession;113 112 114 113 time_t _tLastObjectLookup; … … 130 129 uint64_t getID() const 131 130 { 132 return _uSessionID; 133 } 134 135 const WSDLT_ID& getSessionWSDLID() const; 131 return _uWebsessionID; 132 } 133 134 uint64_t createObjectID() 135 { 136 uint64_t id = ASMAtomicIncU64(&_uNextObjectID); 137 return id - 1; 138 } 136 139 137 140 void touch(); … … 142 145 } 143 146 144 static WebServiceSession* find SessionFromRef(const WSDLT_ID &id);147 static WebServiceSession* findWebsessionFromRef(const WSDLT_ID &id); 145 148 146 149 void DumpRefs(); … … 149 152 /** 150 153 * ManagedObjectRef is used to map COM pointers to object IDs 151 * within a session. Such object IDs are 64-bit integers.154 * within a websession. Such object IDs are 64-bit integers. 152 155 * 153 156 * When a webservice method call is invoked on an object, it 154 157 * has an opaque string called a "managed object reference". Such 155 * a string consists of a session ID combined with an object ID.158 * a string consists of a websession ID combined with an object ID. 156 159 * 157 160 */ … … 159 162 { 160 163 protected: 161 // owning session:162 WebServiceSession &_ session;164 // owning websession: 165 WebServiceSession &_websession; 163 166 164 167 … … 179 182 180 183 public: 181 ManagedObjectRef(WebServiceSession & session,184 ManagedObjectRef(WebServiceSession &websession, 182 185 IUnknown *pobjUnknown, 183 186 void *pobjInterface, … … 224 227 ManagedObjectRef **pRef, 225 228 bool fNullAllowed); 226 227 static ManagedObjectRef* findFromPtr(ComPtr<IUnknown> pcu);228 static ManagedObjectRef* create(const WSDLT_ID &idParent,229 ComPtr<IUnknown> pcu);230 231 229 }; 232 230 … … 263 261 { 264 262 // findRefFromId requires thelock 265 util::AutoWriteLock lock(g_p SessionsLockHandle COMMA_LOCKVAL_SRC_POS);263 util::AutoWriteLock lock(g_pWebsessionsLockHandle COMMA_LOCKVAL_SRC_POS); 266 264 267 265 int rc; … … 314 312 315 313 /** 316 * Creates a new managed object for the given COM pointer. If a reference already exists 317 * for the given pointer, then that reference's ID is returned instead. 318 * 319 * This gets called from tons of generated code in methodmaps.cpp to 320 * resolve objects *returned* from COM methods (i.e. create MOR strings from COM objects 321 * which might have been newly created). 322 * 323 * @param idParent managed object reference of calling object; used to extract session ID 314 * Creates a new managed object reference for the given COM pointer. If one 315 * already exists for the given pointer, then that reference's ID is returned. 316 * 317 * This gets called from tons of generated code in methodmaps.cpp to resolve 318 * objects *returned* from COM methods (i.e. create MOR strings from COM 319 * objects which might have been newly created). 320 * 321 * @param idParent managed object reference of calling object; used to extract 322 * websession ID 324 323 * @param pc COM object for which to create a reference 325 324 * @return existing or new managed object reference … … 328 327 const WSDLT_ID& createOrFindRefFromComPtr(const WSDLT_ID &idParent, 329 328 const char *pcszInterface, 330 ComPtr<T> &pc)329 const ComPtr<T> &pc) 331 330 { 332 331 // NULL comptr should return NULL MOR … … 337 336 } 338 337 339 util::AutoWriteLock lock(g_p SessionsLockHandle COMMA_LOCKVAL_SRC_POS);340 WebServiceSession *p Session;341 if ((p Session = WebServiceSession::findSessionFromRef(idParent)))338 util::AutoWriteLock lock(g_pWebsessionsLockHandle COMMA_LOCKVAL_SRC_POS); 339 WebServiceSession *pWebsession; 340 if ((pWebsession = WebServiceSession::findWebsessionFromRef(idParent))) 342 341 { 343 342 ManagedObjectRef *pRef; … … 346 345 ComPtr<IUnknown> pobjUnknown = pc; 347 346 348 if ( ((pRef = p Session->findRefFromPtr(pobjUnknown)))349 || ((pRef = new ManagedObjectRef(*p Session,347 if ( ((pRef = pWebsession->findRefFromPtr(pobjUnknown))) 348 || ((pRef = new ManagedObjectRef(*pWebsession, 350 349 pobjUnknown, // IUnknown *pobjUnknown 351 350 pc, // void *pobjInterface … … 356 355 } 357 356 358 // session has expired, return an empty MOR instead of allocating a357 // websession has expired, return an empty MOR instead of allocating a 359 358 // new reference which couldn't be used anyway. 360 359 return g_EmptyWSDLID;
Note:
See TracChangeset
for help on using the changeset viewer.