/******************************************************************************* Copyright (c) 1997-2004, Perforce Software, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL PERFORCE SOFTWARE, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *******************************************************************************/ /* * Include math.h here because it's included by some Perl headers and on * Win32 it must be included with C++ linkage. Including it here prevents it * from being reincluded later when we include the Perl headers with C linkage. */ #ifdef OS_NT # include <math.h> #endif #include "clientapi.h" #include "debug.h" /* When including Perl headers, make sure the linkage is C, not C++ */ extern "C" { #include "EXTERN.h" #include "perl.h" #include "XSUB.h" } #ifdef Error // Defined by older versions of Perl to be Perl_Error # undef Error #endif #include "p4result.h" #include "perlclientuser.h" #include "perlclientapi.h" PerlClientApi::PerlClientApi() { client = new ClientApi; ui = new PerlClientUser(); initCount = 0; debugLevel = 0; compatFlags = 0; } PerlClientApi::~PerlClientApi() { Disconnect(); delete ui; } SV * PerlClientApi::Connect() { Error e; if( initCount ) return newSViv( 1 ); client->Init( &e ); if( !e.Test() ) { initCount++; ui->HandleError( &e ); } return newSViv( initCount ); } SV * PerlClientApi::Disconnect() { if( !initCount ) return newSViv( 1 ); Error e; client->Final( &e ); initCount--; if( e.Test() ) ui->HandleError( &e ); return newSViv( !e.Test() ); } SV * PerlClientApi::Dropped() { return newSViv( client->Dropped() ); } void PerlClientApi::SetInput( SV *i ) { ui->SetInput( i ); } void PerlClientApi::SetProg( const char *c ) { #if P4API_VERSION >= 513026 // SetProg first introduced in 2004.2. [ 513026 = ( 2004 << 8 | 2 ) ] client->SetProg( c ); #endif } SV * PerlClientApi::GetClient() { const StrPtr &c = client->GetClient(); return newSVpv( c.Text(), c.Length() ); } SV * PerlClientApi::GetCwd() { const StrPtr &c = client->GetCwd(); return newSVpv( c.Text(), c.Length() ); } SV * PerlClientApi::GetHost() { const StrPtr &c = client->GetHost(); return newSVpv( c.Text(), c.Length() ); } SV * PerlClientApi::GetLanguage() { const StrPtr &c = client->GetLanguage(); return newSVpv( c.Text(), c.Length() ); } SV * PerlClientApi::GetPassword() { const StrPtr &c = client->GetPassword(); return newSVpv( c.Text(), c.Length() ); } SV * PerlClientApi::GetPort() { const StrPtr &c = client->GetPort(); return newSVpv( c.Text(), c.Length() ); } SV * PerlClientApi::GetCharset() { const StrPtr &c = client->GetCharset(); return newSVpv( c.Text(), c.Length() ); } SV * PerlClientApi::GetUser() { const StrPtr &c = client->GetUser(); return newSVpv( c.Text(), c.Length() ); } void PerlClientApi::SetProtocol( const char *p, const char *v ) { client->SetProtocol( p, v ); } StrPtr * PerlClientApi::GetProtocol( const char *v ) { return client->GetProtocol( v ); } SV * PerlClientApi::MergeErrors( int merge ) { switch( merge ) { case 0: printf( "Disabling merge\n" ); compatFlags &= ~CPT_MERGED; break; case 1: printf( "Enabling merge\n" ); compatFlags |= CPT_MERGED; break; } printf( "Merge is %s\n",compatFlags & CPT_MERGED ? "enabled" : "disabled"); return newSViv( compatFlags & CPT_MERGED ); } SV * PerlClientApi::GetFirstOutput() { AV * output = ui->GetResults().GetOutput(); SV **s = av_fetch( output, 0, 0 ); return s ? *s : 0; } AV * PerlClientApi::GetOutput() { return ui->GetResults().GetOutput(); } AV * PerlClientApi::GetWarnings() { return ui->GetResults().GetWarnings(); } AV * PerlClientApi::GetErrors() { return ui->GetResults().GetErrors(); } I32 PerlClientApi::GetOutputCount() { return ui->GetResults().OutputCount(); } I32 PerlClientApi::GetWarningCount() { return ui->GetResults().WarningCount(); } I32 PerlClientApi::GetErrorCount() { return ui->GetResults().ErrorCount(); } void PerlClientApi::SetDebugLevel( int l ) { debugLevel = l; ui->SetDebugLevel( l ); } SV * PerlClientApi::Run( const char *cmd, int argc, char * const *argv ) { ui->Reset( compatFlags & CPT_MERGED ); if( argc ) client->SetArgv( argc, argv ); client->Run( cmd, ui ); return newRV( (SV*) GetOutput() ); }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#2 | 4672 | Raymond Danks |
Add support for Internationalized Perforce Servers. Specifically, add GetCharset, SetCharset, and SetTrans. |
||
#1 | 4669 | Raymond Danks | Create a branch of P4-3.4608. | ||
//guest/tony_smith/perforce/API/Perl/P4/lib/perlclientapi.cc | |||||
#4 | 4608 | Tony Smith |
Bug fix: The SetInput() method was omitted in the big rewrite so quite a lot was broken in builds 3.4579 and later. This change fixes that omission, and adds support for 'p4 login' too (that was how I discovered that SetInput() was missing). |
||
#3 | 4585 | Tony Smith |
Make the new P4Perl work with older versions of the Perforce API (i.e those without ClientApi::SetProg() defined ). This also introduces automatic determination of the API version being used so we can selectively exclude functionality that isn't available. No functional change. |
||
#2 | 4582 | Tony Smith |
Port new P4Perl architecture to Windows. Fixes a few porting issues and a couple of minor errors in the previous change. |
||
#1 | 4579 | Tony Smith |
Rewrite P4Perl to be more like P4Ruby. This change does away with the old P4/P4::Client split and pulls all the functionality of P4::Client into P4. Hence P4::Client is now deprecated. There are a few gotcha's - see the Changes file, and documentation for the details, but in general it's backwards compatible. As part of this change, I'm also releasing the previous current versions of P4 and P4::Client as released versions - for posterity. P4 now gets a v3.x version number so the old versions will stand out clearly. Hopefully it's all working - works fine for me - but people should consider this a beta build, for now at least. |