/******************************************************************************* 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 CONTR IBUTORS "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. *******************************************************************************/ /******************************************************************************* * Name : php_clientapi.h * * Author : Tony Smith <tony@perforce.com> or <tony@smee.org> * * Description : Php bindings for the Perforce API. Definitions of our * main interface to Perforce * ******************************************************************************/ /******************************************************************************* * PhpClientApi class - where we register our Php classes and plumb together * the components ******************************************************************************/ class PhpClientApi { public: PhpClientApi(); ~PhpClientApi(); // Protocol options. Call before Connect() void Tagged(); void ParseForms(); void SetCharset( const char *c ) { client.SetCharset( c ); } void SetClient( const char *c ) { client.SetClient( c ); } void SetCwd( const char *c ) { client.SetCwd( c ); } void SetHost( const char *h ) { client.SetHost( h ); } void SetLanguage( const char *l ) { client.SetLanguage( l ); } void SetPassword( const char *p ) { client.SetPassword( p ); } void SetPort( const char *p ) { client.SetPort( p ); } void SetProg( const char *p ); void SetUser( const char *u ) { client.SetUser( u ); } const StrPtr &GetCharset() { return client.GetCharset(); } const StrPtr &GetClient() { return client.GetClient(); } const StrPtr &GetCwd() { return client.GetCwd(); } const StrPtr &GetHost() { return client.GetHost(); } const StrPtr &GetLanguage() { return client.GetLanguage(); } const StrPtr &GetOs() { return client.GetOs(); } const StrPtr &GetPassword() { return client.GetPassword(); } const StrPtr &GetPort() { return client.GetPort(); } const StrPtr &GetUser() { return client.GetUser(); } // Session management int Connect(); int Disconnect(); int Dropped(); // Executing commands. zval* Run( const char *cmd, int argc, char * const *argv ); void SetInput( zval * input ); // Result handling zval* GetOutput() { return ui.GetResults().GetOutput();} zval* GetErrors() { return ui.GetResults().GetErrors();} zval* GetWarnings() { return ui.GetResults().GetWarnings();} // Spec parsing zval* ParseSpec( const char * type, const char *form ); // // Debugging support. Debug levels are: // // 1: Debugs commands being executed // 2: Debug UI method calls // 3: Show garbage collection // void SetDebug( int d ); private: void RunCmd(const char *cmd, ClientUser *ui, int argc, char * const *argv); StrPtr * FetchSpecDef( const char *type ); void ReportError( Error *e ); void ReportError( const char *msg ); public: ClientApi client; private: PhpClientUser ui; StrBufDict specDict; int initCount; int debug; int server2; int mode; };
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 4627 | Tony Smith |
Rework Jon Parise's PHP interface to work like P4Perl and P4Ruby, mostly. It's pretty close, but lacking method autoloading so the only way to run commands is through the Run() method. This should be considered early beta quality at the moment, Jon will be pulling the bits he likes back into his part of the depot after he's reviewed it. |
||
//guest/tony_smith/perforce/API/Ruby/main/p4clientapi.h | |||||
#13 | 4589 | Tony Smith |
Update P4Ruby to support the new SetProg() method in the 2004.2 API. Whilst the new 'P4#prog=' method is always available, it's only functional if P4Ruby is built with a 2004.2 or later API. The build system got a bit of tidying up to support this change and the API version is now detected automatically if possible. I've also removed the --apilibdir and --apiincludedir flags as they complicate matters and I never use them and I don't believe anyone else does either. There are also some minor doc formatting tweaks to go along with the added documentation for prog=. |
||
#12 | 4261 | Tony Smith |
Add support for parsing arbitrary specs from strings in Ruby space. Useful with spec depots. You might obtain the spec by running a "p4 print -q" against a file in a spec depot, but want to parse it into a Ruby hash. i.e. p4 = P4.new p4.parse_forms # Required! p4.connect buf = p4.run_print( "-q", "//specs/client/myclient" ) spec = p4.parse_client( buf ) # Or equivalently spec = p4.parse_spec( "client", buf ) |
||
#11 | 4157 | Tony Smith |
Copyright notice update. No functional change |
||
#10 | 1869 | Tony Smith |
Build in workaround for 2000.[12] protocol bug with "p4 client -o" in tagged mode so script writers don't have to think about it |
||
#9 | 1426 | Tony Smith |
Cleaned up the debug output a little. Introduced some debug levels so you can decide (roughly) what output you want to see. Level 1 shows command execution, connect and disconnect. Level 2 includes Level 1 and also shows the RPC callbacks as they happen. Level 3 includes 1 and 2 and also shows when Ruby garbage collection takes place. Converted all the simple methods of the form P4#meth( arg ) to aliases for P4#meth=. Added P4#debug= to complete the scheme. The P4#meth( arg ) forms are now deprecated. i.e. you should use: p4.user = "tony" and not: p4.user( "tony" ) It's just more Ruby-like. |
||
#8 | 1391 | Tony Smith |
Bug fix. Garbage collection can apparently run at any time (i.e. when you're in C space and not just when you're in Ruby space) and it was occasionally running in between adjacent "delete" and "new" statements when the result set was being reset. This change removes this race condition by making the result member of ClientUserRuby a permanently instantiated variable and extending the P4Result class so that it can reset itself in a way that GC respects. Now the only dynamically allocated C++ object is the top level P4ClientApi object. No functional change. |
||
#7 | 1275 | Tony Smith |
Added synonym methods for: p4.cwd / p4.cwd= p4.client / p4.client= p4.host / p4.host= p4.password / p4.password= p4.port / p4.port= p4.user / p4.user= And for exceptions: p4.exception_level / p4.exception_level= and p4.exception_level? so you can test the current exception level p4.exception_level and p4.exception_level= now return the exception level rather than true. |
||
#6 | 1166 | Tony Smith |
Followup to previous change. Simplify the interface to getting results/errors and warnings. No need for the P4Result class anymore so that's gone (though it's still there as a C++ class because it's useful) and so is P4#result. Now you get your errors/warnings and results using P4#errors, P4#warnings and P4#output all of which return arrays. |
||
#5 | 1165 | Tony Smith |
Minor reshuffle. Added the ability to disable exceptions completely if you don't like them or to have them raised only for errors (and not for warnings). Removed P4#warnings interface and replaced it with P4#exception_level. Some minor doc tweaks to go with the above change |
||
#4 | 1164 | Tony Smith |
Reworked exception handling (hopefully for the last time) in P4/Ruby. Now exceptions are raised on completion of Perforce commands if any errors or warnings were received as part of executing the command. This change also adds documentation, and indexes the Ruby interface off my main page. Bad form to combine so many changes in one changelist, but it's getting late and I want to get them submitted! |
||
#3 | 1083 | Tony Smith |
Sweeping change to exception handling and garbage collection. Exceptions are no longer raised for errors encoutered during execution of Perforce commands as that was causing processing to abort at the first error when several success messages may have been close behind. Now exceptions are raised for events which are fatal to the execution of commands - such as failure to connect to the Perforce server for example. For other errors, the user must call "p4.errors? " to determine whether or not errors occured and "p4.errors" to get an array of error messages. You can of course then raise exceptions yourself if you want to: begin client = p4.fetch_client if p4.errors? raise P4Exception, "p4 client -o failed" end rescue P4Exception => m puts( m ) p4.errors.each { |e| puts( e ) } end version.h got renamed because it conflicts with ruby's own version.h file. We may need to look in there at some point for ruby's version so I'm getting it out of the way now. Added gc_hack.h to make sure that GC works properly on all platforms now so Ruby shouldn't nuke any objects we're holding now. |
||
#2 | 1081 | Tony Smith |
Debugging and identification support. Adds two new methods: P4#identify() P4#debug( int ) |
||
#1 | 1015 | Tony Smith |
First cut of Perforce bindings for the Ruby scripting language. Similar functionality to the Perl API stuff, but "rubyfied". Supports error reporting via exceptions, and presents tagged output and parsed forms as hash structures, with nested arrays where required. Still early days so the docs are thin on the ground. See the example.pl for a brief guide. Built with Ruby 1.6.4 on Linux. May still be some memory management issues as the Ruby Garbage Collection API has changed a little since the docs I've got and I've just dodged garbage collection for now. Not indexing this just yet. |