?? impiopcitemmgt.cpp
字號(hào):
// - S_FALSE if the function was partially successful.
// This can happen if the client passes down some
// "good" handles and some "bad" handles to be
// removed. The client will then need to look in
// the ppErrors array to find out which item
// handles caused the errors.
// - E_FAIL if the function failed altogether.
//
////////////////////////////////////////////////////////////////
STDMETHODIMP CImpIOPCItemMgt::RemoveItems(DWORD dwNumItems,
OPCHANDLE *phServer,
HRESULT **ppErrors)
{
unsigned int i;
OPCHANDLE OPCHandle;
HRESULT *pHResultList,
hr = S_OK;
// Make sure we were passed good pointers
//
if((NULL == phServer) ||
(NULL == ppErrors))
{
return E_INVALIDARG;
}
// First - allocate memory for the result array(s)
//
*ppErrors = pHResultList =
(HRESULT *)pIMalloc->Alloc(sizeof(HRESULT) * dwNumItems);
if(NULL == pHResultList)
{
return E_OUTOFMEMORY;
}
// Lock the group so other threads don't try and access the items
// we are deleting
//
m_pParentGroup->Lock();
// Now for each item handle...
//
for(i = 0; i < dwNumItems; i++)
{
// Insure handle is valid
//
OPCHandle = phServer[i];
if(!m_pParentGroup->IsItemValid(OPCHandle))
{
pHResultList[i] = OPC_E_INVALIDHANDLE;
hr = S_FALSE;
continue;
}
// Remove it from the map. (This will perform a Release().)
//
m_pParentGroup->ItemFree(OPCHandle);
pHResultList[i] = S_OK;
}
m_pParentGroup->UnLock();
return hr;
}
////////////////////////////////////////////////////////////////
// SetActiveState()
//
// This function sets the state of a list of functions to either
// active or inactive.
//
// Returns:
// HRESULT - S_OK if everything was successful
// - S_FALSE if the function was partially successful.
// This can happen if the client passes down some
// "good" handles and some "bad" handles to be
// removed. The client will then need to look in
// the ppErrors array to find out which item
// handles caused the errors.
// - E_FAIL if the function failed altogether.
//
////////////////////////////////////////////////////////////////
STDMETHODIMP CImpIOPCItemMgt::SetActiveState(DWORD dwNumItems,
OPCHANDLE *phServer,
BOOL bActive,
HRESULT **ppErrors)
{
unsigned int i;
OPCHANDLE OPCHandle;
HRESULT *pHResultList,
hr = S_OK;
// Make sure we were passed good pointers
//
if((NULL == phServer) ||
(NULL == ppErrors))
{
return E_INVALIDARG;
}
// First - allocate memory for the result array(s)
//
*ppErrors = pHResultList = (HRESULT*) pIMalloc->Alloc(sizeof(HRESULT) *dwNumItems);
if(NULL == pHResultList)
{
return E_OUTOFMEMORY;
}
// Now for each item handle...
//
for(i = 0; i < dwNumItems; i++)
{
// Insure handle is valid
//
OPCHandle = phServer[i];
if(FALSE == m_pParentGroup->IsItemValid(OPCHandle))
{
pHResultList[i] = OPC_E_INVALIDHANDLE;
hr = S_FALSE;
continue;
}
// And if so then activate the item
//
m_pParentGroup->GetItemPtr(OPCHandle)->SetActive(bActive);
pHResultList[i] = S_OK;
}
return hr;
}
////////////////////////////////////////////////////////////////
// SetClientHandles()
//
// This function sets the client handles for a list of items.
// The client handle is the handle that the client uses to
// refer to the item. It really doesn;t have any meaning to us.
//
// Returns:
// HRESULT - S_OK if everything was successful
// - S_FALSE if the function was partially successful.
// This can happen if the client passes down some
// "good" handles and some "bad" handles to be
// removed. The client will then need to look in
// the ppErrors array to find out which item
// handles caused the errors.
// - E_FAIL if the function failed altogether.
//
////////////////////////////////////////////////////////////////
STDMETHODIMP CImpIOPCItemMgt::SetClientHandles(DWORD dwNumItems,
OPCHANDLE *phServer,
OPCHANDLE *phClient,
HRESULT **ppErrors)
{
unsigned int i;
OPCHANDLE OPCHandle;
HRESULT *pHResultList,
hr = S_OK;
// Make sure we were passed good pointers
//
if((NULL == phServer) ||
(NULL == ppErrors) ||
(NULL == phClient))
{
return E_INVALIDARG;
}
// First - allocate memory for the result array(s)
//
*ppErrors = pHResultList = (HRESULT*) pIMalloc->Alloc(sizeof(HRESULT) * dwNumItems);
if(NULL == pHResultList)
{
return E_FAIL;
}
// Now for each item handle...
//
for(i = 0; i < dwNumItems; i++)
{
// Insure handle is valid
//
OPCHandle = phServer[i];
if(!m_pParentGroup->IsItemValid(OPCHandle))
{
pHResultList[i] = OPC_E_INVALIDHANDLE;
hr = S_FALSE;
continue;
}
// And if so then set client handle
//
m_pParentGroup->GetItemPtr(OPCHandle)->SetHandle(phClient[i]);
pHResultList[i] = S_OK;
}
return hr;
}
////////////////////////////////////////////////////////////////
// SetDataTypes()
//
// This function sets the requested datatypes of a list of items.
//
// Returns:
// HRESULT - S_OK if everything was successful
// - S_FALSE if the function was partially successful.
// This can happen if the client passes down some
// "good" handles and some "bad" handles to be
// removed. The client will then need to look in
// the ppErrors array to find out which item
// handles caused the errors.
// - E_FAIL if the function failed altogether.
//
////////////////////////////////////////////////////////////////
STDMETHODIMP CImpIOPCItemMgt::SetDatatypes(DWORD dwNumItems,
OPCHANDLE *phServer,
VARTYPE *pRequestedDatatypes,
HRESULT **ppErrors)
{
COPCDrvItem *pItem = NULL;
OPCHANDLE OPCHandle;
HRESULT *pHResultList,
hr = S_OK;
// Make sure we were passed good pointers
//
if((NULL == phServer) ||
(NULL == ppErrors) ||
(NULL == pRequestedDatatypes))
{
return E_INVALIDARG;
}
// First - allocate memory for the result array(s)
//
*ppErrors = pHResultList =
(HRESULT *)pIMalloc->Alloc(sizeof(HRESULT) * dwNumItems);
if(NULL == pHResultList)
{
return E_FAIL;
}
// Now for each item handle...
//
for(DWORD i = 0; i < dwNumItems; i++)
{
// Insure handle is valid
//
OPCHandle = phServer[i];
pItem = m_pParentGroup->GetItemPtr(OPCHandle);
if(FALSE == pItem)
{
pHResultList[i] = OPC_E_INVALIDHANDLE;
hr = S_FALSE;
continue;
}
// And if so then set data type
//
pHResultList[i] = pItem->SetDatatype(pRequestedDatatypes[i]);
if(FAILED(pHResultList[i]))
{
hr = S_FALSE;
continue;
}
}
return hr;
}
////////////////////////////////////////////////////////////////
// CreateEnumerator()
//
////////////////////////////////////////////////////////////////
STDMETHODIMP CImpIOPCItemMgt::CreateEnumerator(REFIID riid,
LPUNKNOWN *ppUnk)
{
// Make sure we were passed good pointers
//
if(NULL == ppUnk)
{
return E_INVALIDARG;
}
// default in case of error
//
*ppUnk = NULL;
if (IID_IEnumOPCItemAttributes == riid)
{
CImpIEnumOPCItemAttributes *temp;
OPCITEMATTRIBUTES *AttrList;
int ItemCount;
HRESULT hr;
// Lock the parent group
//
m_pParentGroup->Lock();
// Get a 'local' snapshot of the item list
//
m_pParentGroup->GetItemList(&AttrList, &ItemCount);
// Create the Enumerator which will contain a copy of the snapshot
// Note that the enumerator is not affected by
// subsequent changes to the item list.
// The group will get an 'addref' via m_Parent below and will thus
// stay around until the enumerator is released
// (although this is probably unnecessary)
//
temp = new CImpIEnumOPCItemAttributes(m_pUnkOuter,
ItemCount,
AttrList,
pIMalloc);
m_pParentGroup->FreeItemList(AttrList, ItemCount);
// Unock the parent group
//
m_pParentGroup->UnLock();
// Then QI for the interface. ('temp' actually is the interface
// but QI is the 'proper' way to get it.)
// Note QI will do an AddRef of the Enum which will also do
// an AddRef of the 'parent' - i.e. the 'this' pointer passed above.
//
hr = temp->QueryInterface(riid, (LPVOID *)ppUnk);
if (FAILED(hr))
{
delete temp;
return hr;
}
return S_OK;
}
return E_INVALIDARG;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -