[Qemu-devel] [RFC][PATCH v4 14/18] virtagent: add client capabilities init function

2010-11-16 Thread Michael Roth
Non-monitor version of agent_capabilities monitor function. This is
called by the local RPC server when it gets a "hello" from the guest
agent to re-negotiate guest agent capabilities.

Signed-off-by: Michael Roth 
---
 virtagent.c |   34 ++
 virtagent.h |1 +
 2 files changed, 35 insertions(+), 0 deletions(-)

diff --git a/virtagent.c b/virtagent.c
index e0f7f99..4ec1b42 100644
--- a/virtagent.c
+++ b/virtagent.c
@@ -694,3 +694,37 @@ int do_agent_capabilities(Monitor *mon, const QDict 
*mon_params,
 
 return 0;
 }
+
+/* non-HMP/QMP RPC client functions */
+
+int va_client_init_capabilities(void)
+{
+xmlrpc_env env;
+xmlrpc_value *params;
+VARPCData *rpc_data;
+int ret;
+
+xmlrpc_env_init(&env);
+
+params = xmlrpc_build_value(&env, "()");
+if (rpc_has_error(&env)) {
+return -1;
+}
+
+rpc_data = qemu_mallocz(sizeof(VARPCData));
+rpc_data->cb = do_agent_capabilities_cb;
+rpc_data->mon_cb = NULL;
+rpc_data->mon_data = NULL;
+
+ret = rpc_execute(&env, "system.listMethods", params, rpc_data);
+if (ret == -EREMOTE) {
+LOG("RPC Failed (%i): %s\n", env.fault_code,
+env.fault_string);
+return -1;
+} else if (ret == -1) {
+LOG("RPC communication error\n");
+return -1;
+}
+
+return 0;
+}
diff --git a/virtagent.h b/virtagent.h
index c10ee35..da4be60 100644
--- a/virtagent.h
+++ b/virtagent.h
@@ -23,6 +23,7 @@
 #define VA_MAX_CHUNK_SIZE 4096 /* max bytes at a time for get/send file */
 
 int va_client_init(VPDriver *vp_drv, bool is_host);
+int va_client_init_capabilities(void);
 void do_agent_viewfile_print(Monitor *mon, const QObject *qobject);
 int do_agent_viewfile(Monitor *mon, const QDict *mon_params,
   MonitorCompletion cb, void *opaque);
-- 
1.7.0.4




Re: [Qemu-devel] [RFC][PATCH v4 14/18] virtagent: add client capabilities init function

2010-11-18 Thread Jes Sorensen
On 11/16/10 17:01, Michael Roth wrote:
> Non-monitor version of agent_capabilities monitor function. This is
> called by the local RPC server when it gets a "hello" from the guest
> agent to re-negotiate guest agent capabilities.
> 
> Signed-off-by: Michael Roth 
> ---
>  virtagent.c |   34 ++
>  virtagent.h |1 +
>  2 files changed, 35 insertions(+), 0 deletions(-)
> 
> diff --git a/virtagent.c b/virtagent.c
> index e0f7f99..4ec1b42 100644
> --- a/virtagent.c
> +++ b/virtagent.c
> @@ -694,3 +694,37 @@ int do_agent_capabilities(Monitor *mon, const QDict 
> *mon_params,
>  
>  return 0;
>  }
> +
> +/* non-HMP/QMP RPC client functions */
> +
> +int va_client_init_capabilities(void)
> +{
> +xmlrpc_env env;
> +xmlrpc_value *params;
> +VARPCData *rpc_data;
> +int ret;
> +
> +xmlrpc_env_init(&env);
> +
> +params = xmlrpc_build_value(&env, "()");
> +if (rpc_has_error(&env)) {
> +return -1;
> +}
> +
> +rpc_data = qemu_mallocz(sizeof(VARPCData));
> +rpc_data->cb = do_agent_capabilities_cb;
> +rpc_data->mon_cb = NULL;
> +rpc_data->mon_data = NULL;
> +
> +ret = rpc_execute(&env, "system.listMethods", params, rpc_data);
> +if (ret == -EREMOTE) {
> +LOG("RPC Failed (%i): %s\n", env.fault_code,
> +env.fault_string);
> +return -1;
> +} else if (ret == -1) {
> +LOG("RPC communication error\n");
> +return -1;
> +}

One of many examples that would have benefited from having a utility
function doing most of the work here.

Cheers,
Jes



Re: [Qemu-devel] [RFC][PATCH v4 14/18] virtagent: add client capabilities init function

2010-11-18 Thread Michael Roth

On 11/18/2010 08:22 AM, Jes Sorensen wrote:

On 11/16/10 17:01, Michael Roth wrote:

Non-monitor version of agent_capabilities monitor function. This is
called by the local RPC server when it gets a "hello" from the guest
agent to re-negotiate guest agent capabilities.

Signed-off-by: Michael Roth
---
  virtagent.c |   34 ++
  virtagent.h |1 +
  2 files changed, 35 insertions(+), 0 deletions(-)

diff --git a/virtagent.c b/virtagent.c
index e0f7f99..4ec1b42 100644
--- a/virtagent.c
+++ b/virtagent.c
@@ -694,3 +694,37 @@ int do_agent_capabilities(Monitor *mon, const QDict 
*mon_params,

  return 0;
  }
+
+/* non-HMP/QMP RPC client functions */
+
+int va_client_init_capabilities(void)
+{
+xmlrpc_env env;
+xmlrpc_value *params;
+VARPCData *rpc_data;
+int ret;
+
+xmlrpc_env_init(&env);
+
+params = xmlrpc_build_value(&env, "()");
+if (rpc_has_error(&env)) {
+return -1;
+}
+
+rpc_data = qemu_mallocz(sizeof(VARPCData));
+rpc_data->cb = do_agent_capabilities_cb;
+rpc_data->mon_cb = NULL;
+rpc_data->mon_data = NULL;
+
+ret = rpc_execute(&env, "system.listMethods", params, rpc_data);
+if (ret == -EREMOTE) {
+LOG("RPC Failed (%i): %s\n", env.fault_code,
+env.fault_string);
+return -1;
+} else if (ret == -1) {
+LOG("RPC communication error\n");
+return -1;
+}


One of many examples that would have benefited from having a utility
function doing most of the work here.



Agreed, I should be able to trim quite a few lines out of virtagent.c 
with a bit more code re-use.



Cheers,
Jes