[Com0com-cvs] hub4com/plugins/tcp import.h, NONE, 1.1 port.cpp, NONE, 1.1 tcp.vcproj, NONE, 1.1
The virtual serial port driver for Windows.
Brought to you by:
vfrolov
From: Vyacheslav F. <vf...@us...> - 2008-03-27 17:19:21
|
Update of /cvsroot/com0com/hub4com/plugins/tcp In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv2316 Added Files: import.h port.cpp tcp.vcproj Log Message: Initial revision --- NEW FILE: import.h --- /* * $Id: import.h,v 1.1 2008/03/27 17:19:18 vfrolov Exp $ * * Copyright (c) 2008 Vyacheslav Frolov * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * * $Log: import.h,v $ * Revision 1.1 2008/03/27 17:19:18 vfrolov * Initial revision * * */ #ifndef _IMPORT_H #define _IMPORT_H #include "../plugins_api.h" /////////////////////////////////////////////////////////////// extern ROUTINE_BUF_ALLOC *pBufAlloc; extern ROUTINE_BUF_FREE *pBufFree; extern ROUTINE_ON_XOFF *pOnXoff; extern ROUTINE_ON_XON *pOnXon; extern ROUTINE_ON_READ *pOnRead; /////////////////////////////////////////////////////////////// #endif // _IMPORT_H --- NEW FILE: port.cpp --- /* * $Id: port.cpp,v 1.1 2008/03/27 17:19:18 vfrolov Exp $ * * Copyright (c) 2008 Vyacheslav Frolov * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * * $Log: port.cpp,v $ * Revision 1.1 2008/03/27 17:19:18 vfrolov * Initial revision * * */ #include "precomp.h" #include "comparams.h" #include "comport.h" #include "import.h" #include "../../utils.h" /////////////////////////////////////////////////////////////// static PLUGIN_TYPE CALLBACK GetPluginType() { return PLUGIN_TYPE_PORT; } /////////////////////////////////////////////////////////////// static const PLUGIN_ABOUT_A about = { sizeof(PLUGIN_ABOUT_A), "tcp", "Copyright (c) 2008 Vyacheslav Frolov", "GNU General Public License", "TCP port", }; static const PLUGIN_ABOUT_A * CALLBACK GetPluginAbout() { return &about; } /////////////////////////////////////////////////////////////// static void CALLBACK Help(const char *pProgPath) { cerr << "Usage (client mode):" << endl << " " << pProgPath << " ... [--use-port-module=" << GetPluginAbout()->pName << "] [*]<host addr>:<host port> ..." << endl << "Usage (server mode):" << endl << " " << pProgPath << " ... [--use-port-module=" << GetPluginAbout()->pName << "] [*]<listen port> ..." << endl << endl << " The sign * above means that connection shold be permanent as it possible." << endl << endl << "Options:" << endl << " --interface=<if> - use interface <if>." << endl << "Examples:" << endl << " " << pProgPath << " --use-port-module=" << GetPluginAbout()->pName << " 1111 222.22.22.22:2222" << endl << " - listen TCP port 1111 and on incoming connection connect to" << endl << " 222.22.22.22:2222, receive data from 1111 and send it to" << endl << " 222.22.22.22:2222, receive data from 222.22.22.22:2222 and send it to" << endl << " 1111, on disconnecting any connection disconnect paired connection." << endl << " " << pProgPath << " --use-port-module=" << GetPluginAbout()->pName << " *111.11.11.11:1111 *222.22.22.22:2222" << endl << " - connect to 111.11.11.11:1111 and connect to 222.22.22.22:2222," << endl << " receive data from 111.11.11.11:1111 and send it to 222.22.22.22:2222," << endl << " receive data from 222.22.22.22:2222 and send it to 111.11.11.11:1111," << endl << " on disconnecting any connection reconnect it." << endl << " " << pProgPath << " --route=All:All --use-port-module=" << GetPluginAbout()->pName << " *1111 *1111 *1111" << endl << " - up to 3 clients can connect to port 2222 and talk each others." << endl ; } /////////////////////////////////////////////////////////////// static HCONFIG CALLBACK ConfigStart() { ComParams *pComParams = new ComParams; if (!pComParams) { cerr << "No enough memory." << endl; exit(2); } return (HCONFIG)pComParams; } /////////////////////////////////////////////////////////////// static BOOL CALLBACK Config( HCONFIG hConfig, const char *pArg) { _ASSERTE(hConfig != NULL); ComParams &comParams = *(ComParams *)hConfig; const char *pParam; if ((pParam = GetParam(pArg, "--interface=")) != NULL) { comParams.SetIF(pParam); } else { return FALSE; } return TRUE; } /////////////////////////////////////////////////////////////// static void CALLBACK ConfigStop( HCONFIG hConfig) { _ASSERTE(hConfig != NULL); delete (ComParams *)hConfig; } /////////////////////////////////////////////////////////////// static vector<Listener *> *pListeners = NULL; static HPORT CALLBACK Create( HCONFIG hConfig, const char *pPath) { _ASSERTE(hConfig != NULL); if (!pListeners) pListeners = new vector<Listener *>; if (!pListeners) return NULL; ComPort *pPort = new ComPort(*pListeners, *(const ComParams *)hConfig, pPath); if (!pPort) return NULL; return (HPORT)pPort; } /////////////////////////////////////////////////////////////// static const char *CALLBACK GetPortName( HPORT hPort) { _ASSERTE(hPort != NULL); return ((ComPort *)hPort)->Name().c_str(); } /////////////////////////////////////////////////////////////// static void CALLBACK SetPortName( HPORT hPort, const char *pName) { _ASSERTE(hPort != NULL); _ASSERTE(pName != NULL); ((ComPort *)hPort)->Name(pName); } /////////////////////////////////////////////////////////////// static BOOL CALLBACK Init( HPORT hPort, HMASTERPORT hMasterPort, HHUB hHub) { _ASSERTE(hPort != NULL); _ASSERTE(hMasterPort != NULL); _ASSERTE(hHub != NULL); return ((ComPort *)hPort)->Init(hMasterPort, hHub); } /////////////////////////////////////////////////////////////// static BOOL CALLBACK Start(HPORT hPort) { _ASSERTE(hPort != NULL); return ((ComPort *)hPort)->Start(); } /////////////////////////////////////////////////////////////// static BOOL CALLBACK Write( HPORT hPort, HUB_MSG *pMsg) { _ASSERTE(hPort != NULL); _ASSERTE(pMsg != NULL); return ((ComPort *)hPort)->Write(pMsg); } /////////////////////////////////////////////////////////////// static void CALLBACK AddXoff( HPORT hPort) { _ASSERTE(hPort != NULL); ((ComPort *)hPort)->AddXoff(1); } /////////////////////////////////////////////////////////////// static void CALLBACK AddXon( HPORT hPort) { _ASSERTE(hPort != NULL); ((ComPort *)hPort)->AddXoff(-1); } /////////////////////////////////////////////////////////////// static void CALLBACK LostReport( HPORT hPort) { _ASSERTE(hPort != NULL); ((ComPort *)hPort)->LostReport(); } /////////////////////////////////////////////////////////////// static const PORT_ROUTINES_A routines = { sizeof(PORT_ROUTINES_A), GetPluginType, GetPluginAbout, Help, ConfigStart, Config, ConfigStop, Create, GetPortName, SetPortName, Init, Start, Write, AddXoff, AddXon, LostReport, }; static const PLUGIN_ROUTINES_A *const plugins[] = { (const PLUGIN_ROUTINES_A *)&routines, NULL }; /////////////////////////////////////////////////////////////// ROUTINE_BUF_ALLOC *pBufAlloc; ROUTINE_BUF_FREE *pBufFree; ROUTINE_ON_XOFF *pOnXoff; ROUTINE_ON_XON *pOnXon; ROUTINE_ON_READ *pOnRead; /////////////////////////////////////////////////////////////// PLUGIN_INIT_A InitA; const PLUGIN_ROUTINES_A *const * CALLBACK InitA( const HUB_ROUTINES_A * pHubRoutines) { if (!ROUTINE_IS_VALID(pHubRoutines, pBufAlloc) || !ROUTINE_IS_VALID(pHubRoutines, pBufFree) || !ROUTINE_IS_VALID(pHubRoutines, pOnXoff) || !ROUTINE_IS_VALID(pHubRoutines, pOnXon) || !ROUTINE_IS_VALID(pHubRoutines, pOnRead)) { return NULL; } pBufAlloc = pHubRoutines->pBufAlloc; pBufFree = pHubRoutines->pBufFree; pOnXoff = pHubRoutines->pOnXoff; pOnXon = pHubRoutines->pOnXon; pOnRead = pHubRoutines->pOnRead; WSADATA wsaData; WSAStartup(MAKEWORD(1, 1), &wsaData); return plugins; } /////////////////////////////////////////////////////////////// --- NEW FILE: tcp.vcproj --- <?xml version="1.0" encoding="windows-1251"?> <VisualStudioProject ProjectType="Visual C++" Version="8,00" Name="port-tcp" ProjectGUID="{A1F397C9-2779-49D9-886F-A25D5E41EB0B}" RootNamespace="hub4com" Keyword="Win32Proj" > <Platforms> <Platform Name="Win32" /> </Platforms> <ToolFiles> </ToolFiles> <Configurations> <Configuration Name="Debug|Win32" OutputDirectory="Debug" IntermediateDirectory="Debug" ConfigurationType="2" UseOfMFC="0" > <Tool Name="VCPreBuildEventTool" /> <Tool Name="VCCustomBuildTool" /> <Tool Name="VCXMLDataGeneratorTool" /> <Tool Name="VCWebServiceProxyGeneratorTool" /> <Tool Name="VCMIDLTool" /> <Tool Name="VCCLCompilerTool" Optimization="0" PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE" MinimalRebuild="true" BasicRuntimeChecks="3" RuntimeLibrary="1" UsePrecompiledHeader="2" PrecompiledHeaderThrough="precomp.h" PrecompiledHeaderFile="$(IntDir)\precomp.pch" WarningLevel="4" Detect64BitPortabilityProblems="true" DebugInformationFormat="4" /> <Tool Name="VCManagedResourceCompilerTool" /> <Tool Name="VCResourceCompilerTool" /> <Tool Name="VCPreLinkEventTool" /> <Tool Name="VCLinkerTool" AdditionalDependencies="ws2_32.lib" OutputFile="..\..\$(OutDir)\plugins\$(ProjectName).dll" LinkIncremental="2" ModuleDefinitionFile="..\plugins.def" GenerateDebugInformation="true" SubSystem="1" TargetMachine="1" /> <Tool Name="VCALinkTool" /> <Tool Name="VCManifestTool" /> <Tool Name="VCXDCMakeTool" /> <Tool Name="VCBscMakeTool" /> <Tool Name="VCFxCopTool" /> <Tool Name="VCAppVerifierTool" /> <Tool Name="VCWebDeploymentTool" /> <Tool Name="VCPostBuildEventTool" /> </Configuration> <Configuration Name="Release|Win32" OutputDirectory="Release" IntermediateDirectory="Release" ConfigurationType="2" UseOfMFC="0" > <Tool Name="VCPreBuildEventTool" /> <Tool Name="VCCustomBuildTool" /> <Tool Name="VCXMLDataGeneratorTool" /> <Tool Name="VCWebServiceProxyGeneratorTool" /> <Tool Name="VCMIDLTool" /> <Tool Name="VCCLCompilerTool" PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE" RuntimeLibrary="0" UsePrecompiledHeader="2" PrecompiledHeaderThrough="precomp.h" PrecompiledHeaderFile="$(IntDir)\precomp.pch" WarningLevel="4" Detect64BitPortabilityProblems="true" DebugInformationFormat="3" /> <Tool Name="VCManagedResourceCompilerTool" /> <Tool Name="VCResourceCompilerTool" /> <Tool Name="VCPreLinkEventTool" /> <Tool Name="VCLinkerTool" AdditionalDependencies="ws2_32.lib" OutputFile="..\..\$(OutDir)\plugins\$(ProjectName).dll" LinkIncremental="2" ModuleDefinitionFile="..\plugins.def" GenerateDebugInformation="true" SubSystem="1" OptimizeReferences="2" EnableCOMDATFolding="2" TargetMachine="1" /> <Tool Name="VCALinkTool" /> <Tool Name="VCManifestTool" /> <Tool Name="VCXDCMakeTool" /> <Tool Name="VCBscMakeTool" /> <Tool Name="VCFxCopTool" /> <Tool Name="VCAppVerifierTool" /> <Tool Name="VCWebDeploymentTool" /> <Tool Name="VCPostBuildEventTool" /> </Configuration> </Configurations> <References> </References> <Files> <Filter Name="Header Files" Filter="h;hpp;hxx;hm;inl;inc;xsd" UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" > <File RelativePath=".\comio.h" > </File> <File RelativePath=".\comparams.h" > </File> <File RelativePath=".\comport.h" > </File> <File RelativePath=".\import.h" > </File> <File RelativePath="..\plugins_api.h" > </File> <File RelativePath=".\precomp.h" > </File> <File RelativePath="..\..\utils.h" > </File> </Filter> <Filter Name="Source Files" Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx" UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" > <File RelativePath=".\comio.cpp" > </File> <File RelativePath=".\comparams.cpp" > </File> <File RelativePath=".\comport.cpp" > </File> <File RelativePath="..\plugins.def" > </File> <File RelativePath=".\port.cpp" > </File> <File RelativePath=".\precomp.cpp" > <FileConfiguration Name="Debug|Win32" > <Tool Name="VCCLCompilerTool" UsePrecompiledHeader="1" /> </FileConfiguration> <FileConfiguration Name="Release|Win32" > <Tool Name="VCCLCompilerTool" UsePrecompiledHeader="1" /> </FileConfiguration> </File> <File RelativePath="..\..\utils.cpp" > </File> </Filter> </Files> <Globals> </Globals> </VisualStudioProject> |