package p4go //#include "p4go.h" //#include import "C" import "unsafe" type p4ApiHandle struct { handle C.P4HANDLE } type clientApiHandle struct { p4ApiHandle } type clientUserHandle struct { p4ApiHandle } type fileSysHandle struct { p4ApiHandle } type strBufHandle struct { p4ApiHandle } type errorHandle struct { handle C.P4ERROR } func (h p4ApiHandle) GetHandle() C.P4HANDLE { return h.handle } type HandleApi interface { GetHandle() C.P4HANDLE } /** * ClientApi */ type ClientApi interface { HandleApi DefineClient(client string, e Error) DefineHost(host string, e Error) DefinePassword(pwd string, e Error) DefinePort(post string, e Error) DefineUser(user string, e Error) Delete() Dropped() int Final(Error) int GetClient() string GetCwd() string GetConfig() string GetHost() string GetOs() string GetPassword() string GetPort() string GetProtocol(pro string) string GetUser() string Init(Error) Run(cmd string, user ClientUser) SetArgv(args []string) SetClient(client string) SetCwd(cwd string) SetCwdNoReload(cwd string) SetHost(host string) SetPassword(pwd string) SetPort(port string) SetProg(prog string) SetProtocol(name string, value string) SetProtocolV(nv string) SetTicketFile(path string) SetUi(user ClientUser) SetUser(user string) SetVersion(version string) } func NewClientApi() ClientApi { var h clientApiHandle h.handle = C.ClientApi_New() return h } func (api clientApiHandle) Delete() { C.ClientApi_Delete(api.handle) } func (api clientApiHandle) DefineClient(client string, e Error) { var clientStr = C.CString(client) defer C.free(unsafe.Pointer(clientStr)) C.ClientApi_DefineClient(api.handle, clientStr, e.GetHandle()) } func (api clientApiHandle) DefineHost(host string, e Error) { var hostStr = C.CString(host) defer C.free(unsafe.Pointer(hostStr)) C.ClientApi_DefineHost(api.handle, hostStr, e.GetHandle()) } func (api clientApiHandle) DefinePassword(pwd string, e Error) { var pwdStr = C.CString(pwd) defer C.free(unsafe.Pointer(pwdStr)) C.ClientApi_DefineHost(api.handle, pwdStr, e.GetHandle()) } func (api clientApiHandle) DefinePort(post string, e Error) { var postStr = C.CString(post) defer C.free(unsafe.Pointer(postStr)) C.ClientApi_DefinePort(api.handle, postStr, e.GetHandle()) } func (api clientApiHandle) DefineUser(user string, e Error) { var userStr = C.CString(user) defer C.free(unsafe.Pointer(userStr)) C.ClientApi_DefineUser(api.handle, userStr, e.GetHandle()) } func (api clientApiHandle) Dropped() int { return int(C.ClientApi_Dropped(api.handle)) } func (api clientApiHandle) Final(e Error) int { return int(C.ClientApi_Final(api.handle, e.GetHandle())) } func (api clientApiHandle) GetClient() string { return C.GoString(C.ClientApi_GetClient(api.handle)) } func (api clientApiHandle) GetCwd() string { return C.GoString(C.ClientApi_GetCwd(api.handle)) } func (api clientApiHandle) GetConfig() string { return C.GoString(C.ClientApi_GetConfig(api.handle)) } func (api clientApiHandle) GetHost() string { return C.GoString(C.ClientApi_GetHost(api.handle)) } func (api clientApiHandle) GetOs() string { return C.GoString(C.ClientApi_GetOs(api.handle)) } func (api clientApiHandle) GetPassword() string { return C.GoString(C.ClientApi_GetPassword(api.handle)) } func (api clientApiHandle) GetPort() string { return C.GoString(C.ClientApi_GetPort(api.handle)) } func (api clientApiHandle) GetProtocol(pro string) string { var proStr = C.CString(pro) defer C.free(unsafe.Pointer(proStr)) return C.GoString(C.ClientApi_GetProtocol(api.handle, proStr)) } func (api clientApiHandle) GetUser() string { return C.GoString(C.ClientApi_GetUser(api.handle)) } func (api clientApiHandle) Init(e Error) { C.ClientApi_Init(api.handle, e.GetHandle()) } func (api clientApiHandle) Run(cmd string, user ClientUser) { var cCmd = C.CString(cmd) defer C.free(unsafe.Pointer(cCmd)) C.ClientApi_Run(api.handle, cCmd, C.P4HANDLE(user.GetHandle())) } func (api clientApiHandle) SetArgv(args []string) { // ARGH need to create a C array... hm... argv := C.CreateStringArray(C.int(len(args))) for ii := 0; ii < len(args); ii++ { cstr := C.CString(args[ii]) C.AssignString(argv, C.int(ii), cstr) } defer C.DeleteStringArray(argv, C.int(len(args))) C.ClientApi_SetArgv(api.handle, C.int(len(args)), argv) } func (api clientApiHandle) SetClient(client string) { var clientStr = C.CString(client) defer C.free(unsafe.Pointer(clientStr)) C.ClientApi_SetClient(api.handle, clientStr) } func (api clientApiHandle) SetCwd(cwd string) { var cwdStr = C.CString(cwd) defer C.free(unsafe.Pointer(cwdStr)) C.ClientApi_SetCwd(api.handle, cwdStr) } func (api clientApiHandle) SetCwdNoReload(cwd string) { var cwdStr = C.CString(cwd) defer C.free(unsafe.Pointer(cwdStr)) C.ClientApi_SetCwdNoReload(api.handle, cwdStr) } func (api clientApiHandle) SetHost(host string) { var hostStr = C.CString(host) defer C.free(unsafe.Pointer(hostStr)) C.ClientApi_SetHost(api.handle, hostStr) } func (api clientApiHandle) SetPassword(pwd string) { var pwdStr = C.CString(pwd) defer C.free(unsafe.Pointer(pwdStr)) C.ClientApi_SetPassword(api.handle, pwdStr) } func (api clientApiHandle) SetPort(port string) { var portStr = C.CString(port) defer C.free(unsafe.Pointer(portStr)) C.ClientApi_SetPort(api.handle, portStr) } func (api clientApiHandle) SetProg(prog string) { var progStr = C.CString(prog) defer C.free(unsafe.Pointer(progStr)) C.ClientApi_SetProg(api.handle, progStr) } func (api clientApiHandle) SetProtocol(name string, value string) { var nameStr = C.CString(name) defer C.free(unsafe.Pointer(nameStr)) var valueStr = C.CString(value) defer C.free(unsafe.Pointer(valueStr)) C.ClientApi_SetProtocol(api.handle, nameStr, valueStr) } func (api clientApiHandle) SetProtocolV(nv string) { var nvStr = C.CString(nv) defer C.free(unsafe.Pointer(nvStr)) C.ClientApi_SetProtocolV(api.handle, nvStr) } func (api clientApiHandle) SetTicketFile(path string) { var pathStr = C.CString(path) defer C.free(unsafe.Pointer(pathStr)) C.ClientApi_SetTicketFile(api.handle, pathStr) } func (api clientApiHandle) SetUi(user ClientUser) { C.ClientApi_SetUi(api.handle, user.GetHandle()) } func (api clientApiHandle) SetUser(user string) { userStr := C.CString(user) defer C.free(unsafe.Pointer(userStr)) C.ClientApi_SetUser(api.handle, userStr) } func (api clientApiHandle) SetVersion(version string) { verStr := C.CString(version) defer C.free(unsafe.Pointer(verStr)) C.ClientApi_SetVersion(api.handle, verStr) } // --------------------------- // ClientUser // --------------------------- type ClientUser interface { HandleApi Clear() Delete() File(fileSysType int) FileSys GetOutputError() string GetOutputInfo() string GetOutputText() string SetInputData(data string) } func NewClientUser() ClientUser { var h clientUserHandle h.handle = C.ClientUser_New() return h } func (u clientUserHandle) Delete() { C.ClientUser_Delete(u.handle) } func (u clientUserHandle) Clear() { C.ClientUser_Clear(u.handle) } func (u clientUserHandle) File(fileSysType int) FileSys { fh := C.ClientUser_File(u.handle, C.int(fileSysType)) return fileSysHandle{p4ApiHandle{fh}} } func (u clientUserHandle) GetOutputError() string { return C.GoString(C.ClientUser_GetOutputError(u.handle)) } func (u clientUserHandle) GetOutputInfo() string { return C.GoString(C.ClientUser_GetOutputInfo(u.handle)) } func (u clientUserHandle) GetOutputText() string { return C.GoString(C.ClientUser_GetOutputText(u.handle)) } func (u clientUserHandle) SetInputData(data string) { cstr := C.CString(data) defer C.free(unsafe.Pointer(cstr)) C.ClientUser_SetInputData(u.handle, cstr) } // --------------------------- // FileSys // --------------------------- type FileSys interface { HandleApi Delete() } func (fs fileSysHandle) Delete() { C.FileSys_Delete(fs.handle) } // --------------------------- // Error // --------------------------- type Error interface { Delete() GetHandle() C.P4ERROR Clear() Dump(trace string) Fmt(sb StrBuf) FmtOpts(sb StrBuf, opts int) GetGeneric() int GetSeverity() int IsFatal() int IsWarning() int Net(op string, arg string) AddInt(ii int) AddStr(str string) Copy(from Error) Set(errSeverity int, fmt string) Sys(op string, arg string) Test() int } func NewError() Error { return errorHandle{C.Error_New()} } func (e errorHandle) Delete() { C.Error_Delete(e.handle) } func (e errorHandle) GetHandle() C.P4ERROR { return e.handle } func (e errorHandle) Clear() { C.Error_Clear(e.handle) } func (e errorHandle) Dump(trace string) { var ctr = C.CString(trace) C.Error_Dump(e.handle, ctr) } func (e errorHandle) Fmt(sb StrBuf) { C.Error_Fmt(e.handle, sb.GetHandle()) } func (e errorHandle) FmtOpts(sb StrBuf, opts int) { C.Error_FmtOpts(e.handle, sb.GetHandle(), C.int(opts)) } func (e errorHandle) GetGeneric() int { return int(C.Error_GetGeneric(e.handle)) } func (e errorHandle) GetSeverity() int { return int(C.Error_GetSeverity(e.handle)) } func (e errorHandle) IsFatal() int { return int(C.Error_IsFatal(e.handle)) } func (e errorHandle) IsWarning() int { return int(C.Error_IsWarning(e.handle)) } func (e errorHandle) Net(op string, arg string) { var copt = C.CString(op) var carg = C.CString(arg) C.Error_Net(e.handle, copt, carg) } func (e errorHandle) AddInt(ii int) { C.Error_Add_Int(e.handle, C.int(ii)) } func (e errorHandle) AddStr(str string) { var cstr = C.CString(str) C.Error_Add_Str(e.handle, cstr) } func (e errorHandle) Copy(from Error) { C.Error_Copy(e.handle, from.GetHandle()) } func (e errorHandle) Set(errSeverity int, fmt string) { var cfmt = C.CString(fmt) C.Error_Set(e.handle, C.int(errSeverity), cfmt) } func (e errorHandle) Sys(op string, arg string) { var cop = C.CString(op) var carg = C.CString(arg) C.Error_Sys(e.handle, cop, carg) } func (e errorHandle) Test() int { return int(C.Error_Test(e.handle)) } // --------------------------- // StrBuf // --------------------------- type StrBuf interface { HandleApi Delete() Text() string } func NewStrBuf() StrBuf { return strBufHandle{p4ApiHandle{C.StrBuf_New(C.P4HANDLE(nil))}} } func (sb strBufHandle) Delete() { C.StrBuf_Delete(sb.handle) } func (sb strBufHandle) Text() string { return C.GoString(C.StrBuf_Text(sb.handle)) } // --------------------------- // Const // --------------------------- const ( // ErrorSeverity E_EMPTY = 0 // nothing yet E_INFO = 1 // something good happened E_WARN = 2 // something not good happened E_FAILED = 3 // user did somthing wrong E_FATAL = 4 // system broken -- nothing can continue // FileOpenMode FOM_READ = 0 // open for reading FOM_WRITE = 1 // open for writing FOM_RW = 2 // open for write, but don't trunc, allow read // FileSysType // Base types FST_TEXT = 0x0001 // file is text FST_BINARY = 0x0002 // file is binary FST_GZIP = 0x0003 // file is gzip FST_DIRECTORY = 0x0005 // it's a directory FST_SYMLINK = 0x0006 // it's a symlink FST_RESOURCE = 0x0007 // Macintosh resource file FST_SPECIAL = 0x0008 // not a regular file FST_MISSING = 0x0009 // no file at all FST_CANTTELL = 0x000A // can read file to find out FST_EMPTY = 0x000B // file is empty FST_UNICODE = 0x000C // file is unicode FST_GUNZIP = 0x000D // stream is gzip FST_UTF16 = 0x000E // stream is utf8 convert to utf16 FST_MASK = 0x000F // mask for types // Modifiers FST_M_APPEND = 0x0010 // open always append FST_M_EXCL = 0x0020 // open exclusive create FST_M_SYNC = 0x0040 // fsync on close FST_M_EXEC = 0x0100 // file is executable FST_M_APPLE = 0x0200 // apple single/double encoding FST_M_COMP = 0x0400 // file is somehow compressed FST_M_MASK = 0x0ff0 // mask for modifiers // Line ending types loosely mapped to LineType FST_L_LOCAL = 0x0000 // LineTypeLocal FST_L_LF = 0x1000 // LineTypeRaw FST_L_CR = 0x2000 // LineTypeCr FST_L_CRLF = 0x3000 // LineTypeCrLf FST_L_LFCRLF = 0x4000 // LineTypeLfcrlf FST_L_MASK = 0xf000 // mask for LineTypes // Composite types for filesys.cc FST_ATEXT = 0x0011 // append-only text FST_XTEXT = 0x0101 // executable text FST_RTEXT = 0x1001 // raw text FST_RXTEXT = 0x1101 // executable raw text FST_CBINARY = 0x0402 // pre-compressed binary FST_XBINARY = 0x0102 // executable binary FST_APPLETEXT = 0x0201 // apple format text FST_APPLEFILE = 0x0202 // apple format binary FST_XAPPLEFILE = 0x0302 // executable apple format binary FST_XUNICODE = 0x010C // executable unicode text FST_XUTF16 = 0x010E // stream is utf8 convert to utf16 FST_RCS = 0x1041 // RCS temporary file: raw text sync on close // FilePerm FPM_RO = 0x00 // leave file read-only FPM_RW = 0x01 // allow read-write operations // FileSys Stat types FSF_ERROR = 0 // failure FSF_EXISTS = 0x01 // file exists FSF_WRITEABLE = 0x02 // file is user-writable FSF_DIRECTORY = 0x04 // file is a directory FSF_SYMLINK = 0x08 // file is symlink FSF_SPECIAL = 0x10 // file is a special file (in the UNIX sense) FSF_EXECUTABLE = 0x20 // file is executable FSF_EMPTY = 0x40 // file is empty FSF_HIDDEN = 0x80 // file is invisible (hidden) )