Beispiel #1
0
func (t *TypedParameters) TypedParamsAddUInt64(val uint64, name string) error {
	cname := C.CString(name)
	defer C.free(unsafe.Pointer(cname))

	result := C.virTypedParamsAddULLong(&t.cptr, &t.length, &t.capacity, cname, C.ulonglong(val))
	if result == -1 {
		return GetLastError()
	}
	return nil
}
Beispiel #2
0
func (dest *VirTypedParameters) loadToCPtr() (params C.virTypedParameterPtr, nParams C.int, err error) {

	var maxParams C.int = 0
	params = nil

	for _, param := range *dest {

		switch param.Name {
		case VIR_DOMAIN_BLOCK_COPY_GRANULARITY:
			value, ok := param.Value.(uint)
			if !ok {
				err = errors.New("Mismatched parameter value type")
				return
			}

			cName := C.CString(param.Name)
			defer C.free(unsafe.Pointer(cName))

			result := C.virTypedParamsAddUInt(&params, &nParams, &maxParams, cName, C.uint(value))
			if result == -1 {
				err = GetLastError()
				return
			}
		case VIR_DOMAIN_BLOCK_COPY_BANDWIDTH, VIR_DOMAIN_BLOCK_COPY_BUF_SIZE:
			value, ok := param.Value.(uint64)
			if !ok {
				err = errors.New("Mismatched parameter value type")
				return
			}

			cName := C.CString(param.Name)
			defer C.free(unsafe.Pointer(cName))

			result := C.virTypedParamsAddULLong(&params, &nParams, &maxParams, cName, C.ulonglong(value))
			if result == -1 {
				err = GetLastError()
				return
			}
		default:
			err = errors.New("Unknown parameter name: " + param.Name)
			return
		}
	}
	return
}