#include "comline.hpp" //#include #include #include "comline.h" static void* __cdecl operator new (unsigned int size) { return malloc (size); } static void __cdecl operator delete (void *buffer) { free (buffer); } using namespace NCOMLINE; CCommandLineServer *NCOMLINE::n_CurServer = NULL; void ExecuteLine(const unsigned char * pszString) { if (n_CurServer) n_CurServer->ExecuteLine ((const char *) pszString); } int NumOutputLines(void) { if (n_CurServer) return n_CurServer->NumOutputLines (); return 0; } void GetOutputLine(int size,unsigned char * pszString) { if (n_CurServer) n_CurServer->GetOutputLine (size,pszString); } void Shutdown(void) { #ifdef LAB_ONLY RPC_STATUS status; status = RpcMgmtStopServerListening(NULL); if (!status) { status = RpcServerUnregisterIf(NULL, NULL, FALSE); } #endif } DWORD WINAPI NCOMLINE::ServerThreadProc (void *p1) { #if LAB_ONLY CCommandLineServer *data; data = static_cast (p1); WaitForSingleObject (data->m_Semaphore,INFINITE); ReleaseSemaphore (data->m_ExitSemaphore,1,NULL); ReleaseSemaphore (data->m_Semaphore,1,NULL); RPC_STATUS status; unsigned char * pszProtocolSequence1 = (unsigned char *) "ncacn_ip_tcp"; unsigned char * pszEndpoint1 = (unsigned char *) "1404"; unsigned char * pszProtocolSequence2 = (unsigned char *) "ncalrpc"; unsigned char * pszEndpoint2 = (unsigned char *) "ComLine"; unsigned char * pszSecurity = (unsigned char *) NULL; unsigned int cMinCalls = 1; unsigned int cMaxCalls = 20; unsigned int fDontWait = FALSE; // status = RpcServerUseAllProtseqs (cMaxCalls,pszSecurity); status = RpcServerUseProtseqEp(pszProtocolSequence1,cMaxCalls,pszEndpoint1,pszSecurity); // Security descriptor if (status) return (status); status = RpcServerUseProtseqEp(pszProtocolSequence2,cMaxCalls,pszEndpoint2,pszSecurity); // Security descriptor if (status) return (status); RPC_BINDING_VECTOR *inq; status = RpcServerInqBindings (&inq); status = RpcServerRegisterIf(ComLine_ServerIfHandle, // interface to register NULL, // MgrTypeUuid NULL); // MgrEpv; null means use default if (status) return (status); status = RpcServerListen(cMinCalls,cMaxCalls,fDontWait); if (status) return status; WaitForSingleObject (data->m_ExitSemaphore,INFINITE); #endif return 0; } void CCommandLineServer::PushLine (const LineData& data) { CRITICAL_CONTROL (m_Critical); if (!m_Inited) return; if (m_NumLines == m_SizeLines) { int i; LineData *temp; temp = new LineData[m_SizeLines+50]; for (i=0;im_Data; strncpy ((char *) pszString,buffer,size-1); pszString[size-1] = 0; RemoveLine (); } else pszString[0] = 0; } bool CCommandLineServer::AddCommand (NCOMLINE::ComFunc func,const CCom_String& name) { CRITICAL_CONTROL (m_Critical); int iter; if (!m_Inited) return false; for (iter = 0;iter