📄 scm.cpp
字号:
++j) { ObjectExporterPtr pExp = (*j).second; COM_ASSERT (pExp != 0); if (pExp && pExp->oidPing (oid) == S_OK) { pinged = true; break; } } if (! pinged) hr = OR_INVALID_OID; } return hr; }////////////////////////////////////////////////////////////////////////////// SCM::ComplexPing -- add/remove some OIDs from the ping-set// indicated by the received SETID, which may also be zero menaing// 'create a new set'...//HRESULT SCM::ComplexPing ( SETID* pSetid, // [in,out] set ID USHORT SeqNum, // [in] sequence number USHORT cAddToSet, // [in] USHORT cDelFromSet, // [in] OID AddToSet [], // [in] OID DelFromSet [], // [in] USHORT* pPingBackoffFactor // [out] ) { TRACE_CALL; S_INFO (LOG_SCM, "ComplexPing()"); SETID setid = *pSetid; // enter critical section VxCritSec critSec (m_mutex); // Are we being asked to create a new set? if (setid == 0) { // Yes we are -- make a new entry in the sets table... setid = ++m_nextSetid; m_oidSets [setid] = OIDSET (); } // Make sure we have the entry now... OIDSETMAP::iterator i = m_oidSets.find (setid); if (i == m_oidSets.end ()) return OR_INVALID_SET; HRESULT hr = S_OK; // Delete some OIDs from the set... for (unsigned int d=0; d < cDelFromSet; ++d) (*i).second.erase (DelFromSet [d]); // Add some OIDs to the set... for (unsigned int a=0; a < cAddToSet; ++a) { OID oid = AddToSet [a]; // Add the OID to the set... (*i).second.insert (oid); bool pinged = false; // Ping the exporter associated with this OID - we don't know // which one it is so try them all until we hit one for (OXIDMAP::iterator j = m_exporters.begin (); j != m_exporters.end (); ++j) { ObjectExporterPtr pExp = (*j).second; COM_ASSERT (pExp); if (pExp && SUCCEEDED (pExp->oidPing (oid))) { pinged = true; break; } } if (! pinged) hr = OR_INVALID_OID; } // Update the SETID value... *pSetid = setid; return hr; }////////////////////////////////////////////////////////////////////////////// SCM::ResolveOxid2 -- given an OXID, return the string-binding// indicating how to connect to the Object Exporter represented by// that OXID value...//HRESULT SCM::ResolveOxid2 ( OXID oxid, // [in] OXID to resolve USHORT cReqProtseqs, // [in] num of protseqs USHORT arReqProtseqs[],// [in] array of protseqs DUALSTRINGARRAY** ppdsaOxidBindings,// [out] bindings IPID* pipidRemUnknown,// [out] IPID DWORD* pAuthHint, // [out] security info COMVERSION* pComVersion // [out] COM version ) { TRACE_CALL; ObjectExporterPtr pExp; DUALSTRINGARRAY* pdsa=0; OLECHAR wszSecInfo [] = { 0x0A, 0xFFFF, 0 }; HRESULT hr = S_OK; // Enumerate all object-exporters and see if any have the OXID // value given... if (cReqProtseqs) { VxCritSec critSec (m_mutex); OXIDMAP::iterator i = m_exporters.begin (); while (i != m_exporters.end ()) { pExp = (*i).second; if (pExp && pExp->oxid () == oxid) { pExp->AddRef (); break; } else pExp = 0; } } if (pExp) { // Get info we need from exporter... *pipidRemUnknown = pExp->ipidRemUnknown (); BSTR bsSvrAddr; HRESULT hrAddr = pExp->addressBinding (&bsSvrAddr); pExp->Release (); // Create DSA... if (SUCCEEDED (hrAddr)) { // Allocate memory to hold the DSA... const DWORD dsaLen = sizeof (DUALSTRINGARRAY) + (2 * SysStringLen (bsSvrAddr)) + (2 * vxcom_wcslen (wszSecInfo)) + 16; pdsa = (DUALSTRINGARRAY*) CoTaskMemAlloc (dsaLen); if (pdsa) // Format the DSA... hr = orpcDSAFormat (pdsa, dsaLen, bsSvrAddr, wszSecInfo); else // Memory ran out? hr = E_OUTOFMEMORY; SysFreeString (bsSvrAddr); } else hr = E_OUTOFMEMORY; } else { *pipidRemUnknown = GUID_NULL; hr = OR_INVALID_OXID; } *ppdsaOxidBindings = pdsa; pComVersion->MajorVersion = 5; pComVersion->MinorVersion = 2; *pAuthHint = 1; return hr; } ////////////////////////////////////////////////////////////////////////////// SCM::oxidRegister -- register an ObjectExporter (by its OXID// value) with the SCM...//void SCM::oxidRegister (OXID oxid, ObjectExporter* pexp) { VxCritSec cs (m_mutex); m_exporters [oxid] = pexp; }////////////////////////////////////////////////////////////////////////////// SCM::oxidUnregister -- unregister an ObjectExporter (by its OXID// value) from the SCM...//void SCM::oxidUnregister (OXID oxid) { VxCritSec cs (m_mutex); m_exporters.erase (oxid); }////////////////////////////////////////////////////////////////////////////// SCM::tick -- it is now 'nSecs' since this function was last// called, so we need to prod all the exporters to timeout their// objects. Rather than locking the 'm_exporters' table for a long// time, we cache all the OXID values first, then unlock the table and// individually tick() each exporter. Finally, we tick() all the// RemoteSCM objects...//void SCM::tick (size_t nSecs) { OXID oxids [MAX_EXPORTERS]; size_t nOxids=0; // Cache all OXID values if (nSecs) { VxCritSec cs1 (m_mutex); for (OXIDMAP::iterator i = m_exporters.begin (); i != m_exporters.end (); ++i) { oxids [nOxids++] = (*i).second->oxid (); } } // Now ask each exporter to perform its timeouts... for (size_t n=0; n < nOxids; ++n) { ObjectExporterPtr pExp = m_exporters [ oxids[n] ]; if (pExp) pExp->tick (nSecs); } // Timeout each of the RemoteSCM objects... { VxCritSec cs2 (m_mutex); for (REMOTESCMMAP::iterator s = m_remoteScmTable.begin (); s != m_remoteScmTable.end (); ++s) { (*s).second->pingTick (nSecs); } } }////////////////////////////////////////////////////////////////////////////void SCM::oidAdd (const RpcStringBinding& resAddr, OID oid) { REMOTESCMMAP::iterator i = m_remoteScmTable.find (resAddr); if (i != m_remoteScmTable.end ()) (*i).second->oidAdd (oid); }////////////////////////////////////////////////////////////////////////////void SCM::oidDel (const RpcStringBinding& resAddr, OID oid) { REMOTESCMMAP::iterator i = m_remoteScmTable.find (resAddr); if (i != m_remoteScmTable.end ()) (*i).second->oidDel (oid); }intSCM::PingTimer::handleTimeout ( const TimeValue& timerValue ) { S_DEBUG (LOG_SCM, "SCM::PingTimer::handleTimeout: " << timerValue); SCM* scm = SCM::theSCM (); if (scm) scm->tick (timerValue.sec ()); return scm ? 0 : -1; }////////////////////////////////////////////////////////////////////////////// Global IRemoteActivation, IOXIDResolver and IPrivateSCM// functions. They simply defer to the equivalent methods in the SCM.//HRESULT RemoteActivation ( void* channelId, ORPCTHIS* pORPCthis, ORPCTHAT* pORPCthat, GUID* pClsid, WCHAR* pwszObjectName, MInterfacePointer* pObjectStorage, DWORD clientImpLevel, DWORD mode, DWORD nItfs, IID* pIIDs, unsigned short cReqProtseqs, USHORT* reqProtseqs, OXID* pOxid, DUALSTRINGARRAY** ppdsaOxidBindings, IPID* pipidRemUnknown, DWORD* pAuthnHint, COMVERSION* pServerVersion, HRESULT* phr, MInterfacePointer** ppInterfaceData, HRESULT* pResults ) { SCM* pscm = SCM::theSCM (); return pscm->RemoteActivation ((int) channelId, pORPCthis, pORPCthat, pClsid, pwszObjectName, pObjectStorage, clientImpLevel, mode, nItfs, pIIDs, cReqProtseqs, reqProtseqs, pOxid, ppdsaOxidBindings, pipidRemUnknown, pAuthnHint, pServerVersion, phr, ppInterfaceData, pResults); }HRESULT ResolveOxid ( void* pvRpcChannel, OXID* pOxid, unsigned short cRequestedProtseqs, unsigned short* arRequestedProtseqs, DUALSTRINGARRAY** ppdsaOxidBindings, IPID* pipidRemUnknown, DWORD* pAuthnHint ) { SCM* pscm = SCM::theSCM (); COMVERSION dummy; return pscm->ResolveOxid2 (*pOxid, cRequestedProtseqs, arRequestedProtseqs, ppdsaOxidBindings, pipidRemUnknown, pAuthnHint, &dummy); }HRESULT SimplePing (void* pvRpcChannel, SETID* pSetId) { SCM* pscm = SCM::theSCM (); return pscm->SimplePing (*pSetId); }HRESULT ComplexPing ( void* pvRpcChannel, SETID* pSetId, unsigned short SequenceNum, unsigned short cAddToSet, unsigned short cDelFromSet, OID* AddToSet, OID* DelFromSet, unsigned short* pPingBackoffFactor ) { SCM* pscm = SCM::theSCM (); return pscm->ComplexPing (pSetId, SequenceNum, cAddToSet, cDelFromSet, AddToSet, DelFromSet, pPingBackoffFactor); }HRESULT ServerAlive (void* pvRpcChannel) { return S_OK; }HRESULT ADummyMethod (void * pvRpcChannel) { return S_OK; }HRESULT ResolveOxid2 ( void* pvRpcChannel, OXID* pOxid, unsigned short cRequestedProtseqs, unsigned short* arRequestedProtseqs, DUALSTRINGARRAY** ppdsaOxidBindings, IPID* pipidRemUnknown, DWORD* pAuthnHint, COMVERSION* pComVersion ) { SCM* pscm = SCM::theSCM (); return pscm->ResolveOxid2 (*pOxid, cRequestedProtseqs, arRequestedProtseqs, ppdsaOxidBindings, pipidRemUnknown, pAuthnHint, pComVersion); }#if 0HRESULT IndirectActivation ( LPWSTR pwszServerName, // PROTSEQ + server name REFGUID clsid, // CLSID to activate DWORD mode, // all-1's == get-class-obj DWORD nItfs, // num of interfaces IID* pIIDs, // array of IIDs HRESULT* phr, // returned activation result MInterfacePointer** ppItfData, // returned interface(s) HRESULT* pResults // returned results per i/f ) { SCM* pscm = SCM::theSCM (); return pscm->IndirectActivation (pwszServername, clsid, mode, nItfs, pIIDs, phr, ppItfData, pResults); }HRESULT AddOid (OID oid) { SCM* pscm = SCM::theSCM (); return pscm->AddOid (oid); }HRESULT DelOid (OID oid) { SCM* pscm = SCM::theSCM (); return pscm->DelOid (oid); }HRESULT GetNextOid (OID* pOid) { SCM* pscm = SCM::theSCM (); return pscm->GetNextOid (pOid); }HRESULT GetOxidResolverBinding ( USHORT cProtseqs, USHORT arProtseqs[], DUALSTRINGARRAY** ppdsaBindings ) { SCM* pscm = SCM::theSCM (); return pscm->GetOxidResolverBinding (cProtseqs, arProtseqs, ppdsaBindings); }#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -