Patch for sendKey
binBASH opened this issue · 1 comments
binBASH commented
diff --git src/domain.cc src/domain.cc
index 2a4011a..5b8e0c7 100644
--- src/domain.cc
+++ src/domain.cc
@@ -156,6 +156,8 @@ namespace NodeLibvirt {
Domain::Start);
NODE_SET_PROTOTYPE_METHOD(t, "suspend",
Domain::Suspend);
+ NODE_SET_PROTOTYPE_METHOD(t, "sendKey",
+ Domain::SendKey);
NODE_SET_PROTOTYPE_METHOD(t, "attachDevice",
Domain::AttachDevice);
NODE_SET_PROTOTYPE_METHOD(t, "detachDevice",
@@ -282,6 +284,9 @@ namespace NodeLibvirt {
NODE_DEFINE_CONSTANT(object_tmpl, VIR_DOMAIN_EVENT_WATCHDOG_SHUTDOWN);
NODE_DEFINE_CONSTANT(object_tmpl, VIR_DOMAIN_EVENT_WATCHDOG_DEBUG);
+
+ NODE_DEFINE_CONSTANT(object_tmpl, VIR_DOMAIN_SEND_KEY_MAX_KEYS);
+
state_symbol = NODE_PSYMBOL("state");
max_memory_symbol = NODE_PSYMBOL("max_memory");
memory_symbol = NODE_PSYMBOL("memory");
@@ -937,6 +942,41 @@ namespace NodeLibvirt {
return True();
}
+ Handle<Value> Domain::SendKey(const Arguments& args) {
+ HandleScope scope;
+ int ret = -1;
+
+ if(args.Length() == 0) {
+ return ThrowException(Exception::TypeError(
+ String::New("You must specify arguments to invoke this function")));
+ }
+
+ if(!args[0]->IsArray()) {
+ return ThrowException(Exception::TypeError(
+ String::New("Argument must be an array of objects")));
+ }
+
+ Domain *domain = ObjectWrap::Unwrap<Domain>(args.This());
+
+ unsigned int keycodes[VIR_DOMAIN_SEND_KEY_MAX_KEYS];
+
+ Local<Array> keycodes_ = Local<Array>::Cast(args[0]);
+
+ unsigned int length = keycodes_->Length();
+
+ for(unsigned int i = 0; i < length; i++) {
+ keycodes[i] = (unsigned int) keycodes_->Get(Integer::New(i))->Int32Value();
+ }
+
+ ret = virDomainSendKey(domain->domain_, 0, 150, keycodes, length, 0);
+
+ if(ret == -1) {
+ ThrowException(Error::New(virGetLastError()));
+ return False();
+ }
+ return True();
+ }
+
Handle<Value> Domain::GetVcpus(const Arguments& args) {
HandleScope scope;
diff --git src/domain.h src/domain.h
index e914942..07595bd 100644
--- src/domain.h
+++ src/domain.h
@@ -55,6 +55,7 @@ namespace NodeLibvirt {
static Handle<Value> Shutdown(const Arguments& args);
static Handle<Value> Start(const Arguments& args);
static Handle<Value> Destroy(const Arguments& args);
+ static Handle<Value> SendKey(const Arguments& args);
static Handle<Value> GetVcpus(const Arguments& args);
static Handle<Value> SetVcpus(const Arguments& args);
static Handle<Value> Migrate(const Arguments& args);
c4milo commented
Nice!, thank you for sending this patch. Would you please send it through a Pull Request?