diff options
author | schnetter <schnetter@83718e91-0e4f-0410-abf4-91180603181f> | 2005-05-18 17:16:15 +0000 |
---|---|---|
committer | schnetter <schnetter@83718e91-0e4f-0410-abf4-91180603181f> | 2005-05-18 17:16:15 +0000 |
commit | 28ff3a5f5499b2c4c732dfabbb326a5f91271cd7 (patch) | |
tree | 754b2463ac8d9d60b335155b8045b4e710bf182a | |
parent | 1f9dc994fce18f5bc3c9524479aab3d4fa6affcd (diff) |
Replace dummy routines by socket routines that send the information to
a portal.
No error checking yet, though.
git-svn-id: http://svn.cactuscode.org/arrangements/CactusUtils/Formaline/trunk@4 83718e91-0e4f-0410-abf4-91180603181f
-rw-r--r-- | param.ccl | 21 | ||||
-rw-r--r-- | src/formaline.c | 206 |
2 files changed, 205 insertions, 22 deletions
@@ -1,2 +1,23 @@ # Parameter definitions for thorn Formaline # $Header$ + + + +BOOLEAN announce_to_portal "Announce to the portal" +{ +} yes + +STRING portal_hostname "Portal host name" +{ + "" :: "" +} "portal.cct.lsu.edu" + +INT portal_port "Portal port" +{ + 1:65535 :: "" +} 9296 + +STRING portal_username "User name on the portal" +{ + "" :: "" +} "" diff --git a/src/formaline.c b/src/formaline.c index 3718a65..22a61c5 100644 --- a/src/formaline.c +++ b/src/formaline.c @@ -3,31 +3,103 @@ #include <assert.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include "cctk.h" #include "cctk_Arguments.h" #include "cctk_Parameters.h" #include "cctk_Version.h" + #include "util_Network.h" +#ifdef HAVE_UNISTD_H +# include <unistd.h> +#endif +#ifdef HAVE_SYS_TIME_H +# include <sys/time.h> +#endif +#ifdef HAVE_SYS_TYPES_H +# include <sys/types.h> +#endif +#ifdef HAVE_SYS_SOCKET_H +# include <sys/socket.h> +#endif +#ifdef HAVE_NETINET_IN_H +# include <netinet/in.h> +#endif +#ifdef HAVE_NETDB_H +# include <netdb.h> +#endif +#ifdef HAVE_ARPA_INET_H +# include <arpa/inet.h> +#endif +#ifdef HAVE_WINSOCK2_H +# include <winsock2.h> +#endif +#include <errno.h> + +#ifndef SOCKET +# define SOCKET int +#endif + +#ifdef SOCKET_ERROR +# define ERROR_CHECK(a) ((a) == SOCKET_ERROR) +#else +# define ERROR_CHECK(a) ((a) < 0) +#endif + +#ifdef HAVE_WINSOCK2_H +# define CLOSESOCKET(a) closesocket(a) +#else +# define CLOSESOCKET(a) close(a) +#endif + +#ifndef MSG_NOSIGNAL +# define MSG_NOSIGNAL 0 +#endif + + + +struct connection; + +static struct connection * +OpenConnection (char const * id); + +static void +CloseConnection (struct connection * conn); + +static void +WriteToConnection (struct connection * conn, + char const * msg); + static void -StoreIntKey (char const * key, int value); +StoreIntKey (struct connection * conn, + char const * key, + int value); static void -StoreStringKey (char const * key, char const * value); +StoreStringKey (struct connection *, + char const * key, + char const * value); void Formaline (CCTK_ARGUMENTS) { + /* Create a unique job id */ + char const * restrict const jobid = "not unique"; + + struct connection * restrict const conn = OpenConnection (jobid); + assert (conn); + /* Cactus */ { char const * const cactus_version = CCTK_FullVersion(); - StoreStringKey ("Cactus version", cactus_version); + StoreStringKey (conn, "Cactus version", cactus_version); } @@ -36,17 +108,17 @@ Formaline (CCTK_ARGUMENTS) { char const * const compile_user = CCTK_CompileUser(); - StoreStringKey ("compile user", compile_user); + StoreStringKey (conn, "compile user", compile_user); } { char const * const compile_date = CCTK_CompileDate(); - StoreStringKey ("compile date", compile_date); + StoreStringKey (conn, "compile date", compile_date); } { char const * const compile_time = CCTK_CompileTime(); - StoreStringKey ("compile time", compile_time); + StoreStringKey (conn, "compile time", compile_time); } @@ -55,25 +127,25 @@ Formaline (CCTK_ARGUMENTS) { char const * const run_user = CCTK_RunUser(); - StoreStringKey ("run user", run_user); + StoreStringKey (conn, "run user", run_user); } { char run_date [1000]; Util_CurrentDate (sizeof run_date, run_date); - StoreStringKey ("run date", run_date); + StoreStringKey (conn, "run date", run_date); } { char run_time [1000]; Util_CurrentTime (sizeof run_time, run_time); - StoreStringKey ("run time", run_time); + StoreStringKey (conn, "run time", run_time); } { char run_host [1000]; Util_GetHostName (run_host, sizeof run_host); - StoreStringKey ("run host", run_host); + StoreStringKey (conn, "run host", run_host); } { @@ -81,7 +153,7 @@ Formaline (CCTK_ARGUMENTS) int type; run_title = CCTK_ParameterGet ("run_title", "Cactus", & type); assert (type == CCTK_VARIABLE_STRING); - StoreStringKey ("run title", run_title); + StoreStringKey (conn, "run title", run_title); } @@ -94,19 +166,19 @@ Formaline (CCTK_ARGUMENTS) int n; CCTK_CommandLine (& argv); for (argc = 0; argv [argc]; ++ argc); - StoreIntKey ("argc", argc); + StoreIntKey (conn, "argc", argc); for (n = 0; n < argc; ++ n) { char buffer [1000]; snprintf (buffer, sizeof buffer, "argv[%d]", n); - StoreStringKey (buffer, argv[n]); + StoreStringKey (conn, buffer, argv[n]); } } { char parameter_filename [10000]; CCTK_ParameterFilename (sizeof parameter_filename, parameter_filename); - StoreStringKey ("parameter filename", parameter_filename); + StoreStringKey (conn, "parameter filename", parameter_filename); } { @@ -120,7 +192,7 @@ Formaline (CCTK_ARGUMENTS) fclose (file); assert (count < sizeof parameter_file - 1); parameter_file [count] = '\0'; - StoreStringKey ("parameter file", parameter_file); + StoreStringKey (conn, "parameter file", parameter_file); } { @@ -128,33 +200,123 @@ Formaline (CCTK_ARGUMENTS) int type; out_dir = CCTK_ParameterGet ("out_dir", "IO", & type); assert (type == CCTK_VARIABLE_STRING); - StoreStringKey ("out dir", out_dir); + StoreStringKey (conn, "out dir", out_dir); } { int nprocs; nprocs = CCTK_nProcs (cctkGH); - StoreIntKey ("nprocs", nprocs); + StoreIntKey (conn, "nprocs", nprocs); } + + CloseConnection (conn); } -/* Dummy implementations */ +/* + <simulation id="ID"> + <key>key</key> <value>value</value> + </simulation> + */ + + + +struct connection { + SOCKET socket; +}; + +static struct connection * +OpenConnection (char const * restrict const id) +{ + DECLARE_CCTK_PARAMETERS; + struct connection * const conn = malloc (sizeof * conn); +#warning "TODO: handle errors" + assert (conn); + + conn->socket = socket (PF_INET, SOCK_STREAM, 0); +#warning "TODO: handle errors" + + struct hostent * hostinfo; + hostinfo = gethostbyname (portal_hostname); +#warning "TODO: handle errors" + assert (hostinfo); + + struct sockaddr_in addr; + addr.sin_family = AF_INET; + addr.sin_port = portal_port; + addr.sin_addr = * (struct in_addr *) hostinfo->h_addr; + + int const ierr = connect (conn->socket, & addr, sizeof addr); +#warning "TODO: handle errors" + assert (! ERROR_CHECK (ierr)); + + char buf[1000]; + snprintf (buf, sizeof buf, "<simulation id=\"%s\">\n", id); + WriteToConnection (conn, buf); + + return conn; +} + +static void +CloseConnection (struct connection * restrict const conn) +{ + assert (conn); + + char buf[1000]; + snprintf (buf, sizeof buf, "</simulation>\n"); + WriteToConnection (conn, buf); + + CLOSESOCKET (conn->socket); +#warning "TODO: handle errors" + + free (conn); +} + +static void +WriteToConnection (struct connection * restrict const conn, + char const * restrict const msg) +{ + assert (conn); + assert (msg); + + size_t const len = strlen (msg); + ssize_t const nelems = send (conn, msg, len, MSG_NOSIGNAL); + assert (! ERROR_CHECK (nelems)); +#warning "TODO: handle errors" +#warning "TODO: handle overflow" + assert (nelems == len); +} + + static void -StoreIntKey (char const * const key, int const value) +StoreIntKey (struct connection * restrict const conn, + char const * restrict const key, + int const value) { + assert (conn); assert (key); - /* Do nothing */ + char buf[1000]; +#warning "TODO: quote key and value" + snprintf (buf, sizeof buf, "<key>%s</key> <value>%d</value>\n", key, value); +#warning "TODO: handle overflow" + WriteToConnection (conn, buf); } static void -StoreStringKey (char const * const key, char const * const value) +StoreStringKey (struct connection * restrict const conn, + char const * restrict const key, + char const * restrict const value) { + assert (conn); assert (key); assert (value); - /* Do nothing */ + char buf[1000]; +#warning "TODO: quote key and value" + snprintf (buf, sizeof buf, "<key>%s</key> <value>%s</value>\n", key, value); +#warning "TODO: handle overflow" + WriteToConnection (conn, buf); } |