summaryrefslogtreecommitdiff
path: root/rld-process.h
diff options
context:
space:
mode:
authorChris Johns <chrisj@rtems.org>2014-08-05 23:01:15 +1000
committerChris Johns <chrisj@rtems.org>2014-08-05 23:01:15 +1000
commitf40cea54f3e7ef474552136b6f4b29cdb3b5c0f3 (patch)
tree961a51588821aa1ab1f712a314c7261324b3727c /rld-process.h
parent13ee8dc9506807fd3fb253b52583611754cb719e (diff)
Fix temporary file handling and add tempfile write support.
Move the static objects into the rld-process file and change the clean up to a call. Add support to write to tempfiles.
Diffstat (limited to 'rld-process.h')
-rw-r--r--rld-process.h73
1 files changed, 47 insertions, 26 deletions
diff --git a/rld-process.h b/rld-process.h
index 4f5be11..c50bb08 100644
--- a/rld-process.h
+++ b/rld-process.h
@@ -1,10 +1,10 @@
/*
- * Copyright (c) 2011, Chris Johns <chrisj@rtems.org>
+ * Copyright (c) 2011, Chris Johns <chrisj@rtems.org>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
- *
+ *
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
@@ -44,7 +44,7 @@ namespace rld
* Container of temporary file names.
*/
typedef std::list < std::string > tempfile_container;
-
+
/**
* Construct the temporary files.
*/
@@ -58,7 +58,7 @@ namespace rld
/**
* Get a new temporary file name.
*/
- const std::string get ();
+ const std::string get (const std::string& suffix = ".rldxx");
/**
* Remove the temporary file.
@@ -82,11 +82,6 @@ namespace rld
};
/**
- * The temporary files.
- */
- static temporary_files temporaries;
-
- /**
* Handle the output files from the process.
*/
class tempfile
@@ -96,7 +91,7 @@ namespace rld
/**
* Get a temporary file name.
*/
- tempfile ();
+ tempfile (const std::string& suffix = ".rldxx");
/**
* Clean up the temporary file.
@@ -104,9 +99,9 @@ namespace rld
~tempfile ();
/**
- * Open the temporary file.
+ * Open the temporary file. It can optionally be written too.
*/
- void open ();
+ void open (bool writable = false);
/**
* Close the temporary file.
@@ -124,20 +119,35 @@ namespace rld
size_t size ();
/**
- * Get all the file.
+ * Read all the file.
+ */
+ void read (std::string& all);
+
+ /**
+ * Read a line at a time.
+ */
+ void read_line (std::string& line);
+
+ /**
+ * Write the string to the file.
*/
- void get (std::string& all);
+ void write (const std::string& s);
/**
- * Get time.
+ * Write the string as a line to the file.
*/
- void getline (std::string& line);
+ void write_line (const std::string& s);
+
+ /**
+ * Write the strings to the file using a suitable line separator.
+ */
+ void write_lines (const rld::strings& ss);
/**
* Output the file.
*/
- void output (const std::string& prefix,
- std::ostream& out,
+ void output (const std::string& prefix,
+ std::ostream& out,
bool line_numbers = false);
/**
@@ -147,12 +157,23 @@ namespace rld
private:
- std::string _name; //< The name of the file.
- int fd; //< The file descriptor
- char buf[256]; //< The read buffer.
- int level; //< The level of data in the buffer.
+ std::string _name; //< The name of the file.
+ const std::string suffix; //< The temp file's suffix.
+ int fd; //< The file descriptor
+ char buf[256]; //< The read buffer.
+ int level; //< The level of data in the buffer.
};
-
+
+ /**
+ * Keep the temporary files.
+ */
+ void set_keep_temporary_files ();
+
+ /**
+ * Clean up the temporaryes.
+ */
+ void temporaries_clean_up ();
+
/**
* The arguments containter has a single argument per element.
*/
@@ -169,7 +190,7 @@ namespace rld
signal, //< The process terminated due to receipt of a signal.
stopped //< The process has not terminated, but has stopped and can be restarted.
};
-
+
types type; //< Type of status.
int code; //< The status code returned.
};
@@ -178,7 +199,7 @@ namespace rld
* Execute a process and capture stdout and stderr. The first element is
* the program name to run. Return an error code.
*/
- status execute (const std::string& pname,
+ status execute (const std::string& pname,
const arg_container& args,
const std::string& outname,
const std::string& errname);
@@ -187,7 +208,7 @@ namespace rld
* Execute a process and capture stdout and stderr given a command line
* string. Return an error code.
*/
- status execute (const std::string& pname,
+ status execute (const std::string& pname,
const std::string& command,
const std::string& outname,
const std::string& errname);