aboutsummaryrefslogtreecommitdiff
path: root/src/portal.cc
diff options
context:
space:
mode:
authorschnetter <schnetter@83718e91-0e4f-0410-abf4-91180603181f>2005-05-27 10:49:27 +0000
committerschnetter <schnetter@83718e91-0e4f-0410-abf4-91180603181f>2005-05-27 10:49:27 +0000
commitf7e4d7ae9de31669bcb700e02bba9e71c4c959e5 (patch)
tree6f9c455fca76e17a7750cb13b4b46616e0288f50 /src/portal.cc
parent3c42753983e5094afabe023e956ca30417e5d7df (diff)
Store the source tarballs into a subdirectory to remove clutter.
Restructure the announcing code so that there can be multiple announce targets. "Announce" to a file in the output directory by default. Also announce the list of active thorns and all parameter values. git-svn-id: http://svn.cactuscode.org/arrangements/CactusUtils/Formaline/trunk@14 83718e91-0e4f-0410-abf4-91180603181f
Diffstat (limited to 'src/portal.cc')
-rw-r--r--src/portal.cc194
1 files changed, 55 insertions, 139 deletions
diff --git a/src/portal.cc b/src/portal.cc
index b8faae7..5d36f5a 100644
--- a/src/portal.cc
+++ b/src/portal.cc
@@ -1,156 +1,72 @@
// $Header$
#include <cassert>
-#include <cstdio>
-#include <cstdlib>
-#include <cstring>
+#include <string>
+#include <sstream>
-#include "cctk.h"
-#include "cctk_Arguments.h"
#include "cctk_Parameters.h"
-#include "cctk_Version.h"
-#include "util_Network.h"
-#include "connection.hh"
+#include "portal.hh"
-extern "C"
-void
-Formaline_Portal (CCTK_ARGUMENTS)
+using std::string;
+using std::ostringstream;
+
+
+
+portal::
+portal (char const * const id)
{
- if (CCTK_MyProc (cctkGH) != 0) return;
-
- /* Create a unique job id */
- char const * restrict const jobid = "not unique";
-
- connection conn (jobid);
-
-
-
- /* Cactus */
-
- {
- char const * const cactus_version = CCTK_FullVersion();
- conn.store ("Cactus version", cactus_version);
- }
-
-
-
- /* Compiling */
-
-#if 0
- {
- char const * const compile_user = CCTK_CompileUser();
- conn.store ("compile user", compile_user);
- }
-#endif
-
- {
- char const * const compile_date = CCTK_CompileDate();
- conn.store ("compile date", compile_date);
- }
-
- {
- char const * const compile_time = CCTK_CompileTime();
- conn.store ("compile time", compile_time);
- }
-
-
-
- /* Running */
+ DECLARE_CCTK_PARAMETERS;
-#if 0
- {
- char const * const run_user = CCTK_RunUser();
- conn.store ("run user", run_user);
- }
-#else
- {
- char const * const run_user = getenv ("USER");
- conn.store ("run user", run_user);
- }
-#endif
+ sock = socket (PF_INET, SOCK_STREAM, 0);
+#warning "TODO: handle errors"
- {
- char run_date [1000];
- Util_CurrentDate (sizeof run_date, run_date);
- conn.store ("run date", run_date);
- }
+ struct hostent * hostinfo;
+ hostinfo = gethostbyname (portal_hostname);
+#warning "TODO: handle errors"
+ assert (hostinfo);
- {
- char run_time [1000];
- Util_CurrentTime (sizeof run_time, run_time);
- conn.store ("run time", run_time);
- }
+ struct sockaddr_in addr;
+ addr.sin_family = AF_INET;
+ addr.sin_port = portal_port;
+ addr.sin_addr = * (struct in_addr *) hostinfo->h_addr;
- {
- char run_host [1000];
- Util_GetHostName (run_host, sizeof run_host);
- conn.store ("run host", run_host);
- }
+ int const ierr
+ = connect (sock, (struct sockaddr const *) (& addr), sizeof addr);
+#warning "TODO: handle errors"
+ assert (! ERROR_CHECK (ierr));
- {
- int type;
- void const * const ptr
- = CCTK_ParameterGet ("run_title", "Cactus", & type);
- assert (type == CCTK_VARIABLE_STRING);
- char const * const run_title = static_cast<char const *> (ptr);
- conn.store ("run title", run_title);
- }
-
-
-
- /* Parameters */
-
- {
- char ** argv;
- int argc;
- int n;
- CCTK_CommandLine (& argv);
- for (argc = 0; argv [argc]; ++ argc);
- conn.store ("argc", argc);
- for (n = 0; n < argc; ++ n)
- {
- char buffer [1000];
- snprintf (buffer, sizeof buffer, "argv[%d]", n);
- conn.store (buffer, argv[n]);
- }
- }
-
- {
- char parameter_filename [10000];
- CCTK_ParameterFilename (sizeof parameter_filename, parameter_filename);
- conn.store ("parameter filename", parameter_filename);
- }
-
- {
- char parameter_filename [10000];
- char parameter_file [1000000];
- size_t count;
- FILE * file;
- CCTK_ParameterFilename (sizeof parameter_filename, parameter_filename);
- file = fopen (parameter_filename, "r");
- count = fread (parameter_file, 1, sizeof parameter_file - 1, file);
- fclose (file);
- assert (count < sizeof parameter_file - 1);
- parameter_file [count] = '\0';
- conn.store ("parameter file", parameter_file);
- }
-
- {
- int type;
- void const * const ptr
- = CCTK_ParameterGet ("out_dir", "IO", & type);
- assert (type == CCTK_VARIABLE_STRING);
- char const * const out_dir = static_cast<char const *> (ptr);
- conn.store ("out dir", out_dir);
- }
-
- {
- int nprocs;
- nprocs = CCTK_nProcs (cctkGH);
- conn.store ("nprocs", nprocs);
- }
+ ostringstream buf;
+ buf << "<simulation id=\"" << clean (id) << "\">\n";
+ write (buf.str());
+}
+
+
+
+portal::
+~ portal ()
+{
+ ostringstream buf;
+ buf << "</simulation>\n";
+ write (buf.str());
+ CLOSESOCKET (sock);
+#warning "TODO: handle errors"
+}
+
+
+
+void portal::
+write (string const & msg)
+{
+ char const * const cmsg = msg.c_str();
+
+ size_t const len = strlen (cmsg);
+ ssize_t const nelems = send (sock, cmsg, len, MSG_NOSIGNAL);
+ assert (! ERROR_CHECK (nelems));
+#warning "TODO: handle errors"
+#warning "TODO: handle overflow"
+ assert (nelems == len);
}