/******************************************************************************* Copyright (c) 2010, 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. *******************************************************************************/ /******************************************************************************* * Name : p4bridge-api.cc * * Author : dbb * * Description : A "Flat C" interface for the Perforce API. Used to provide * simple access for C#.NET using P/Invoke and dllimport. * ******************************************************************************/ #include "stdafx.h" #include "P4BridgeServer.h" // If there is a connection error, keep it so the client can fetch it later P4ClientError * connectionError = NULL; /****************************************************************************** * Helper function to (re)connect to the server and determine if it is Unicode * enabled. ******************************************************************************/ int ServerConnect(P4BridgeServer* pServer) { // dereference old error string, if any. It's not 'our' string, so we can't // free it. if (connectionError) { delete connectionError; connectionError = NULL; } //Connect to the server and // See if the api returns an error. if( !pServer->connected( &connectionError ) ) { // Abort if the connect did not succeed return 0; } if ( pServer && pServer->get_ui( ) ) { // Check if the server is Unicode enabled if ( pServer->unicodeServer( ) ) { pServer->get_ui()->UseUnicode(1); } else { pServer->get_ui()->UseUnicode(0); } // reinitialize the callbacks pServer->get_ui()->SetTaggedOutputCallbackFn( pServer->pTaggedOutputCallbackFn ); pServer->get_ui()->SetErrorCallbackFn( pServer->pErrorCallbackFn ); pServer->get_ui()->SetInfoResultsCallbackFn( pServer->pInfoResultsCallbackFn ); pServer->get_ui()->SetTextResultsCallbackFn( pServer->pTextResultsCallbackFn ); pServer->get_ui()->SetBinaryResultsCallbackFn( pServer->pBinaryResultsCallbackFn ); pServer->get_ui()->SetPromptCallbackFn( pServer->pPromptCallbackFn ); pServer->get_ui()->SetResolveCallbackFn( pServer->pResolveCallbackFn ); pServer->get_ui()->SetResolveACallbackFn( pServer->pResolveACallbackFn ); } return 1; } /****************************************************************************** * Helper function to (re)connect to the server and determine if it is Unicode * enabled. ******************************************************************************/ int ServerConnectTrust(P4BridgeServer* pServer, char* trust_flag, char* fingerprint) { // dereference old error string, if any. It's not 'our' string, so we can't // free it. if (connectionError) { delete connectionError; connectionError = NULL; } //Connect to the server and // See if the api returns an error. if( !pServer->connect_and_trust( &connectionError, trust_flag, fingerprint ) ) { // Abort if the connect did not succeed return 0; } if ( pServer && pServer->get_ui( ) ) { // Check if the server is Unicode enabled if ( pServer->unicodeServer( ) ) { pServer->get_ui()->UseUnicode(1); } else { pServer->get_ui()->UseUnicode(0); } // reinitialize the callbacks pServer->get_ui()->SetTaggedOutputCallbackFn( pServer->pTaggedOutputCallbackFn ); pServer->get_ui()->SetErrorCallbackFn( pServer->pErrorCallbackFn ); pServer->get_ui()->SetInfoResultsCallbackFn( pServer->pInfoResultsCallbackFn ); pServer->get_ui()->SetTextResultsCallbackFn( pServer->pTextResultsCallbackFn ); pServer->get_ui()->SetBinaryResultsCallbackFn( pServer->pBinaryResultsCallbackFn ); pServer->get_ui()->SetPromptCallbackFn( pServer->pPromptCallbackFn ); pServer->get_ui()->SetResolveCallbackFn( pServer->pResolveCallbackFn ); pServer->get_ui()->SetResolveACallbackFn( pServer->pResolveACallbackFn ); } return 1; } /****************************************************************************** * 'Flat' C interface for the dll. This interface will be imported into C# * using P/Invoke ******************************************************************************/ extern "C" { /************************************************************************** * * P4BridgeServer functions * * These are the functions that use a P4BridgeServer* to access an object * created in the dll. * **************************************************************************/ /************************************************************************** * * Connect: Connect to the a Perforce server and create a new * P4BridgeServer to access the server. * * Returns: Pointer to the new P4BridgeServer, NULL if there is an error. * * NOTE: Call CloseConnection() on the returned pointer to free the object * **************************************************************************/ __declspec(dllexport) P4BridgeServer* Connect( const char *server, const char *user, const char *pass, const char *ws_client, LogCallbackFn *log_fn) { //Connect to the server P4BridgeServer* pServer = new P4BridgeServer( server, user, pass, ws_client); P4BridgeServer::SetLogCallFn(log_fn); if (ServerConnect( pServer ) ) { return pServer; } return NULL; } /************************************************************************** * * TrustedConnect: Connect to the a Perforce server and create a new * P4BridgeServer to access the server, and establish (or reestablish) * a trust relationship based on the servers certificate fingerprint. * * Returns: Pointer to the new P4BridgeServer, NULL if there is an error. * * NOTE: Call CloseConnection() on the returned pointer to free the object * **************************************************************************/ __declspec(dllexport) P4BridgeServer* TrustedConnect( const char *server, const char *user, const char *pass, const char *ws_client, char *trust_flag, char *fingerprint, LogCallbackFn *log_fn) { //Connect to the server P4BridgeServer* pServer = new P4BridgeServer( server, user, pass, ws_client); P4BridgeServer::SetLogCallFn(log_fn); if (ServerConnectTrust( pServer, trust_flag, fingerprint ) ) { return pServer; } return NULL; } /************************************************************************** * * GetConnectionError: Returns the text of a the error message * generated by the connection attempt, if any. * **************************************************************************/ __declspec(dllexport) P4ClientError * GetConnectionError( void ) { return connectionError; } /************************************************************************** * * CloseConnection: Closes the connection and deletes the P4BridgeServer * object. * * pServer: Pointer to the P4BridgeServer * **************************************************************************/ __declspec(dllexport) void CloseConnection( P4BridgeServer* pServer ) { VALIDATE_HANDLE_V(pServer, tP4BridgeServer) pServer->pTaggedOutputCallbackFn = NULL; pServer->pErrorCallbackFn = NULL; pServer->pInfoResultsCallbackFn = NULL; pServer->pTextResultsCallbackFn = NULL; pServer->pBinaryResultsCallbackFn = NULL; pServer->pPromptCallbackFn = NULL; pServer->pResolveCallbackFn = NULL; pServer->pResolveACallbackFn = NULL; if (pServer->get_ui()) { pServer->get_ui()->SetTaggedOutputCallbackFn(NULL); pServer->get_ui()->SetErrorCallbackFn(NULL); pServer->get_ui()->SetInfoResultsCallbackFn(NULL); pServer->get_ui()->SetTextResultsCallbackFn( NULL ); pServer->get_ui()->SetBinaryResultsCallbackFn( NULL ); pServer->get_ui()->SetPromptCallbackFn( NULL ); pServer->get_ui()->SetResolveCallbackFn( NULL ); pServer->get_ui()->SetResolveACallbackFn( NULL ); } delete pServer; } /************************************************************************** * * Disconnect: Disconnect from the server after running one or more * commands. * * pServer: Pointer to the P4BridgeServer * **************************************************************************/ __declspec(dllexport) void Disconnect( P4BridgeServer* pServer ) { VALIDATE_HANDLE_V(pServer, tP4BridgeServer) pServer->disconnect(); } /************************************************************************** * * IsUnicode: Check if the server supports Unicode * * Note: Is set during connection so is valid immediately after Connect() * successfully completes. * **************************************************************************/ __declspec(dllexport) int IsUnicode( P4BridgeServer* pServer ) { VALIDATE_HANDLE_B(pServer, tP4BridgeServer) return pServer->unicodeServer(); } /************************************************************************** * * APILevel: Get the API level supported by the server * * Note: Is set during connection so is valid immediately after Connect() * successfully completes. * **************************************************************************/ __declspec(dllexport) int APILevel( P4BridgeServer* pServer ) { VALIDATE_HANDLE_B(pServer, tP4BridgeServer) return pServer->APILevel(); } /************************************************************************** * * UseLogin: Check if the server requires the Login command be used * * Note: Is set during connection so is valid immediately after Connect() * successfully completes. * **************************************************************************/ __declspec(dllexport) int UseLogin( P4BridgeServer* pServer ) { VALIDATE_HANDLE_B(pServer, tP4BridgeServer) return pServer->UseLogin(); } /************************************************************************** * * SupportsExtSubmit: Check if the server support extended submit options * (2006.2 higher)? * * Note: Is set during connection so is valid immediately after Connect() * successfully completes. * **************************************************************************/ __declspec(dllexport) int SupportsExtSubmit( P4BridgeServer* pServer ) { VALIDATE_HANDLE_B(pServer, tP4BridgeServer) return pServer->SupportsExtSubmit(); } /************************************************************************** * * IsUnicode: Check if the server supports Unicode * * pServer: Pointer to the P4BridgeServer * * pCharSet: String name for the character set to use for command * data passed to/from the server. * * pFileCharSet: String name for the character set to use for the * contents of type Unicode file when stored in the * a file on the client's disk. * * Note: Needs to be called before any command which takes parameters is * called. * **************************************************************************/ __declspec(dllexport) char * SetCharacterSet( P4BridgeServer* pServer, const char * pCharSet, const char * pFileCharSet ) { VALIDATE_HANDLE_P(pServer, tP4BridgeServer) return pServer->set_charset( pCharSet, pFileCharSet ); } /************************************************************************** * * set_connection: Set the connection parameters. * * pServer: Pointer to the P4BridgeServer * * newPort: New port * newUser: New workspace * newPassword: New password * newClient: New workspace * * Return: None **************************************************************************/ __declspec(dllexport) void set_connection( P4BridgeServer* pServer, const char* newPort, const char* newUser, const char* newPassword, const char* newClient ) { VALIDATE_HANDLE_V(pServer, tP4BridgeServer) return pServer->set_connection(newPort, newUser, newPassword, newClient); } /************************************************************************** * * set_client: Set the client workspace. * * pServer: Pointer to the P4BridgeServer * * pNew: New workspace * * Return: None **************************************************************************/ __declspec(dllexport) void set_client( P4BridgeServer* pServer, const char* workspace ) { VALIDATE_HANDLE_V(pServer, tP4BridgeServer) return pServer->set_client(workspace); } /************************************************************************** * * get_client: Get the name of the current client workspace. * * pServer: Pointer to the P4BridgeServer * * Return: Pointer to access the data. * **************************************************************************/ __declspec(dllexport) const char * get_client( P4BridgeServer* pServer ) { VALIDATE_HANDLE_P(pServer, tP4BridgeServer) if (!pServer->get_client()) return NULL; return pServer->get_client()->Text(); } /************************************************************************** * * get_user: Get the user name for the current connection. * * pServer: Pointer to the P4BridgeServer * * Return: Pointer access the data. * **************************************************************************/ __declspec(dllexport) char * get_user( P4BridgeServer* pServer ) { VALIDATE_HANDLE_P(pServer, tP4BridgeServer) if (!pServer->get_user()) return NULL; return pServer->get_user()->Text(); } /************************************************************************** * * set_user: Set the user name for the connection. * * pServer: Pointer to the P4BridgeServer * newValue: The new value * * Return: Pointer access the data. * **************************************************************************/ __declspec(dllexport) void set_user( P4BridgeServer* pServer, char * newValue ) { VALIDATE_HANDLE_V(pServer, tP4BridgeServer) pServer->set_user(newValue); } /************************************************************************** * * get_port: Get the port for the current connection. * * pServer: Pointer to the P4BridgeServer * * Return: Pointer to access the data. * **************************************************************************/ __declspec(dllexport) char * get_port( P4BridgeServer* pServer ) { VALIDATE_HANDLE_P(pServer, tP4BridgeServer) if (!pServer->get_port()) return NULL; return pServer->get_port()->Text(); } /************************************************************************** * * set_port: Set the port for the connection. * * pServer: Pointer to the P4BridgeServer * newValue: The new value * * Return: Pointer to access the data. * **************************************************************************/ __declspec(dllexport) void set_port( P4BridgeServer* pServer, char * newValue ) { VALIDATE_HANDLE_V(pServer, tP4BridgeServer) pServer->set_port(newValue); } /************************************************************************** * * get_password: Get the password for the current connection. * * pServer: Pointer to the P4BridgeServer * * Return: Pointer to access the data. * **************************************************************************/ __declspec(dllexport) char * get_password( P4BridgeServer* pServer ) { VALIDATE_HANDLE_P(pServer, tP4BridgeServer) if (!pServer->get_password()) return NULL; return pServer->get_password()->Text(); } /************************************************************************** * * set_password: Set the password for the connection. * * pServer: Pointer to the P4BridgeServer * newValue: The new value * * Return: Pointer to access the data. * **************************************************************************/ __declspec(dllexport) void set_password( P4BridgeServer* pServer, char * newValue ) { VALIDATE_HANDLE_V(pServer, tP4BridgeServer) pServer->set_password(newValue); } /************************************************************************** * * GetCwd: Gets the current working directory for the P4BridgeServer. * * pServer: Pointer to the P4BridgeServer * **************************************************************************/ __declspec(dllexport) char * get_cwd( P4BridgeServer* pServer ) { VALIDATE_HANDLE_P(pServer, tP4BridgeServer) return pServer->get_cwd().Text(); } /************************************************************************** * * SetCwd: Sets the current working directory for the P4BridgeServer. * * pServer: Pointer to the P4BridgeServer * * new_val: Path to the new current working directory * **************************************************************************/ __declspec(dllexport) void set_cwd( P4BridgeServer* pServer, const char * new_val ) { VALIDATE_HANDLE_V(pServer, tP4BridgeServer) pServer->set_cwd((const char *) new_val); } /************************************************************************** * * get_programName: Get the program name to use for the connection. * * pServer: Pointer to the P4BridgeServer * * Return: Pointer to access the data. * **************************************************************************/ __declspec(dllexport) const char * get_programName( P4BridgeServer* pServer ) { VALIDATE_HANDLE_P(pServer, tP4BridgeServer) return pServer->get_programName(); } /************************************************************************** * * set_programName: Set the program name to use for the connection. * * pServer: Pointer to the P4BridgeServer * newValue: The new value * * Return: Pointer to access the data. * **************************************************************************/ __declspec(dllexport) void set_programName( P4BridgeServer* pServer, char * newValue ) { VALIDATE_HANDLE_V(pServer, tP4BridgeServer) pServer->set_programName(newValue); } /************************************************************************** * * get_programVer: Get the program version to use for the connection. * * pServer: Pointer to the P4BridgeServer * * Return: Pointer to access the data. * **************************************************************************/ __declspec(dllexport) const char * get_programVer( P4BridgeServer* pServer ) { VALIDATE_HANDLE_P(pServer, tP4BridgeServer) return pServer->get_programVer(); } /************************************************************************** * * set_programVer: Set the program version to use for the connection. * * pServer: Pointer to the P4BridgeServer * newValue: The new value * * Return: Pointer to access the data. * **************************************************************************/ __declspec(dllexport) void set_programVer( P4BridgeServer* pServer, char * newValue ) { VALIDATE_HANDLE_V(pServer, tP4BridgeServer) pServer->set_programVer(newValue); } /************************************************************************** * * get_charset: Get the character to use for the connection. * * pServer: Pointer to the P4BridgeServer * * Return: Pointer to access the data. * **************************************************************************/ __declspec(dllexport) const char * get_charset( P4BridgeServer* pServer ) { VALIDATE_HANDLE_P(pServer, tP4BridgeServer) return pServer->get_charset()->Text(); } /************************************************************************** * * get_config: Get the config file for the current connection, if any. * * pServer: Pointer to the P4BridgeServer * * Return: Pointer to access the data. * **************************************************************************/ __declspec(dllexport) char * get_config( P4BridgeServer* pServer ) { VALIDATE_HANDLE_P(pServer, tP4BridgeServer) if (!pServer->get_config()) return NULL; return pServer->get_config()->Text(); } /************************************************************************** * * RunCommand: Run a command using the P4BridgeServer. * * pServer: Pointer to the P4BridgeServer * * cmd: Command name, i.e 'fstst'. These are always in ASCII, regardless * of whether or not the server is Unicode enabled. * * tagged: If non zero, run the command using tagged protocol * * args: list of arguments. For non Unicode servers, these are ASCII * encode strings. For Unicode servers they should be encoded in * using the encoding specified in a previous call to * SetCharacterSet(). * * argc: count of arguments * * Return: Zero if there was an error running the command **************************************************************************/ __declspec(dllexport) int RunCommand( P4BridgeServer* pServer, const char *cmd, int tagged, char **args, int argc ) { VALIDATE_HANDLE_I(pServer, tP4BridgeServer) // make sure we're connected to the server if (0 == ServerConnect( pServer )) { return 0; } return pServer->run_command(cmd, tagged, args, argc); } /************************************************************************** * * CancelCommand: Cancel a running command * * Return: None **************************************************************************/ __declspec(dllexport) void CancelCommand( P4BridgeServer* pServer ) { VALIDATE_HANDLE_V(pServer, tP4BridgeServer) pServer->cancel_command(); } /************************************************************************** * * SetTaggedOutputCallbackFn: Set the tagged output callback fn. * * pServer: Pointer to the P4BridgeServer * * pNew: New function pointer * * Return: None **************************************************************************/ __declspec(dllexport) void SetTaggedOutputCallbackFn( P4BridgeServer* pServer, IntTextTextCallbackFn* pNew ) { VALIDATE_HANDLE_V(pServer, tP4BridgeServer) pServer->pTaggedOutputCallbackFn = pNew; if (!pServer->get_ui()) return; pServer->get_ui()->SetTaggedOutputCallbackFn(pNew); } /************************************************************************** * * StrDictListIterator: Get a StrDictListIterator to iterate through * the tagged output. * * pServer: Pointer to the P4BridgeServer * * Return: Pointer to a new StrDictListIterator to access the data. * * NOTE: Call Release() on the returned pointer to free the object * **************************************************************************/ __declspec(dllexport) StrDictListIterator * GetTaggedOutput( P4BridgeServer* pServer ) { VALIDATE_HANDLE_P(pServer, tP4BridgeServer) if (!pServer->get_ui()) return NULL; return pServer->get_ui()->GetTaggedOutput(); } /************************************************************************** * * SetErrorCallbackFn: Set the error output callback fn. * * pServer: Pointer to the P4BridgeServer * * pNew: New function pointer * * Return: None **************************************************************************/ __declspec(dllexport) void SetErrorCallbackFn( P4BridgeServer* pServer, IntTextCallbackFn* pNew ) { VALIDATE_HANDLE_V(pServer, tP4BridgeServer) pServer->pErrorCallbackFn = pNew; if (!pServer->get_ui()) return; pServer->get_ui()->SetErrorCallbackFn(pNew); } /************************************************************************** * * GetErrorResults: Get the error output. * * pServer: Pointer to the P4BridgeServer * * Return: Pointer to the data. * **************************************************************************/ __declspec(dllexport) P4ClientError * GetErrorResults( P4BridgeServer * pServer) { VALIDATE_HANDLE_P(pServer, tP4BridgeServer) if ((!pServer->get_ui()) || (!pServer->get_ui()->GetErrorResults())) return NULL; return pServer->get_ui()->GetErrorResults(); } /************************************************************************** * * SetInfoResultsCallbackFn: Set the info output callback fn. * * pServer: Pointer to the P4BridgeServer * * pNew: New function pointer * * Return: None **************************************************************************/ __declspec(dllexport) void SetInfoResultsCallbackFn( P4BridgeServer* pServer, IntTextCallbackFn* pNew ) { VALIDATE_HANDLE_V(pServer, tP4BridgeServer) pServer->pInfoResultsCallbackFn = pNew; if (!pServer->get_ui()) return; pServer->get_ui()->SetInfoResultsCallbackFn(pNew); } /************************************************************************** * * GetInfoResults: Get the info output. * * pServer: Pointer to the P4BridgeServer * * Return: Pointer to access the data. * **************************************************************************/ __declspec(dllexport) char * GetInfoResults( P4BridgeServer* pServer) { VALIDATE_HANDLE_P(pServer, tP4BridgeServer) if (!pServer->get_ui()->GetInfoResults()) return NULL; return pServer->get_ui()->GetInfoResults()->Text(); } /************************************************************************** * * SetTextResultsCallbackFn: Set the text output callback fn. * * pServer: Pointer to the P4BridgeServer * * pNew: New function pointer * * Return: None **************************************************************************/ __declspec(dllexport) void SetTextResultsCallbackFn( P4BridgeServer* pServer, TextCallbackFn* pNew ) { VALIDATE_HANDLE_V(pServer, tP4BridgeServer) pServer->pTextResultsCallbackFn = pNew; if (!pServer->get_ui()) return; pServer->get_ui()->SetTextResultsCallbackFn(pNew); } /************************************************************************** * * GetTextResults: Get the text output. * * pServer: Pointer to the P4BridgeServer * * Return: Pointer to the data. * **************************************************************************/ __declspec(dllexport) char * GetTextResults( P4BridgeServer* pServer ) { VALIDATE_HANDLE_P(pServer, tP4BridgeServer) if (!pServer->get_ui()->GetTextResults()) return NULL; return pServer->get_ui()->GetTextResults()->Text(); } /************************************************************************** * * SetBinaryResultsCallbackFn: Set the callback for binary output. * * pServer: Pointer to the P4BridgeServer * * pNew: The new callback function pointer * * Return: None **************************************************************************/ __declspec(dllexport) void SetBinaryResultsCallbackFn( P4BridgeServer* pServer, BinaryCallbackFn* pNew ) { VALIDATE_HANDLE_V(pServer, tP4BridgeServer) pServer->pBinaryResultsCallbackFn = pNew; if (!pServer->get_ui()) return; pServer->get_ui()->SetBinaryResultsCallbackFn( pNew ); } /************************************************************************** * * GetBinaryResultsCount: Get the size in bytes of the binary output. * * pServer: Pointer to the P4BridgeServer * * Return: Byte count for the data. * **************************************************************************/ __declspec(dllexport) int GetBinaryResultsCount( P4BridgeServer* pServer ) { VALIDATE_HANDLE_I(pServer, tP4BridgeServer) if (!pServer->get_ui()) return 0; return pServer->get_ui()->GetBinaryResultsCount( ); } /************************************************************************** * * GetBinaryResults: Get the binary output. * * pServer: Pointer to the P4BridgeServer * * Return: Pointer to the data. * **************************************************************************/ __declspec(dllexport) void *GetBinaryResults( P4BridgeServer* pServer ) { VALIDATE_HANDLE_P(pServer, tP4BridgeServer) if (!pServer->get_ui()) return NULL; return pServer->get_ui()->GetBinaryResults( ); } /************************************************************************** * * SetTextResults: Set the Data Set in the UI (P4Client). * * pServer: Pointer to the P4BridgeServer * * data: String Pointer to the data * * Return: Pointer to char * for the data. * **************************************************************************/ __declspec(dllexport) void SetDataSet( P4BridgeServer* pServer, const char * data ) { VALIDATE_HANDLE_V(pServer, tP4BridgeServer) if (!pServer->get_ui()) return; return pServer->get_ui()->SetDataSet(data); } /************************************************************************** * * GetDataSet: Get the Data Set in the UI (P4Client). * * pServer: Pointer to the P4BridgeServer * * Return: Pointer to a new char * to access the data. * **************************************************************************/ __declspec(dllexport) char * GetDataSet( P4BridgeServer* pServer ) { VALIDATE_HANDLE_P(pServer, tP4BridgeServer) if (!pServer->get_ui()->GetDataSet()) return NULL; return pServer->get_ui()->GetDataSet()->Text(); } /************************************************************************** * * SetPromptCallbackFn: Set the callback for replying to a server prompt. * * pServer: Pointer to the P4BridgeServer * * pNew: The new callback function pointer * * Return: None **************************************************************************/ __declspec(dllexport) void SetPromptCallbackFn( P4BridgeServer* pServer, PromptCallbackFn* pNew ) { VALIDATE_HANDLE_V(pServer, tP4BridgeServer) pServer->pPromptCallbackFn = pNew; if (!pServer->get_ui()) return; pServer->get_ui()->SetPromptCallbackFn( pNew ); } /************************************************************************** * class StrDictListIterator * * A StrDictList is a list of items defined by StrDictionaries. Each * StrDictionary can be considered a collection of entries, key:value * pairs of string data. StrDictListIterator allows you to walk this * list of lists. * * itemList---->item1----->item2-....->itemN * ->entry1 ->entry1 ->entry1 * ->entry2 ->entry2 ->entry2 * ... ... ... * ->entryX ->entryY ->entryZ * * Basic Usage: * StrDictListIterator * pItem; * while (pItem = pIterator-GetNextItem() * { * KeyValuePair * = pEntry; * while (pEntry = pIterator-GetNextEntry() * // do something with the key:value pair, pEntry * } * * NOTE: The iterate as currently implemented, can only iterate through the * data once, as there is no method to rest it. * **************************************************************************/ /************************************************************************** * * GetNextEntry: Get the next Item in the list. Returns the first item * on the first call. * * pServer: Pointer to the P4BridgeServer * * Return: Pointer to access the data. * **************************************************************************/ __declspec(dllexport) StrDictList* GetNextItem( StrDictListIterator* pObj ) { VALIDATE_HANDLE_P(pObj, tStrDictListIterator) return pObj->GetNextItem(); } /************************************************************************** * * GetNextEntry: Get the next Entry for the current item. Returns the first * entry for the item on the first call to. * * pObj: Pointer to the iterator. * * Return: Pointer to access the data. * **************************************************************************/ __declspec(dllexport) KeyValuePair * GetNextEntry( StrDictListIterator* pObj ) { VALIDATE_HANDLE_P(pObj, tStrDictListIterator) return pObj->GetNextEntry(); } /************************************************************************** * * Release: Delete the iterator. * * pObj: Pointer to the iterator. * * Return: None. * **************************************************************************/ __declspec(dllexport) void Release( StrDictListIterator* pObj ) { VALIDATE_HANDLE_V(pObj, tStrDictListIterator) delete pObj; } /************************************************************************** * class KeyValuePair **************************************************************************/ /************************************************************************** * * GetKey: Get the key. * * pObj: Pointer to the KeyValuePair. * * Return: Pointer to access the data. * **************************************************************************/ __declspec(dllexport) const char * GetKey( KeyValuePair* pObj ) { VALIDATE_HANDLE_P(pObj, tKeyValuePair) return pObj->key; } /************************************************************************** * * GetValue: Get the value. * * pObj: Pointer to the KeyValuePair. * * Return: Pointer to access the data. * **************************************************************************/ __declspec(dllexport) const char * GetValue( KeyValuePair* pObj ) { VALIDATE_HANDLE_P(pObj, tKeyValuePair) return pObj->value; } /************************************************************************** * P4ClientError *************************************************************************/ /************************************************************************** * * GetSeverity: Get the severity. * * pObj: Pointer to the P4ClientError. * * Return: Severity of the Error. * **************************************************************************/ __declspec(dllexport) const int Severity( P4ClientError* pObj ) { VALIDATE_HANDLE_P(pObj, tP4ClientError) return pObj->Severity; } /************************************************************************** * * ErrorCode: Get the Error Code. * * pObj: Pointer to the P4ClientError. * * Return: Unique ErrorCode of the Error. * **************************************************************************/ __declspec(dllexport) const int ErrorCode( P4ClientError* pObj ) { VALIDATE_HANDLE_P(pObj, tP4ClientError) return pObj->ErrorCode; } /************************************************************************** * * GetMessage: Get the error message. * * pObj: Pointer to the P4ClientError. * * Return: Error Message. * **************************************************************************/ __declspec(dllexport) const char * Message( P4ClientError* pObj ) { VALIDATE_HANDLE_P(pObj, tP4ClientError) return pObj->Message; } /************************************************************************** * * GetNext: Get the next error message. * * pObj: Pointer to the P4ClientError. * * Return: Pointer to the next error message. * **************************************************************************/ __declspec(dllexport) P4ClientError * Next( P4ClientError * pObj ) { VALIDATE_HANDLE_P(pObj, tP4ClientError) return pObj->Next; } /************************************************************************** * * P4ClientMerge * * This simple class is a ClientMerge object. * *************************************************************************/ __declspec(dllexport) int CM_AutoResolve( P4ClientMerge* pObj, MergeForce forceMerge ) { VALIDATE_HANDLE_I(pObj, tP4ClientMerge); return (int) pObj->AutoResolve(forceMerge); } __declspec(dllexport) int CM_Resolve( P4ClientMerge* pObj ) { VALIDATE_HANDLE_I(pObj, tP4ClientMerge); return (int) pObj->Resolve(); } __declspec(dllexport) int CM_DetectResolve( P4ClientMerge* pObj ) { VALIDATE_HANDLE_I(pObj, tP4ClientMerge); return (int) pObj->DetectResolve(); } __declspec(dllexport) int CM_IsAcceptable( P4ClientMerge* pObj ) { VALIDATE_HANDLE_I(pObj, tP4ClientMerge); return pObj->IsAcceptable(); } __declspec(dllexport) char *CM_GetBaseFile( P4ClientMerge* pObj ) { VALIDATE_HANDLE_P(pObj, tP4ClientMerge) if (!pObj->GetBaseFile()) return NULL; return pObj->GetBaseFile()->Text(); } __declspec(dllexport) char *CM_GetYourFile( P4ClientMerge* pObj ) { VALIDATE_HANDLE_P(pObj, tP4ClientMerge) if (!pObj->GetYourFile()) return NULL; return pObj->GetYourFile()->Text(); } __declspec(dllexport) char *CM_GetTheirFile( P4ClientMerge* pObj ) { VALIDATE_HANDLE_P(pObj, tP4ClientMerge) if (!pObj->GetTheirFile()) return NULL; return pObj->GetTheirFile()->Text(); } __declspec(dllexport) char *CM_GetResultFile( P4ClientMerge* pObj ) { VALIDATE_HANDLE_P(pObj, tP4ClientMerge) if (!pObj->GetResultFile()) return NULL; return pObj->GetResultFile()->Text(); } __declspec(dllexport) int CM_GetYourChunks( P4ClientMerge* pObj ) { VALIDATE_HANDLE_I(pObj, tP4ClientMerge); return pObj->GetYourChunks(); } __declspec(dllexport) int CM_GetTheirChunks( P4ClientMerge* pObj ) { VALIDATE_HANDLE_I(pObj, tP4ClientMerge); return pObj->GetTheirChunks(); } __declspec(dllexport) int CM_GetBothChunks( P4ClientMerge* pObj ) { VALIDATE_HANDLE_I(pObj, tP4ClientMerge); return pObj->GetBothChunks(); } __declspec(dllexport) int CM_GetConflictChunks( P4ClientMerge* pObj ) { VALIDATE_HANDLE_I(pObj, tP4ClientMerge); return pObj->GetConflictChunks(); } __declspec(dllexport) char *CM_GetMergeDigest( P4ClientMerge* pObj ) { VALIDATE_HANDLE_P(pObj, tP4ClientMerge) if (!pObj->GetBaseFile()) return NULL; return pObj->GetMergeDigest()->Text(); } __declspec(dllexport) char *CM_GetYourDigest( P4ClientMerge* pObj ) { if (!pObj->GetBaseFile()) return NULL; return pObj->GetYourDigest()->Text(); } __declspec(dllexport) char *CM_GetTheirDigest( P4ClientMerge* pObj ) { VALIDATE_HANDLE_P(pObj, tP4ClientMerge) if (!pObj->GetBaseFile()) return NULL; return pObj->GetTheirDigest()->Text(); } __declspec(dllexport) P4ClientError *CM_GetLastClientMergeError(P4ClientMerge* pObj) { VALIDATE_HANDLE_P(pObj, tP4ClientMerge) return pObj->GetLastError(); } /******************************************************************************* * * P4ClientResolve * * This simple class is a wrapper for ClientResolve object. * ******************************************************************************/ __declspec(dllexport) int CR_AutoResolve( P4ClientResolve* pObj, MergeForce force ) { VALIDATE_HANDLE_I(pObj, tP4ClientResolve); return (int) pObj->AutoResolve(force); } __declspec(dllexport) int CR_Resolve( P4ClientResolve* pObj, int preview, Error *e ) { VALIDATE_HANDLE_I(pObj, tP4ClientResolve); return (int) pObj->Resolve(preview); } __declspec(dllexport) char *CR_GetType(P4ClientResolve* pObj) { VALIDATE_HANDLE_P(pObj, tP4ClientResolve); return pObj->GetType().Text(); } __declspec(dllexport) char *CR_GetMergeAction(P4ClientResolve* pObj) { VALIDATE_HANDLE_P(pObj, tP4ClientResolve) return pObj->GetMergeAction().Text(); } __declspec(dllexport) char *CR_GetYoursAction(P4ClientResolve* pObj) { VALIDATE_HANDLE_P(pObj, tP4ClientResolve) return pObj->GetYoursAction().Text(); } __declspec(dllexport) char *CR_GetTheirAction(P4ClientResolve* pObj) { VALIDATE_HANDLE_P(pObj, tP4ClientResolve) return pObj->GetTheirAction().Text(); } // For the CLI interface, probably not of interest to others __declspec(dllexport) char *CR_GetMergePrompt(P4ClientResolve* pObj) { VALIDATE_HANDLE_P(pObj, tP4ClientResolve) return pObj->GetMergePrompt().Text(); } __declspec(dllexport) char *CR_GetYoursPrompt(P4ClientResolve* pObj) { VALIDATE_HANDLE_P(pObj, tP4ClientResolve) return pObj->GetYoursPrompt().Text(); } __declspec(dllexport) char *CR_GetTheirPrompt(P4ClientResolve* pObj) { VALIDATE_HANDLE_P(pObj, tP4ClientResolve) return pObj->GetTheirPrompt().Text(); } __declspec(dllexport) char *CR_GetMergeOpt(P4ClientResolve* pObj) { VALIDATE_HANDLE_P(pObj, tP4ClientResolve) return pObj->GetMergeOpt().Text(); } __declspec(dllexport) char *CR_GetYoursOpt(P4ClientResolve* pObj) { VALIDATE_HANDLE_P(pObj, tP4ClientResolve) return pObj->GetYoursOpt().Text(); } __declspec(dllexport) char *CR_GetTheirOpt(P4ClientResolve* pObj) { VALIDATE_HANDLE_P(pObj, tP4ClientResolve) return pObj->GetTheirOpt().Text(); } __declspec(dllexport) char *CR_GetSkipOpt(P4ClientResolve* pObj) { VALIDATE_HANDLE_P(pObj, tP4ClientResolve) return pObj->GetSkipOpt().Text(); } __declspec(dllexport) char *CR_GetHelpOpt(P4ClientResolve* pObj) { VALIDATE_HANDLE_P(pObj, tP4ClientResolve) return pObj->GetHelpOpt().Text(); } __declspec(dllexport) char *CR_GetAutoOpt(P4ClientResolve* pObj) { VALIDATE_HANDLE_P(pObj, tP4ClientResolve) return pObj->GetAutoOpt().Text(); } __declspec(dllexport) char *CR_GetPrompt(P4ClientResolve* pObj) { VALIDATE_HANDLE_P(pObj, tP4ClientResolve) return pObj->GetPrompt().Text(); } __declspec(dllexport) char *CR_GetTypePrompt(P4ClientResolve* pObj) { VALIDATE_HANDLE_P(pObj, tP4ClientResolve) return pObj->GetTypePrompt().Text(); } __declspec(dllexport) char *CR_GetUsageError(P4ClientResolve* pObj) { VALIDATE_HANDLE_P(pObj, tP4ClientResolve) return pObj->GetUsageError().Text(); } __declspec(dllexport) char *CR_GetHelp(P4ClientResolve* pObj) { VALIDATE_HANDLE_P(pObj, tP4ClientResolve) return pObj->GetHelp().Text(); } __declspec(dllexport) P4ClientError *CR_GetLastError(P4ClientResolve* pObj) { VALIDATE_HANDLE_P(pObj, tP4ClientResolve) return pObj->GetLastError(); } /************************************************************************** * * SetResolveCallbackFn: Set the callback for replying to a resolve * callback. * * pServer: Pointer to the P4BridgeServer * * pNew: The new callback function pointer * * Return: None **************************************************************************/ __declspec(dllexport) void SetResolveCallbackFn( P4BridgeServer* pServer, ResolveCallbackFn* pNew ) { VALIDATE_HANDLE_V(pServer, tP4BridgeServer) pServer->pResolveCallbackFn = pNew; if (!pServer->get_ui()) return; pServer->get_ui()->SetResolveCallbackFn( pNew ); } /************************************************************************** * * SetResolveACallbackFn: Set the callback for replying to a resolve * callback. * * pServer: Pointer to the P4BridgeServer * * pNew: The new callback function pointer * * Return: None **************************************************************************/ __declspec(dllexport) void SetResolveACallbackFn( P4BridgeServer* pServer, ResolveACallbackFn* pNew ) { VALIDATE_HANDLE_V(pServer, tP4BridgeServer) pServer->pResolveACallbackFn = pNew; if (!pServer->get_ui()) return; pServer->get_ui()->SetResolveACallbackFn( pNew ); } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#3 | 16210 | Norman Morse | Remove files from old locations | ||
#2 | 12135 | Norman Morse |
Integrate dev branch changes into main. This code is the basiis of the 2.7 BETA release which provides Unity 5 compatibility |
||
#1 | 10940 | Norman Morse |
Inital Workshop release of P4Connect. Released under BSD-2 license |