Esempio n. 1
0
func (s *Server) GetVms() (vms *list.List, err error) {

	vms = list.New()
	var hJob = C.PrlSrv_GetVmList(s.handle)
	defer C.PrlHandle_Free(hJob)

	res := C.PrlJob_Wait(hJob, 10000)
	if res < 0 {
		return vms, from_prl_error("PrlJob_Wait", res)
	}

	var nJobReturnCode C.PRL_RESULT
	var hJobResult C.PRL_HANDLE
	defer C.PrlHandle_Free(hJobResult)

	res = C.PrlJob_GetRetCode(hJob, &nJobReturnCode)
	if res < 0 {
		return vms, from_prl_error("PrlJob_GetRetCode", res)
	}
	if nJobReturnCode < 0 {
		return vms, from_prl_error("PrlJob_GetRetCode", nJobReturnCode)
	}

	res = C.PrlJob_GetResult(hJob, &hJobResult)
	if res < 0 {
		return vms, from_prl_error("PrlJob_GetResult", res)
	}

	var nIndex, nCount C.PRL_UINT32

	res = C.PrlResult_GetParamsCount(hJobResult, &nCount)
	if res < 0 {
		return vms, from_prl_error("PrlResult_GetParamsCount", res)
	}

	for nIndex = 0; nIndex < nCount; nIndex++ {

		var hVm *C.PRL_HANDLE = new(C.PRL_HANDLE)
		res = C.PrlResult_GetParamByIndex(hJobResult, nIndex, hVm)
		if res >= 0 {
			vms.PushBack(VirtualMachine{handle: *hVm})
		}
	}
	return vms, nil
}
Esempio n. 2
0
func LoginLocal() (server Server, err error) {

	var hServer C.PRL_HANDLE
	var res C.PRL_RESULT

	res = C.PrlApi_InitEx(C.PARALLELS_API_VER, C.PAM_DESKTOP, C.PRL_UINT32(0), C.PRL_UINT32(0))
	if res < 0 {
		C.PrlApi_Deinit()
		return Server{}, from_prl_error("PrlApi_InitEx", res)
	}

	//Call the PrlSrv_Create to obtain the handle.
	res = C.PrlSrv_Create(&hServer)
	if res < 0 {
		C.PrlApi_Deinit()
		return Server{}, from_prl_error("PrlSrv_Create", res)
	}

	// Log in (PrlSrv_Login is asynchronous).
	var hJob = C.PrlSrv_LoginLocal(hServer, nil, C.PRL_UINT32(0), C.PSL_LOW_SECURITY)
	defer C.PrlHandle_Free(hJob)
	// Wait for a maximum of 10 seconds for asynchronous function PrlSrv_Login to complete.
	res = C.PrlJob_Wait(hJob, 10000)
	if res < 0 {
		defer C.PrlHandle_Free(hServer)
		defer C.PrlApi_Deinit()
		return Server{}, from_prl_error("PrlJob_Wait", res)
	}
	// Analyse the result of the PrlServer_Login call.
	var nJobResult C.PRL_RESULT
	res = C.PrlJob_GetRetCode(hJob, &nJobResult)
	if nJobResult < 0 {
		defer C.PrlHandle_Free(hServer)
		defer C.PrlApi_Deinit()
		return Server{}, from_prl_error("PrlJob_GetRetCode", res)
	}

	server.handle = hServer

	return server, nil
}
func (v *VirtualMachine) DisplayConnect() error {

	// PDCQ_HIGH_QUALITY = 1<<0
	// PDCC_NO_COMPRESSION = 1<<18
	// 1 | 1<<18 = 262145 = 0x40001
	//C.PrlDevDisplay_ConnectToVm(v.handle, C.enum_PDCT_HIGH_QUALITY_WITHOUT_COMPRESSION)
	hJob := C.PrlDevDisplay_ConnectToVm(v.handle, C.PRL_DISPLAY_CODEC_TYPE(0x40001))
	defer C.PrlHandle_Free(hJob)
	res := C.PrlJob_Wait(hJob, 10000)
	if res < 0 {
		return from_prl_error("PrlJob_Wait", res)
	}
	v.displayConnected = true
	return nil
}
Esempio n. 4
0
func (s *Server) Disconnect() {
	defer C.PrlHandle_Free(s.handle)
	defer C.PrlApi_Deinit()
}