From nobody Fri May 16 22:06:50 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1495227527516159.86252845692604; Fri, 19 May 2017 13:58:47 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B4988C04B92A; Fri, 19 May 2017 20:58:45 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 91F081713F; Fri, 19 May 2017 20:58:45 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 46118180BAF2; Fri, 19 May 2017 20:58:45 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v4JKwFgs012484 for ; Fri, 19 May 2017 16:58:15 -0400 Received: by smtp.corp.redhat.com (Postfix) id 087B317C53; Fri, 19 May 2017 20:58:15 +0000 (UTC) Received: from mx1.redhat.com (ext-mx07.extmail.prod.ext.phx2.redhat.com [10.5.110.31]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 02FF65DC1D for ; Fri, 19 May 2017 20:58:14 +0000 (UTC) Received: from mail-qk0-f172.google.com (mail-qk0-f172.google.com [209.85.220.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D0255C04B320 for ; Fri, 19 May 2017 20:58:12 +0000 (UTC) Received: by mail-qk0-f172.google.com with SMTP id a72so70710736qkj.2 for ; Fri, 19 May 2017 13:58:12 -0700 (PDT) Received: from silas.datto.lan ([47.19.105.250]) by smtp.gmail.com with ESMTPSA id t66sm2685740qkt.42.2017.05.19.13.58.11 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 May 2017 13:58:11 -0700 (PDT) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B4988C04B92A Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=datto.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com B4988C04B92A Authentication-Results: mx1.redhat.com; dkim=fail reason="signature verification failed" (2048-bit key) header.d=datto-com.20150623.gappssmtp.com header.i=@datto-com.20150623.gappssmtp.com header.b="hv3DhkDt" DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com D0255C04B320 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=datto.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=sramanujam@datto.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com D0255C04B320 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=datto-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references; bh=v1Vl9yuWDgmaRn+wiLsGbQMRhiEfPPbqK1yIs+yfQuQ=; b=hv3DhkDttrj1aLVppQ9c8Ukon0ifieXYg2wMFU6lkGrTiBsh8R0ZVKR8iwHY/5X9tu IkCGojS2BZnCr/zuu/3MoRv9NCbVxlpEziJmPM61Fd3GYK8ph4C2eKIXeSgi53MgeYvv /ITQaSaOckRlDjnyjjqSuDQfpgW2REuPDozIzkEwzLEX+eVohJuMdUhwRKoOIxCC7B/Y RzslRl1D+TPrzEHWzXEFlgfDuy7jZLwNV8YvpUDKHIzSN92W50mSoBq+Yr4bh4c1taU8 dQEsI6pyjfQ1L4EwNcCKUHaX1pzwZJ3F0swUMDj8lTKobLs2bnO8yuTT9Hng9wQXqGMx fRsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=v1Vl9yuWDgmaRn+wiLsGbQMRhiEfPPbqK1yIs+yfQuQ=; b=YlinxiEN/TvaELO24ihU3a6WQ0JxUtl22a+edS2EeN4lY2OfOP+agks7SKotAywm8j Nvgdw15fgzwXROhiB2NMhDWmzKvaaTHjCla+TrBjgSU9qtOgt2b6aJlpNQvrRHLyJo0f t/1l1vtoYWyRzhIS4153FsYir4ykrozZtB/hr4AlONZeVc4GTurlHumtugoeEJHxxmna EupF8TJlJKg68JB1dcj7DthD39tRTeRIBT4QC+S56Cm7spjnhvZsjoa0lawGitujlDSR R8n8zqCcftTFL+s9DW+HbRXKwy+zclyGjPZyDotYtArnCj/9m1gpMY/SgddqbkADGpYV Xtwg== X-Gm-Message-State: AODbwcCvx1Clr5IoysAJF7T4PGXjQMRGOgodHDghr6I1Go44A3tb1Nkd ZGVSZSJcDOd5xFe3LnA= X-Received: by 10.55.136.1 with SMTP id k1mr11684065qkd.104.1495227491822; Fri, 19 May 2017 13:58:11 -0700 (PDT) From: Sri Ramanujam To: libvir-list@redhat.com Date: Fri, 19 May 2017 16:58:01 -0400 Message-Id: <20170519205802.27094-5-sramanujam@datto.com> In-Reply-To: <20170519205802.27094-1-sramanujam@datto.com> References: <20170519205802.27094-1-sramanujam@datto.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 19 May 2017 20:58:13 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 19 May 2017 20:58:13 +0000 (UTC) for IP:'209.85.220.172' DOMAIN:'mail-qk0-f172.google.com' HELO:'mail-qk0-f172.google.com' FROM:'sramanujam@datto.com' RCPT:'' X-RedHat-Spam-Score: -1.911 (BAYES_50, DCC_REPUT_00_12, DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, RCVD_IN_SORBS_SPAM, SPF_PASS) 209.85.220.172 mail-qk0-f172.google.com 209.85.220.172 mail-qk0-f172.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.31 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v4 4/5] hyperv: support virDomainSendKey X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 19 May 2017 20:58:46 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This commit adds support for virDomainSendKey. It also serves as an example of how to use the new method invocation APIs with a single "simple" type parameter. --- src/hyperv/hyperv_driver.c | 107 ++++++++++++++++++++++++++++++= ++++ src/hyperv/hyperv_wmi.c | 7 +++ src/hyperv/hyperv_wmi.h | 3 +- src/hyperv/hyperv_wmi_generator.input | 86 +++++++++++++++++++++++++++ 4 files changed, 202 insertions(+), 1 deletion(-) diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c index 0ca5971..a01515a 100644 --- a/src/hyperv/hyperv_driver.c +++ b/src/hyperv/hyperv_driver.c @@ -35,6 +35,8 @@ #include "hyperv_wmi.h" #include "openwsman.h" #include "virstring.h" +#include "virkeycode.h" +#include "intprops.h" =20 #define VIR_FROM_THIS VIR_FROM_HYPERV =20 @@ -1373,6 +1375,110 @@ hypervConnectListAllDomains(virConnectPtr conn, #undef MATCH =20 =20 +static int +hypervDomainSendKey(virDomainPtr domain, unsigned int codeset, + unsigned int holdtime, unsigned int *keycodes, int nkeycodes, + unsigned int flags) +{ + int result =3D -1; + size_t i =3D 0; + int keycode =3D 0; + int *translatedKeycodes =3D NULL; + hypervPrivate *priv =3D domain->conn->privateData; + char uuid_string[VIR_UUID_STRING_BUFLEN]; + char *selector =3D NULL; + Msvm_ComputerSystem *computerSystem =3D NULL; + Msvm_Keyboard *keyboard =3D NULL; + virBuffer query =3D VIR_BUFFER_INITIALIZER; + hypervInvokeParamsListPtr params =3D NULL; + char keycodeStr[INT_BUFSIZE_BOUND(int)]; + + virCheckFlags(0, -1); + + virUUIDFormat(domain->uuid, uuid_string); + + if (hypervMsvmComputerSystemFromDomain(domain, &computerSystem) < 0) + goto cleanup; + + virBufferAsprintf(&query, + "associators of " + "{Msvm_ComputerSystem.CreationClassName=3D\"Msvm_ComputerSyste= m\"," + "Name=3D\"%s\"} " + "where ResultClass =3D Msvm_Keyboard", + uuid_string); + + if (hypervGetMsvmKeyboardList(priv, &query, &keyboard) < 0) + goto cleanup; + + if (VIR_ALLOC_N(translatedKeycodes, nkeycodes) < 0) + goto cleanup; + + /* translate keycodes to win32 and generate keyup scancodes. */ + for (i =3D 0; i < nkeycodes; i++) { + if (codeset !=3D VIR_KEYCODE_SET_WIN32) { + keycode =3D virKeycodeValueTranslate(codeset, VIR_KEYCODE_SET_= WIN32, + keycodes[i]); + + if (keycode < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Could not translate keycode")); + goto cleanup; + } + translatedKeycodes[i] =3D keycode; + } + } + + if (virAsprintf(&selector, + "CreationClassName=3DMsvm_Keyboard&DeviceID=3D%s&" + "SystemCreationClassName=3DMsvm_ComputerSystem&" + "SystemName=3D%s", keyboard->data.common->DeviceID, uuid_s= tring) < 0) + goto cleanup; + + /* press the keys */ + for (i =3D 0; i < nkeycodes; i++) { + snprintf(keycodeStr, sizeof(keycodeStr), "%d", translatedKeycodes[= i]); + + params =3D hypervCreateInvokeParamsList(priv, "PressKey", selector, + Msvm_Keyboard_WmiInfo); + if (hypervAddSimpleParam(params, "keyCode", keycodeStr) < 0) + goto cleanup; + + if (hypervInvokeMethod(priv, params, NULL) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not press key = %d"), + translatedKeycodes[i]); + goto cleanup; + } + } + + /* simulate holdtime by sleeping */ + if (holdtime > 0) + usleep(holdtime * 1000); + + /* release the keys */ + for (i =3D 0; i < nkeycodes; i++) { + snprintf(keycodeStr, sizeof(keycodeStr), "%d", translatedKeycodes[= i]); + params =3D hypervCreateInvokeParamsList(priv, "ReleaseKey", select= or, + Msvm_Keyboard_WmiInfo); + if (hypervAddSimpleParam(params, "keyCode", keycodeStr) < 0) + goto cleanup; + + if (hypervInvokeMethod(priv, params, NULL) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not release ke= y %s"), + keycodeStr); + goto cleanup; + } + } + + result =3D 0; + + cleanup: + VIR_FREE(translatedKeycodes); + VIR_FREE(selector); + hypervFreeObject(priv, (hypervObject *) keyboard); + hypervFreeObject(priv, (hypervObject *) computerSystem); + virBufferFreeAndReset(&query); + return result; +} =20 =20 static virHypervisorDriver hypervHypervisorDriver =3D { @@ -1408,6 +1514,7 @@ static virHypervisorDriver hypervHypervisorDriver =3D= { .domainManagedSave =3D hypervDomainManagedSave, /* 0.9.5 */ .domainHasManagedSaveImage =3D hypervDomainHasManagedSaveImage, /* 0.9= .5 */ .domainManagedSaveRemove =3D hypervDomainManagedSaveRemove, /* 0.9.5 */ + .domainSendKey =3D hypervDomainSendKey, /* TODO: version */ .connectIsAlive =3D hypervConnectIsAlive, /* 0.9.8 */ }; =20 diff --git a/src/hyperv/hyperv_wmi.c b/src/hyperv/hyperv_wmi.c index b847d17..2165838 100644 --- a/src/hyperv/hyperv_wmi.c +++ b/src/hyperv/hyperv_wmi.c @@ -1326,6 +1326,13 @@ hypervGetMsvmMemorySettingDataList(hypervPrivate *pr= iv, virBufferPtr query, (hypervObject **) list); } =20 +int hypervGetMsvmKeyboardList(hypervPrivate *priv, virBufferPtr query, + Msvm_Keyboard **list) +{ + return hypervGetWmiClassList(priv, Msvm_Keyboard_WmiInfo, query, + (hypervObject **) list); +} + =20 =20 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *= * * diff --git a/src/hyperv/hyperv_wmi.h b/src/hyperv/hyperv_wmi.h index f39f79f..eb6f43d 100644 --- a/src/hyperv/hyperv_wmi.h +++ b/src/hyperv/hyperv_wmi.h @@ -217,7 +217,8 @@ int hypervGetMsvmProcessorSettingDataList(hypervPrivate= *priv, int hypervGetMsvmMemorySettingDataList(hypervPrivate *priv, virBufferPtr q= uery, Msvm_MemorySettingData **list); =20 - +int hypervGetMsvmKeyboardList(hypervPrivate *priv, virBufferPtr query, + Msvm_Keyboard **list); =20 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *= * * * Msvm_ComputerSystem diff --git a/src/hyperv/hyperv_wmi_generator.input b/src/hyperv/hyperv_wmi_= generator.input index d7f819e..4ccda04 100644 --- a/src/hyperv/hyperv_wmi_generator.input +++ b/src/hyperv/hyperv_wmi_generator.input @@ -956,3 +956,89 @@ class Msvm_VirtualHardDiskSettingData uint32 PhysicalSectorSize string VirtualDiskId end + +class Msvm_Keyboard + string Caption + string Description + string ElementName + datetime InstallDate + string Name + uint16 OperationalStatus[] + string StatusDescriptions[] + string Status + uint16 HealthState + uint16 EnabledState + string OtherEnabledState + uint16 RequestedState + uint16 EnabledDefault + datetime TimeOfLastStateChange + string SystemCreationClassName + string SystemName + string CreationClassName + string DeviceID + boolean PowerManagementSupported + uint16 PowerManagementCapabilities[] + uint16 Availability + uint16 StatusInfo + uint32 LastErrorCode + string ErrorDescription + boolean ErrorCleared + string OtherIdentifyingInfo[] + uint64 PowerOnHours + uint64 TotalPowerOnHours + string IdentifyingDescriptions[] + uint16 AdditionalAvailability[] + uint64 MaxQuiesceTime + uint16 LocationIndicator + boolean IsLocked + string Layout + uint16 NumberOfFunctionKeys + uint16 Password +end + + +class v2/Msvm_Keyboard + string InstanceID + string Caption + string Description + string ElementName + datetime InstallDate + string Name + uint16 OperationalStatus[] + string StatusDescriptions[] + string Status + uint16 HealthState + uint16 CommunicationStatus + uint16 DetailedStatus + uint16 OperatingStatus + uint16 PrimaryStatus + uint16 EnabledState + string OtherEnabledState + uint16 RequestedState + uint16 EnabledDefault + datetime TimeOfLastStateChange + uint16 AvailableRequestedStates[] + uint16 TransitioningToState + string SystemCreationClassName + string SystemName + string CreationClassName + string DeviceID + boolean PowerManagementSupported + uint16 PowerManagementCapabilities[] + uint16 Availability + uint16 StatusInfo + uint32 LastErrorCode + string ErrorDescription + boolean ErrorCleared + string OtherIdentifyingInfo[] + uint64 PowerOnHours + uint64 TotalPowerOnHours + string IdentifyingDescriptions[] + uint16 AdditionalAvailability[] + uint64 MaxQuiesceTime + boolean IsLocked + string Layout + uint16 NumberOfFunctionKeys + uint16 Password + boolean UnicodeSupported +end --=20 2.9.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list