⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 opcshutdownrequest.cpp

📁 此为Insight opc client InfoServerExplorer源程序
💻 CPP
字号:
/////////////////////////////////////////////////////////////////////////////
//
//  OPC DataAccess VC++ Client:	OPCShutDownRequest.cpp
//								(Source File)
//
/////////////////////////////////////////////////////////////////////////////
//
//          Author: Raphael Imhof
//    Initial Date: 12/10/98
//       $Workfile: OPCShutDownRequest.cpp $
//       $Revision: 1 $
//           $Date: 7/27/99 5:23p $
//   Target System: Microsoft Windows NT 4.0
//     Environment: Visual C++ 5.0 / OPC DataAccess 2.0
//         Remarks: 
//
/////////////////////////////////////////////////////////////////////////////
//
//     Description: implementation of the connection point class:
//					COPCShutDownRequest (for OPC 2.0 server shutdown)
//
/////////////////////////////////////////////////////////////////////////////
//
//  History of Changes     (Please remove very old comments and blank lines!)
//            $Log: /IDK/OPCServer/clients/VC++/InfoServerExplorer/OPCShutDownRequest.cpp $
// 
// 1     7/27/99 5:23p Imhof
// 
// 1     7/27/99 5:19p Imhof
// 
// 6     2/08/99 7:45p Imhof
// removed #pragma msg
// 
// 5     1/15/99 6:43p Imhof
// Updated legal notice.
// 
// 4     12/15/98 10:50a Imhof
// Removed unnecessary code line
// 
// 3     12/15/98 9:51a Imhof
// Outputbar output for server shutdown.
// 
// 2     12/11/98 5:58p Imhof
// Made modifications for OPC 2.0.
// 
// 
// 
//  $Nokeywords:$ (To avoid useless search while checking in.)
/////////////////////////////////////////////////////////////////////////////
//  Copyright (C) 1998, Siemens Building Technologies, Inc. Landis Division
//
// SIEMENS BUILDING TECHNOLOGIES, INC. IS PROVIDING THE FOLLOWING
// EXAMPLES OF CODE AS SAMPLE ONLY.
//
// SIEMENS BUILDING TECHNOLOGIES, INC.  MAKES NO REPRESENTATIONS
// OR WARRANTIES OF ANY KIND  WITH RESPECT TO THE VALIDTY OF THE 
// CODES   OR   DESIRED   RESULTS   AND   DISCLAIMS   ALL   SUCH 
// REPRESENTATIONS   AND   WARRANTIES,  INCLUDING  FOR  EXAMPLE, 
// WARRANTIES  OF  MERCHANTABILITY  AND FITNESS FOR A PARTICULAR 
// PURPOSE.    SIEMENS  BUILIDNG  TECHNOLOGIES,  INC.  DOES  NOT 
// REPRESENT  OR  WARRANT  THAT  THE  FOLLOWING CODE SAMPLES ARE 
// ACCURATE, VALID, COMPLETE OR CURRENT.
//
/////////////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "infoserverexplorer.h"
#include "OPCShutDownRequest.h"
#include "MainFrm.h"
#include "infoserverexplorerdoc.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

COPCShutDownRequest::COPCShutDownRequest()
{
	m_dwConnection = 0;
}

COPCShutDownRequest::~COPCShutDownRequest()
{
	ASSERT(m_dwConnection <= 0);
}

STDMETHODIMP COPCShutDownRequest::ShutdownRequest(LPCWSTR szReason)
{
  	/*
		InfoSvr gets marked disconnected in the mainframe shutdown handler
	*/

	CMainFrame* pMainFrame = (CMainFrame*) AfxGetMainWnd();

	((CInfoServerExplorerApp*)AfxGetApp())->DisplayText(szReason);

	//no message boxes in this handler (no blocking in this handler)!
	pMainFrame->SetLastShutdownReason(szReason); //need to safe the reason string
	pMainFrame->PostMessage(WM_SHUTDOWN_MSG);

	return S_OK;
}

BOOL COPCShutDownRequest::Init(CInfoServer* pInfoServer)
{
	DWORD								dwConnection = 0;
	CComPtr<IConnectionPointContainer>	pConPointCont = NULL;
	CComPtr<IConnectionPoint>			pConPoint = NULL;
	BOOL								bRet = FALSE;
	HRESULT								hRes;

	if(pInfoServer->GetOPCVersion() >= OPC_VERSION_20)
	{
		hRes = pInfoServer->GetInterface()->QueryInterface(IID_IConnectionPointContainer, (void**)&pConPointCont);
		if(SUCCEEDED(hRes))
		{
			hRes = pConPointCont->FindConnectionPoint(IID_IOPCShutdown, &pConPoint);				
			if(FAILED(hRes))
			{
				 ((CInfoServerExplorerApp*)AfxGetApp())->DisplayText(_T("FindConnectionPoint"), hRes);
			}
			else
			{
				hRes = pConPoint->Advise(GetUnknown(), &dwConnection);					
				if(FAILED(hRes))
				{
					((CInfoServerExplorerApp*)AfxGetApp())->DisplayText(_T("IConnectionPoint::Advise"), hRes);
				}
				else
				{
					m_dwConnection = dwConnection;
					bRet = TRUE;
				}
				pConPoint.Release();
			}
			pConPointCont.Release();
		}
		else
		{
			//no connection point support
			pInfoServer->DisplayError(hRes);
		}
	}
	
	return bRet;
}

BOOL COPCShutDownRequest::Term(CInfoServer* pInfoServer)
{
	CComPtr<IConnectionPointContainer>	pConPointCont = NULL;
	CComPtr<IConnectionPoint>			pConPoint = NULL;
	BOOL								bRet = FALSE;
	HRESULT								hRes;

	if(pInfoServer->IsConnected())//if server did shutdown it can't succeed)
	{
		hRes = pInfoServer->GetInterface()->QueryInterface(IID_IConnectionPointContainer, (void**)&pConPointCont);
		if(SUCCEEDED(hRes) && (m_dwConnection != 0))
		{
			hRes = pConPointCont->FindConnectionPoint(IID_IOPCShutdown, &pConPoint);				
			if(FAILED(hRes))
			{
				 ((CInfoServerExplorerApp*)AfxGetApp())->DisplayText(_T("FindConnectionPoint"), hRes);
			}
			else
			{
				hRes = pConPoint->Unadvise(m_dwConnection);					
				if(FAILED(hRes))
				{
					((CInfoServerExplorerApp*)AfxGetApp())->DisplayText(_T("IConnectionPoint::Unadvise"), hRes);
				}
				else
				{
					m_dwConnection = 0;
					bRet = TRUE;
				}
				pConPoint.Release();
			}
			pConPointCont.Release();
		}
		else
		{
			//no connection point support
			pInfoServer->DisplayError(hRes);
		}
	}
	else
	{
		m_dwConnection = 0;
	}

	return bRet;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -