#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 | |
---|---|---|---|---|---|
#4 | 5830 | Shawn Hladky | P4.Net: reorg to support release branches | ||
#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 |