summaryrefslogtreecommitdiffstats
path: root/generator
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2012-11-02 10:38:48 +0000
committerRichard W.M. Jones <rjones@redhat.com>2012-11-02 14:36:31 +0000
commit6f34b81321ad61adb2c22655ec68c57febbbe80b (patch)
treec6640630dc35750b07848a75feaa1d8b1fc0d1e1 /generator
parentf56bc8edd5f23c23298bf3f609a98dd6fec5d512 (diff)
downloadlibguestfs-6f34b81321ad61adb2c22655ec68c57febbbe80b.tar.gz
libguestfs-6f34b81321ad61adb2c22655ec68c57febbbe80b.tar.xz
libguestfs-6f34b81321ad61adb2c22655ec68c57febbbe80b.zip
generator: actions: Move 3 helper functions to a separate file.
This is just code motion.
Diffstat (limited to 'generator')
-rw-r--r--generator/c.ml95
1 files changed, 6 insertions, 89 deletions
diff --git a/generator/c.ml b/generator/c.ml
index 54f35b57..167ab86c 100644
--- a/generator/c.ml
+++ b/generator/c.ml
@@ -739,12 +739,9 @@ and generate_client_actions () =
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
-#include <string.h>
#include <inttypes.h>
-#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
-#include <assert.h>
#include \"guestfs.h\"
#include \"guestfs-internal.h\"
@@ -752,86 +749,6 @@ and generate_client_actions () =
#include \"guestfs_protocol.h\"
#include \"errnostring.h\"
-/* Check the return message from a call for validity. */
-static int
-check_reply_header (guestfs_h *g,
- const struct guestfs_message_header *hdr,
- unsigned int proc_nr, unsigned int serial)
-{
- if (hdr->prog != GUESTFS_PROGRAM) {
- error (g, \"wrong program (%%d/%%d)\", hdr->prog, GUESTFS_PROGRAM);
- return -1;
- }
- if (hdr->vers != GUESTFS_PROTOCOL_VERSION) {
- error (g, \"wrong protocol version (%%d/%%d)\",
- hdr->vers, GUESTFS_PROTOCOL_VERSION);
- return -1;
- }
- if (hdr->direction != GUESTFS_DIRECTION_REPLY) {
- error (g, \"unexpected message direction (%%d/%%d)\",
- hdr->direction, GUESTFS_DIRECTION_REPLY);
- return -1;
- }
- if (hdr->proc != proc_nr) {
- error (g, \"unexpected procedure number (%%d/%%d)\", hdr->proc, proc_nr);
- return -1;
- }
- if (hdr->serial != serial) {
- error (g, \"unexpected serial (%%d/%%d)\", hdr->serial, serial);
- return -1;
- }
-
- return 0;
-}
-
-/* Check the appliance is up when running a daemon_function. */
-static int
-check_appliance_up (guestfs_h *g, const char *caller)
-{
- if (guestfs__is_config (g) || guestfs__is_launching (g)) {
- error (g, \"%%s: call launch before using this function\\n(in guestfish, don't forget to use the 'run' command)\",
- caller);
- return -1;
- }
- return 0;
-}
-
-/* Convenience wrapper for tracing. */
-static FILE *
-trace_open (guestfs_h *g)
-{
- assert (g->trace_fp == NULL);
- g->trace_buf = NULL;
- g->trace_len = 0;
- g->trace_fp = open_memstream (&g->trace_buf, &g->trace_len);
- if (g->trace_fp)
- return g->trace_fp;
- else
- return stderr;
-}
-
-static void
-trace_send_line (guestfs_h *g)
-{
- char *buf;
- size_t len;
-
- if (g->trace_fp) {
- fclose (g->trace_fp);
- g->trace_fp = NULL;
-
- /* The callback might invoke other libguestfs calls, so keep
- * a copy of the pointer to the buffer and length.
- */
- buf = g->trace_buf;
- len = g->trace_len;
- g->trace_buf = NULL;
- guestfs___call_callbacks_message (g, GUESTFS_EVENT_TRACE, buf, len);
-
- free (buf);
- }
-}
-
";
(* Generate code for enter events. *)
@@ -959,7 +876,7 @@ trace_send_line (guestfs_h *g)
pr "\n"
);
- pr " trace_fp = trace_open (g);\n";
+ pr " trace_fp = guestfs___trace_open (g);\n";
pr " fprintf (trace_fp, \"%%s\", \"%s\");\n" name;
@@ -1028,7 +945,7 @@ trace_send_line (guestfs_h *g)
pr " }\n"
) optargs;
- pr " trace_send_line (g);\n";
+ pr " guestfs___trace_send_line (g);\n";
pr " }\n";
pr "\n";
in
@@ -1047,7 +964,7 @@ trace_send_line (guestfs_h *g)
pr "\n"
);
- pr "%s trace_fp = trace_open (g);\n" indent;
+ pr "%s trace_fp = guestfs___trace_open (g);\n" indent;
pr "%s fprintf (trace_fp, \"%%s = \", \"%s\");\n" indent name;
@@ -1083,7 +1000,7 @@ trace_send_line (guestfs_h *g)
pr "%s fprintf (trace_fp, \"<struct guestfs_%s_list *>\");\n"
indent typ (* XXX *)
);
- pr "%s trace_send_line (g);\n" indent;
+ pr "%s guestfs___trace_send_line (g);\n" indent;
pr "%s}\n" indent;
pr "\n";
in
@@ -1268,7 +1185,7 @@ trace_send_line (guestfs_h *g)
) args;
(* This is a daemon_function so check the appliance is up. *)
- pr " if (check_appliance_up (g, \"%s\") == -1) {\n" name;
+ pr " if (guestfs___check_appliance_up (g, \"%s\") == -1) {\n" name;
trace_return_error ~indent:4 name style errcode;
pr " return %s;\n" (string_of_errcode errcode);
pr " }\n";
@@ -1388,7 +1305,7 @@ trace_send_line (guestfs_h *g)
pr " }\n";
pr "\n";
- pr " if (check_reply_header (g, &hdr, GUESTFS_PROC_%s, serial) == -1) {\n"
+ pr " if (guestfs___check_reply_header (g, &hdr, GUESTFS_PROC_%s, serial) == -1) {\n"
(String.uppercase name);
trace_return_error ~indent:4 name style errcode;
pr " return %s;\n" (string_of_errcode errcode);