/* Copyright (C) 2007 Vizim Worldwide. All rights reserved. This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. */ /******************************************************************************* * Name: p4clientapi.cpp * * Author: Robert Cowham <robert@vizim.com> * * Description: * Wrapper for P4API * ******************************************************************************/ #include "stdafx.h" #include "p4connection.h" P4Connection::P4Connection() { m_initCount = 0; m_tagged = 0; m_exceptionLevel = 2; m_prog = "P4Connect"; m_version = "2009.1"; } P4Connection::~P4Connection() { if (m_initCount) { Error e; m_client.Final(&e); // Ignore errors } } int P4Connection::Connect(StrBuf &errMsg) { if (m_initCount) { return S_OK; } Error e; m_client.Init(&e); if (e.Test() && m_exceptionLevel) { StrBuf m; e.Fmt(&m); errMsg = m.Text(); return E_FAIL; } if (e.Test()) return E_FAIL; m_initCount++; return S_OK; } // // Disconnect session // int P4Connection::Disconnect() { if (!m_initCount) { return S_OK; } Error e; m_client.Final( &e ); m_initCount--; return S_OK; } void P4Connection::Tagged() { m_client.SetProtocol("tag", ""); m_tagged = 1; } void P4Connection::ParseForms() { m_client.SetProtocol("tag", ""); m_client.SetProtocol("specstring", ""); m_tagged = 1; } long P4Connection::Run(LPCSTR cmd, int argc, char *const *argv) { if (!m_initCount) return E_FAIL; Error e; m_ui.Reset(); // Clear out any results from the previous command // Set values which must be done between Init and Run if (m_prog.Length() > 0) m_client.SetProg(&m_prog); if (m_version.Length() > 0) m_client.SetVersion(&m_version); m_client.SetArgv( argc, argv ); m_client.Run( cmd, &m_ui ); m_ui.CloseFiles(); return S_OK; } void GetMsg(StrBuf &msg, StrArray *sba) { for (int i = 0; i < sba->Count(); i++) { msg.Append(sba->Get(i)); msg.Append(" "); } } StrBuf P4Connection::ErrorMsg() { StrBuf errMsg; // Create msg from error array (if exists) if (ExceptionLevel() > 0) { if (ExceptionLevel() == 1) { GetMsg(errMsg, m_ui.ErrorArray()); } else { GetMsg(errMsg, m_ui.WarningArray()); GetMsg(errMsg, m_ui.ErrorArray()); } } return errMsg; }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#2 | 7502 | Robert Cowham |
- Updated for 2009.1 API - use static version (/MT rather than /MD) - Fixed SetProg/SetVersion calls - ensures they are called at correct moment. - Add SetProtocol - Added some more tests/examples |
||
#1 | 6468 | Robert Cowham | Draft version. |