/* * P4.Net * Copyright (c) 2006 Shawn Hladky Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include "StdAfx.h" #using <mscorlib.dll> #include "clientapi_m.h" using namespace System::Runtime::InteropServices; p4dn::ClientApi::ClientApi() { _Disposed = false; _clientApi = new ::ClientApi(); _keepAliveDelegate = NULL; } p4dn::ClientApi::~ClientApi() { CleanUp(); } ::ClientApi* p4dn::ClientApi::_getClientApi() { // Oops someone called dispose too early!!! if (_Disposed) { //Have to throw an error here. throw new System::Exception("Error! ClientApi has been Disposed!"); } return _clientApi; } void p4dn::ClientApi::CleanUp() { if (_clientApi != NULL) delete _clientApi; if (_keepAliveDelegate != NULL) delete _keepAliveDelegate; _clientApi = NULL; _keepAliveDelegate = NULL; } void p4dn::ClientApi::Dispose() { System::GC::SuppressFinalize(this); CleanUp(); _Disposed = true; } void p4dn::ClientApi::SetTrans( int output, int content, int fnames, int dialog ) { _getClientApi()->SetTrans( output, content, fnames, dialog ); } void p4dn::ClientApi::SetProtocol( String *p, String *v ) { char* str_p = (char *)(void *) Marshal::StringToHGlobalAnsi( p ); char* str_v = (char *)(void *) Marshal::StringToHGlobalAnsi( v ); _getClientApi()->SetProtocol( str_p, str_v ); Marshal::FreeHGlobal( str_p ); Marshal::FreeHGlobal( str_v ); } void p4dn::ClientApi::SetArgv( String* args[] ) { char** argsArray = new char* [ args->Length ]; for (int i = 0; i < args->Length; ++i) { argsArray[i] = (char *)(void *) Marshal::StringToHGlobalAnsi( args[i] ); } _getClientApi()->SetArgv( args->Length, argsArray ); for (int i = 0; i < args->Length; ++i) { Marshal::FreeHGlobal( argsArray[i] ); } delete argsArray; } void p4dn::ClientApi::SetProtocolV( String* p ) { char* str_p = (char *)(void *) Marshal::StringToHGlobalAnsi( p ); _getClientApi()->SetProtocolV( str_p ); Marshal::FreeHGlobal( str_p ); } String* p4dn::ClientApi::GetProtocol( String *v ) { char* str_p = (char *)(void *) Marshal::StringToHGlobalAnsi( v ); StrPtr* ptr = _getClientApi()->GetProtocol( str_p ); String* s = ptr->Text(); delete ptr; Marshal::FreeHGlobal( str_p ); return s; } void p4dn::ClientApi::Init( p4dn::Error* e ) { _getClientApi()->Init( e->get_InternalError() ); } void p4dn::ClientApi::Run( String* func, p4dn::ClientUser *ui ) { // System::Console::WriteLine( "Running command {0}", func ); char* f = (char *)(void *) Marshal::StringToHGlobalAnsi( func ); ClientUserDelegate __nogc* cud = new ClientUserDelegate(ui); _getClientApi()->Run(f, cud); delete cud; Marshal::FreeHGlobal( f ); } void p4dn::ClientApi::SaveForm( String* func, p4dn::ClientUser *ui ) { // System::Console::WriteLine( "Running command {0}", func ); char* f = (char *)(void *) Marshal::StringToHGlobalAnsi( func ); ClientUserDelegate __nogc* cud = new ClientUserDelegate(ui); cud->SaveForm(); _getClientApi()->Run(f, cud); delete cud; Marshal::FreeHGlobal( f ); } int p4dn::ClientApi::Final( p4dn::Error *e ) { return _getClientApi()->Final( e->get_InternalError() ); } int p4dn::ClientApi::Dropped() { return _getClientApi()->Dropped(); } // // These functions are disabled. There will be a lot of work to enable // asynchronous execution and ensure that all of references are released // so managed objects are garbage collected // //void p4dn::ClientApi::RunTag( String* func, p4dn::ClientUser *ui ) //{ // char* f = (char *)(void *) Marshal::StringToHGlobalAnsi( func ); //ClientUserDelegate __nogc* cud = new ClientUserDelegate(ui); // _clientApi->RunTag( f, cud); //delete cud; // Marshal::FreeHGlobal( f ); //} //void p4dn::ClientApi::WaitTag( p4dn::ClientUser *ui ) //{ //ClientUserDelegate __nogc* cud = new ClientUserDelegate(ui); // _clientApi->WaitTag( cud ); //delete cud; //} void p4dn::ClientApi::SetCharset( String* c ) { char* f = (char *)(void *) Marshal::StringToHGlobalAnsi( c ); _getClientApi()->SetCharset( f ); Marshal::FreeHGlobal( f ); } void p4dn::ClientApi::SetClient( String* c ) { char* f = (char *)(void *) Marshal::StringToHGlobalAnsi( c ); _getClientApi()->SetClient( f ); Marshal::FreeHGlobal( f ); } void p4dn::ClientApi::SetCwd( String* c ) { char* f = (char *)(void *) Marshal::StringToHGlobalAnsi( c ); _getClientApi()->SetCwd( f ); Marshal::FreeHGlobal( f ); } void p4dn::ClientApi::SetHost( String* c ) { char* f = (char *)(void *) Marshal::StringToHGlobalAnsi( c ); _getClientApi()->SetHost( f ); Marshal::FreeHGlobal( f ); } void p4dn::ClientApi::SetLanguage( String* c ) { char* f = (char *)(void *) Marshal::StringToHGlobalAnsi( c ); _getClientApi()->SetLanguage( f ); Marshal::FreeHGlobal( f ); } void p4dn::ClientApi::SetPassword( String* c ) { char* f = (char *)(void *) Marshal::StringToHGlobalAnsi( c ); _getClientApi()->SetPassword( f ); Marshal::FreeHGlobal( f ); } void p4dn::ClientApi::SetPort( String* c ) { char* f = (char *)(void *) Marshal::StringToHGlobalAnsi( c ); _getClientApi()->SetPort( f ); Marshal::FreeHGlobal( f ); } void p4dn::ClientApi::SetProg( String* c ) { char* f = (char *)(void *) Marshal::StringToHGlobalAnsi( c ); _getClientApi()->SetProg( f ); Marshal::FreeHGlobal( f ); } void p4dn::ClientApi::SetVersion( String* c ) { char* f = (char *)(void *) Marshal::StringToHGlobalAnsi( c ); _getClientApi()->SetVersion( f ); Marshal::FreeHGlobal( f ); } void p4dn::ClientApi::SetUser( String* c ) { char* f = (char *)(void *) Marshal::StringToHGlobalAnsi( c ); _getClientApi()->SetUser( f ); Marshal::FreeHGlobal( f ); } void p4dn::ClientApi::SetBreak( p4dn::KeepAlive *keepAlive ) { if (_keepAliveDelegate != NULL) { return; } _keepAliveDelegate = new KeepAliveDelegate( keepAlive ); } void p4dn::ClientApi::DefineCharset( String* c, p4dn::Error* e ) { char* f = (char *)(void *) Marshal::StringToHGlobalAnsi( c ); _getClientApi()->DefineCharset( f, e->get_InternalError() ); Marshal::FreeHGlobal( f ); } void p4dn::ClientApi::DefineClient( String* c, p4dn::Error* e ) { char* f = (char *)(void *) Marshal::StringToHGlobalAnsi( c ); _getClientApi()->DefineClient( f, e->get_InternalError() ); Marshal::FreeHGlobal( f ); } void p4dn::ClientApi::DefineHost( String* c, p4dn::Error* e ) { char* f = (char *)(void *) Marshal::StringToHGlobalAnsi( c ); _getClientApi()->DefineHost( f, e->get_InternalError() ); Marshal::FreeHGlobal( f ); } void p4dn::ClientApi::DefineLanguage( String* c, p4dn::Error* e ) { char* f = (char *)(void *) Marshal::StringToHGlobalAnsi( c ); _getClientApi()->DefineLanguage( f, e->get_InternalError() ); Marshal::FreeHGlobal( f ); } void p4dn::ClientApi::DefinePassword( String* c, p4dn::Error* e ) { char* f = (char *)(void *) Marshal::StringToHGlobalAnsi( c ); _getClientApi()->DefinePassword( f, e->get_InternalError() ); Marshal::FreeHGlobal( f ); } void p4dn::ClientApi::DefinePort( String* c, p4dn::Error* e ) { char* f = (char *)(void *) Marshal::StringToHGlobalAnsi( c ); _getClientApi()->DefinePort( f, e->get_InternalError() ); Marshal::FreeHGlobal( f ); } void p4dn::ClientApi::DefineUser( String* c, p4dn::Error* e ) { char* f = (char *)(void *) Marshal::StringToHGlobalAnsi( c ); _getClientApi()->DefineUser( f, e->get_InternalError() ); Marshal::FreeHGlobal( f ); }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 7291 | Andrew McDonald | initial submittal | ||
//guest/shawn_hladky/P4.Net/release/0.9/src/p4dn/ClientApi_m.cpp | |||||
#1 | 5831 | Shawn Hladky | P4.Net: Branch release 0.9 and delete a few files missed last time | ||
//guest/shawn_hladky/P4.Net/main/src/p4dn/ClientApi_m.cpp | |||||
#1 | 5830 | Shawn Hladky | P4.Net: reorg to support release branches | ||
//guest/shawn_hladky/P4.Net/src/p4dn/ClientApi_m.cpp | |||||
#3 | 5798 | Shawn Hladky |
P4.Net... still not ready for beta Added license to all files Added several doc files Misc bugs |
||
#2 | 5373 | Shawn Hladky | P4.Net: Still WIP, but some things starting to work | ||
#1 | 5348 | Shawn Hladky | Re-organizing, for the improved API | ||
//guest/shawn_hladky/PerforceDotNet/p4dn/ClientApi_m.cpp | |||||
#4 | 5064 | Shawn Hladky |
WIP -- Added ability to parse forms. Added new tester application. ** not ready for human consumption, needs more review and testing. |
||
#3 | 4643 | Shawn Hladky | Clean-up some more memory issues | ||
#2 | 4545 | Shawn Hladky |
Several Fixes: Updated solution to Visual Studio 2003 Implemented InputData Implemented OutPutBinary Changed ClientAPI and Error objects to implement the IDisposable interface to improve Garbage Collection Changed header files so you don't need to add #pragma once to the p4 api headers. Refactored the ClientUserDelagate class Fixed a few minor memory leaks |
||
#1 | 4328 | Shawn Hladky | Branching from //guest/jacob_gladish/PerforceDotNet/... | ||
//guest/jacob_gladish/PerforceDotNet/p4dn/ClientApi_m.cpp | |||||
#1 | 3787 | Jacob Gladish | initial code submission |