#include <stdio.h>#include <unistd.h>#include <stdlib.h>#include <sys/types.h>#include <sys/socket.h>#include <netdb.h>#include <netinet/in.h>#include <arpa/inet.h>#include <netinet/tcp.h>#include <errno.h>#include "msgLog.h"#include <string.h>#include "rototalk.h"#include "rotoMessages.h"Go to the source code of this file.
Classes | |
| struct | roto_conn |
| struct | roto_dcsfile |
| struct | roto_beammonfile |
Defines | |
| #define | MINBUFFERSIZE 2*1024*1024 |
| #define | REPLYBUFFERSIZE 4096 |
| #define | ctorRooterCmd(cmd) |
Typedefs | |
| typedef long int | rotocmd |
Functions | |
| rotocmd | roto_complete_cmd (rotocmd cmd, int whoami) |
| int | roto_send_command (rotocmd cmd, const void *buffer, int nsendbytes) |
| int | roto_set_std_file_status (rotocmd cmd, int entity, int det, int tag1, int tag2) |
| int | roto_set_named_file_status (rotocmd cmd, const char *fname) |
| int | roto_recv_cmdreply (rotocmd cmd) |
| int | roto_check_ack (rotocmd cmd, int ack) |
| int | roto_recv_reqreply (rotocmd cmd) |
| int | roto_reallocate_sendbuffer (int minsize) |
| int | roto_readn (int fd, char *ptr, int nbytes) |
| int | roto_writen (int fd, const char *ptr, int nbytes) |
| int | roto_open_DCP_connection (const char *host) |
| int | roto_open_DCS_connection (const char *host) |
| int | roto_open_BeamMon_connection (const char *host) |
| int | roto_open_connection (const char *host, int port, int whoami) |
| int | roto_set_connection_nodelay (int val) |
| int | roto_close_connection () |
| int | roto_send_record (const void *buffer, int nbytes) |
| int | roto_send_autosave_config (const char *stream, unsigned int nrec, unsigned int nsec) |
| int | roto_send_compress_config (const char *stream, int level) |
| int | roto_send_basketsize_config (const char *stream, int bsize) |
| int | roto_open_daqfile (int detector, int run, int subrun) |
| int | roto_close_daqfile (int detector, int run, int subrun) |
| int | roto_open_dcsfile (int detector, int sec, int nsec) |
| int | roto_close_dcsfile () |
| int | roto_open_beammonfile (int sec, int nsec) |
| int | roto_close_beammonfile () |
| int | roto_open_named_file (const char *fname) |
| int | roto_close_named_file (const char *fname) |
| int | roto_request_shutdown (int priority) |
Variables | |
| int | roto_verbose = 0 |
| int | iam = 0 |
| roto_conn | g_roto_conn |
| roto_dcsfile | g_roto_dcsfile |
| roto_beammonfile | g_roto_beammonfile |
| int | last_ack |
| int | last_statereport |
| int | sendbuffer_size = 0 |
| char * | sendbuffer = 0 |
| long int * | cmdword |
| long int * | sizeword |
| char * | datastart |
| char | replybuffer [REPLYBUFFERSIZE] |
| const long int | roto_connect = ctorRooterCmd(MINOS_ROOTER_OPENSOCKET) |
| const long int | roto_disconn = ctorRooterCmd(MINOS_ROOTER_CLOSESOCKET) |
| const long int | roto_openf = ctorRooterCmd(MINOS_ROOTER_OPENFILE) |
| const long int | roto_closef = ctorRooterCmd(MINOS_ROOTER_CLOSEFILE) |
| const long int | roto_recbuff = ctorRooterCmd(MINOS_ROOTER_RECBUFFER) |
| const long int | roto_shutdown = ctorRooterCmd(MINOS_ROOTER_SHUTDOWN) |
| const long int | roto_config = ctorRooterCmd(MINOS_ROOTER_CONFIG) |
| const long int | roto_datatofollow = RC_DATAFLAG_MASK |
|
|
Value: ( MINOS_ROOTER_ROOTER << RC_TO_BITPOS | \ MINOS_ROOTER_COMMAND << RC_TYPE_BITPOS | \ cmd ) Definition at line 115 of file rototalk.c. |
|
|
Definition at line 98 of file rototalk.c. |
|
|
Definition at line 104 of file rototalk.c. |
|
|
Definition at line 163 of file rototalk.c. Referenced by roto_close_connection(), roto_complete_cmd(), roto_open_connection(), roto_request_shutdown(), roto_send_autosave_config(), roto_send_basketsize_config(), roto_send_compress_config(), and roto_send_record(). |
|
||||||||||||
|
Definition at line 1261 of file rototalk.c. References MINOS_ROOTER_ACKNOWLEDGE, RC_FROM_BITPOS, RC_TO_BITPOS, RC_TYPE_BITPOS, and rototalk_success. Referenced by roto_recv_cmdreply(). 01262 {
01263 int oldfrom = (cmd & RC_FROM_MASK) >> RC_FROM_BITPOS;
01264 int oldto = (cmd & RC_TO_MASK) >> RC_TO_BITPOS;
01265 /* int oldtype = (cmd & RC_TYPE_MASK) >> RC_TYPE_BITPOS; */
01266 int oldinstr = (cmd & RC_COMMAND_MASK) >> RC_COMMAND_BITPOS;
01267
01268 /*
01269 * swap "to" and "from"
01270 * type should be ACK
01271 * same command
01272 */
01273 int expect = oldfrom << RC_TO_BITPOS |
01274 oldto << RC_FROM_BITPOS |
01275 MINOS_ROOTER_ACKNOWLEDGE << RC_TYPE_BITPOS |
01276 oldinstr << RC_COMMAND_BITPOS;
01277
01278 return (expect == ack) ? rototalk_success : rototalk_err_nack;
01279
01280 }
|
|
|
Definition at line 836 of file rototalk.c. References g_roto_beammonfile, MINOS_ROOTER_BEAMMON, roto_beammonfile::nsec, roto_closef, roto_set_std_file_status(), and roto_beammonfile::sec. Referenced by BeamData::close_file(), RotoClient::CloseBeamMonFile(), roto_open_beammonfile(), and send_bogus_stuff(). 00837 {
00838 int err;
00839 err = roto_set_std_file_status(roto_closef,MINOS_ROOTER_BEAMMON,0,
00840 g_roto_beammonfile.sec,
00841 g_roto_beammonfile.nsec);
00842
00843 if (!err) {
00844 g_roto_beammonfile.sec = 0;
00845 g_roto_beammonfile.nsec = 0;
00846 }
00847 return err;
00848 }
|
|
|
Definition at line 401 of file rototalk.c. References roto_conn::conn_host, roto_conn::conn_nrec_sent, roto_conn::conn_port, roto_conn::conn_socketfd, g_roto_conn, iam, logError(), logInfo(), roto_complete_cmd(), roto_disconn, roto_recv_cmdreply(), roto_send_command(), roto_verbose, and rotocmd. Referenced by BeamData::close_connection(), RotoClient::CloseConnection(), and main(). 00402 {
00403 rotocmd cmd;
00404 int err;
00405
00406 /*
00407 * complain if we aren't actually connected
00408 */
00409 if (g_roto_conn.conn_socketfd<0) {
00410 logError("roto_close_connection: not connected");
00411 return rototalk_err_notconnected;
00412 }
00413
00414 /*
00415 * Send "command" in fashion similar to run control protocol
00416 */
00417 cmd = roto_complete_cmd(roto_disconn,iam);
00418 err = roto_send_command(cmd,0,0);
00419 if (err) return err;
00420 /*
00421 * Get the command reply (ACK|NACK + state report)
00422 */
00423 err = roto_recv_cmdreply(cmd);
00424
00425 /* vicious (cf. man -S 2 shutdown) without regard to further send/receives
00426 shutdown(conn_socket,2)
00427 */
00428
00429 /*
00430 * friendly closing of the socket
00431 */
00432 errno = 0;
00433 while ( close(g_roto_conn.conn_socketfd) == -1 &&
00434 errno == EINTR ) errno = 0;
00435
00436 /*
00437 * make a note that we're not connected
00438 */
00439 g_roto_conn.conn_socketfd = -1;
00440 strcpy(g_roto_conn.conn_host,"no-longer-connected");
00441 g_roto_conn.conn_port = 0;
00442 g_roto_conn.conn_nrec_sent = 0;
00443
00444 if (roto_verbose>0)
00445 logInfo("roto_close_connection requested");
00446
00447 return err;
00448 }
|
|
||||||||||||||||
|
Definition at line 674 of file rototalk.c. References MINOS_ROOTER_DCP, roto_closef, roto_set_std_file_status(), and run(). Referenced by RotoClient::CloseDAQFile(). 00675 {
00676 return roto_set_std_file_status(roto_closef,MINOS_ROOTER_DCP,
00677 detector,run,subrun);
00678 }
|
|
|
Definition at line 751 of file rototalk.c. References roto_dcsfile::detector, g_roto_dcsfile, MINOS_ROOTER_DCS, roto_dcsfile::nsec, roto_closef, roto_set_std_file_status(), and roto_dcsfile::sec. Referenced by RotoClient::CloseDCSFile(), and roto_open_dcsfile(). 00752 {
00753 int err;
00754 err = roto_set_std_file_status(roto_closef,MINOS_ROOTER_DCS,
00755 g_roto_dcsfile.detector,
00756 g_roto_dcsfile.sec,
00757 g_roto_dcsfile.nsec);
00758
00759 if (!err) {
00760 g_roto_dcsfile.detector = 0;
00761 g_roto_dcsfile.sec = 0;
00762 g_roto_dcsfile.nsec = 0;
00763 }
00764 return err;
00765 }
|
|
|
Definition at line 883 of file rototalk.c. References roto_closef, and roto_set_named_file_status(). Referenced by RotoClient::CloseFile(), and send_whole_file(). 00884 {
00885 return roto_set_named_file_status(roto_closef,fname);
00886 }
|
|
||||||||||||
|
Definition at line 1082 of file rototalk.c. References rotocmd. Referenced by roto_close_connection(), roto_open_connection(), roto_request_shutdown(), roto_send_autosave_config(), roto_send_basketsize_config(), roto_send_compress_config(), roto_send_record(), roto_set_named_file_status(), and roto_set_std_file_status(). 01083 {
01084 return ((whoami<< RC_FROM_BITPOS) | cmd);
01085 }
|
|
|
Definition at line 203 of file rototalk.c. References MINOS_ROOTER_BEAMMON, ROOTER_PORT_BEAMMON, and roto_open_connection(). Referenced by main(), and BeamData::open_connection(). 00204 {
00205 return roto_open_connection(host,ROOTER_PORT_BEAMMON,MINOS_ROOTER_BEAMMON);
00206 }
|
|
||||||||||||
|
Definition at line 785 of file rototalk.c. References g_roto_beammonfile, logError(), MINOS_ROOTER_BEAMMON, roto_beammonfile::nsec, roto_close_beammonfile(), roto_openf, roto_set_std_file_status(), and roto_beammonfile::sec. Referenced by BeamData::open_file(), RotoClient::OpenBeamMonFile(), and send_bogus_stuff(). 00786 {
00787 int err;
00788
00789 if (g_roto_beammonfile.sec != 0 ||
00790 g_roto_beammonfile.nsec != 0 ) {
00791 /* a file is already open */
00792
00793 if (g_roto_beammonfile.sec == sec ||
00794 g_roto_beammonfile.nsec == nsec ) {
00795 /* do nothing, requested the same file ... */
00796 return rototalk_success;
00797 }
00798
00799 /* a different file is already open! */
00800 logError("roto_open_beammonfile:");
00801 logError(" a file (0x%8.8x 0x%8.8x) is already open",
00802 g_roto_beammonfile.sec,g_roto_beammonfile.nsec);
00803 logError(" close it and open (0x%8.8x 0x%8.8x)",
00804 sec,nsec);
00805 roto_close_beammonfile();
00806 }
00807
00808
00809 err = roto_set_std_file_status(roto_openf,MINOS_ROOTER_BEAMMON,
00810 0,sec,nsec);
00811 if (!err) {
00812 g_roto_beammonfile.sec = sec;
00813 g_roto_beammonfile.nsec = nsec;
00814 }
00815
00816 return err;
00817 }
|
|
||||||||||||||||
|
Definition at line 224 of file rototalk.c. References roto_conn::conn_host, roto_conn::conn_nrec_sent, roto_conn::conn_port, roto_conn::conn_socketfd, g_roto_conn, iam, logDebug(), logError(), logInfo(), logWarn(), MINOS_ROOTER_BEAMMON, MINOS_ROOTER_DCP, MINOS_ROOTER_DCS, port, roto_complete_cmd(), roto_connect, roto_recv_cmdreply(), roto_send_command(), roto_set_connection_nodelay(), roto_verbose, and rotocmd. Referenced by main(), roto_open_BeamMon_connection(), roto_open_DCP_connection(), roto_open_DCS_connection(), and RotoClient::SetupConnection(). 00225 {
00226 const char *whoami_name = "unknown";
00227 int socketfd = 0;
00228 struct hostent *host_ptr;
00229 struct sockaddr_in serv_addr;
00230 unsigned long int addr; /* good for 4 byte address */
00231 struct in_addr ad;
00232
00233 int err;
00234 rotocmd cmd;
00235
00236 switch (whoami) {
00237 case MINOS_ROOTER_DCP: whoami_name = "DCP"; break;
00238 case MINOS_ROOTER_DCS: whoami_name = "DCS"; break;
00239 case MINOS_ROOTER_BEAMMON: whoami_name = "BeamMon"; break;
00240 default:
00241 logError("roto_open_connection: whoami 0x%02x is not allowed",whoami);
00242 return rototalk_err_whoami;
00243 }
00244 iam = whoami;
00245
00246 if (g_roto_conn.conn_socketfd>0) {
00247 logError("roto_open_connection: already established to %s:%d",
00248 g_roto_conn.conn_host,g_roto_conn.conn_port);
00249
00250 /*
00251 * should we close that connection and reopen
00252 * or simply return a failure??
00253 * ... for now simply leave existing one open
00254 */
00255 return rototalk_err_alreadyconn;
00256 }
00257
00258 /*
00259 * code based on both:
00260 * Unix Network Programming, W. Richard Stevens, Prentice Hall, pg 286
00261 * ROOT TSocket and TUnixSystem classes
00262 */
00263
00264 /*
00265 * prepare the address structure
00266 */
00267
00268 memset(&serv_addr,0,sizeof(serv_addr)); /* clear the structure */
00269 #ifdef HASNOT_INETATON
00270 logWarn("roto_open_connection: using obsolete inet_addr() function");
00271
00272 if ((addr = (unsigned long int)inet_addr(host))
00273 != INADDR_NONE) {
00274 #else
00275 if (inet_aton(host, &ad)) {
00276 memcpy(&addr, &ad.s_addr, sizeof(ad.s_addr));
00277 #endif
00278 if (!(host_ptr = gethostbyaddr((const char *)&addr,
00279 sizeof(addr), AF_INET))) {
00280 /* unnamed host */
00281 }
00282 }
00283 else if ((host_ptr = gethostbyname(host))) {
00284 logDebug(3,"roto_open_connection: resorted to gethostbyname");
00285 }
00286 if (!host_ptr) {
00287 logError("roto_open_connection: unknown host %s",host);
00288 return rototalk_err_unknownhost;
00289 }
00290 if (host_ptr->h_addrtype != AF_INET) {
00291 logError("roto_open_connection: %s not an internet host",host);
00292 return rototalk_err_notinethost;
00293 }
00294
00295 /*
00296 * Magic incantation
00297 */
00298 memcpy(&addr,host_ptr->h_addr,host_ptr->h_length);
00299 serv_addr.sin_family = AF_INET;
00300 serv_addr.sin_addr.s_addr = addr;
00301 serv_addr.sin_port = htons(port);
00302
00303 /*
00304 * Open the TCP socket (an Internet stream socket)
00305 */
00306 if ( (socketfd = socket(AF_INET,SOCK_STREAM, 0)) < 0 ) {
00307 logError("roto_open_connection: failed to open socket");
00308 return rototalk_err_socketfail;
00309 }
00310
00311 /*
00312 * Connect to the server
00313 */
00314 if (connect(socketfd,(struct sockaddr *)&serv_addr,sizeof(serv_addr)) < 0) {
00315 logError("roto_open_connection: can't connect");
00316 logError(" host '%s' expanded '%s' port %d",host,host_ptr->h_name,port);
00317 logError(" sin_addr.s_addr 0x%8.8x sin_port 0x%4.4x",
00318 serv_addr.sin_addr.s_addr,serv_addr.sin_port);
00319 return rototalk_err_connectfail;
00320 }
00321
00322 /*
00323 * Save a copy of who we're connected to
00324 */
00325 g_roto_conn.conn_socketfd = socketfd;
00326 strcpy(g_roto_conn.conn_host,host_ptr->h_name); /* copy the expanded name */
00327 g_roto_conn.conn_port = port;
00328 g_roto_conn.conn_nrec_sent = 0;
00329
00330 /*
00331 * by default make connection use TCP_NODELAY
00332 */
00333 roto_set_connection_nodelay(1);
00334
00335 if (roto_verbose>0) {
00336 logInfo("roto_open_connection: %s:%d, i am '%s'",
00337 host,port,whoami_name);
00338 }
00339
00340 /*
00341 * Send "command" in fashion similar to run control protocol
00342 */
00343 cmd = roto_complete_cmd(roto_connect,iam);
00344 err = roto_send_command(cmd,0,0);
00345 if (err) return err;
00346 /*
00347 * Get the command reply (ACK|NACK + state report)
00348 */
00349 return roto_recv_cmdreply(cmd);
00350 }
|
|
||||||||||||||||
|
Definition at line 653 of file rototalk.c. References MINOS_ROOTER_DCP, roto_openf, roto_set_std_file_status(), and run(). Referenced by RotoClient::OpenDAQFile(). 00654 {
00655 return roto_set_std_file_status(roto_openf,MINOS_ROOTER_DCP,
00656 detector,run,subrun);
00657 }
|
|
|
Definition at line 195 of file rototalk.c. References MINOS_ROOTER_DCP, ROOTER_PORT_DAQ, and roto_open_connection(). Referenced by main(). 00196 {
00197 return roto_open_connection(host,ROOTER_PORT_DAQ,MINOS_ROOTER_DCP);
00198 }
|
|
|
Definition at line 199 of file rototalk.c. References MINOS_ROOTER_DCS, ROOTER_PORT_DCS, and roto_open_connection(). Referenced by main(). 00200 {
00201 return roto_open_connection(host,ROOTER_PORT_DCS,MINOS_ROOTER_DCS);
00202 }
|
|
||||||||||||||||
|
Definition at line 698 of file rototalk.c. References roto_dcsfile::detector, g_roto_dcsfile, logError(), MINOS_ROOTER_DCS, roto_dcsfile::nsec, roto_close_dcsfile(), roto_openf, roto_set_std_file_status(), and roto_dcsfile::sec. Referenced by RotoClient::OpenDCSFile(). 00699 {
00700 int err;
00701
00702 if (g_roto_dcsfile.detector != 0 ||
00703 g_roto_dcsfile.sec != 0 ||
00704 g_roto_dcsfile.nsec != 0 ) {
00705 /* a file is already open */
00706
00707 if (g_roto_dcsfile.detector == detector ||
00708 g_roto_dcsfile.sec == sec ||
00709 g_roto_dcsfile.nsec == nsec ) {
00710 /* do nothing, requested the same file ... */
00711 return rototalk_success;
00712 }
00713
00714 /* a different file is already open! */
00715 logError("roto_open_dcsfile:");
00716 logError(" a file (0x%2.2x 0x%8.8x 0x%8.8x) is already open",
00717 g_roto_dcsfile.detector,g_roto_dcsfile.sec,g_roto_dcsfile.nsec);
00718 logError(" close it and open (0x%2.2x 0x%8.8x 0x%8.8x)",
00719 detector,sec,nsec);
00720 roto_close_dcsfile();
00721 }
00722
00723 err = roto_set_std_file_status(roto_openf,MINOS_ROOTER_DCS,
00724 detector,sec,nsec);
00725 if (!err) {
00726 g_roto_dcsfile.detector = detector;
00727 g_roto_dcsfile.sec = sec;
00728 g_roto_dcsfile.nsec = nsec;
00729 }
00730
00731 return err;
00732 }
|
|
|
Definition at line 864 of file rototalk.c. References roto_openf, and roto_set_named_file_status(). Referenced by RotoClient::OpenFile(), and send_whole_file(). 00865 {
00866 return roto_set_named_file_status(roto_openf,fname);
00867 }
|
|
||||||||||||||||
|
Definition at line 1377 of file rototalk.c. Referenced by roto_recv_cmdreply(). 01378 {
01379 int nleft, nread;
01380
01381 nleft = nbytes;
01382 while (nleft > 0) {
01383 nread = read(fd, ptr, nleft);
01384 if (nread < 0) return nread; /* error, return < 0 */
01385 else if (nread == 0) break; /* EOF */
01386 nleft -= nread;
01387 ptr += nread;
01388 }
01389 return (nbytes-nleft); /* return >= 0 */
01390 }
|
|
|
Definition at line 1319 of file rototalk.c. References cmdword, datastart, logError(), logInfo(), sendbuffer, sendbuffer_size, and sizeword. Referenced by roto_send_command(). 01320 {
01321 int oldsize = sendbuffer_size;
01322 int mrequest = minsize;
01323 int failures = 0;
01324
01325 if (sendbuffer) {
01326 free(sendbuffer); /* release existing buffer */
01327 sendbuffer = 0;
01328 }
01329
01330 /* set absolute mimimum */
01331 if (mrequest<MINBUFFERSIZE) mrequest = MINBUFFERSIZE;
01332
01333 while ( ! sendbuffer ) {
01334 sendbuffer = (char*)malloc(mrequest);
01335 if (sendbuffer) break; /* success !!! */
01336 failures++;
01337 mrequest -= 1024*sizeof(char); /* failed, try smaller size */
01338 }
01339 sendbuffer_size = mrequest;
01340
01341 /* set pointers to short cuts */
01342 cmdword = (long int*)sendbuffer;
01343 sizeword = cmdword + 1;
01344 datastart = sendbuffer + 2*sizeof(long int);
01345
01346 if (sendbuffer_size<minsize) {
01347 logError("roto_reallocate_sendbuffer: from %d to %d failed, only have %d",
01348 oldsize,minsize,sendbuffer_size);
01349 return rototalk_err_reallocate;
01350 }
01351 else {
01352 logInfo("roto_reallocate_sendbuffer: from %d to %d",
01353 oldsize,sendbuffer_size);
01354 return rototalk_success;
01355 }
01356 }
|
|
|
Definition at line 1165 of file rototalk.c. References roto_conn::conn_socketfd, g_roto_conn, last_ack, last_statereport, logError(), replybuffer, roto_check_ack(), and roto_readn(). Referenced by roto_close_connection(), roto_open_connection(), roto_request_shutdown(), roto_send_autosave_config(), roto_send_basketsize_config(), roto_send_compress_config(), roto_send_record(), roto_set_named_file_status(), and roto_set_std_file_status(). 01166 {
01167 int nread;
01168 int nreply;
01169
01170 if (g_roto_conn.conn_socketfd<0) {
01171 logError("roto_recv_cmdreply: not connected");
01172 return rototalk_err_notconnected;
01173 }
01174
01175 /*
01176 * Read the ACK/NACK
01177 */
01178 nread = roto_readn(g_roto_conn.conn_socketfd,(char*)&last_ack,sizeof(int));
01179 if (nread != sizeof(int)) return rototalk_err_badrecvack;
01180 if (last_ack & roto_datatofollow) {
01181 /* there was some reply data ... how odd */
01182 nread = roto_readn(g_roto_conn.conn_socketfd,
01183 (char*)&nreply,sizeof(int));
01184 if (nread != sizeof(int)) return rototalk_err_badrecvacksize;
01185 nreply -= sizeof(int); /* byte count is inclusive */
01186 nread = roto_readn(g_roto_conn.conn_socketfd,
01187 (char*)replybuffer,nreply);
01188 if (nreply != nread) return rototalk_err_badrecvackdata;
01189 }
01190
01191 /*
01192 * Read the state report
01193 */
01194 nread = roto_readn(g_roto_conn.conn_socketfd,
01195 (char*)&last_statereport,sizeof(int));
01196 if (nread != sizeof(int)) return rototalk_err_badrecvstate;
01197
01198 /*
01199 * Verify that we got a proper ACK
01200 */
01201 return roto_check_ack(cmd,last_ack);
01202 }
|
|
|
|
|
|
Definition at line 1219 of file rototalk.c. References roto_conn::conn_socketfd, g_roto_conn, iam, logError(), logNotice(), roto_complete_cmd(), roto_recv_cmdreply(), roto_send_command(), roto_shutdown, roto_verbose, and rotocmd. Referenced by main(), and RotoClient::SendShutdownMessage(). 01220 {
01221 rotocmd cmd;
01222 int err;
01223
01224 if (g_roto_conn.conn_socketfd<0) {
01225 logError("roto_request_shutdown: not connected");
01226 return rototalk_err_notconnected;
01227 }
01228
01229 /*
01230 * Send "command" in fashion similar to run control protocol
01231 */
01232 cmd = roto_complete_cmd(roto_shutdown,iam);
01233 err = roto_send_command(cmd,&priority,sizeof(int));
01234 if (err) return err;
01235
01236 if (roto_verbose>0)
01237 logNotice("roto_request_shutdown (priority=%d)",priority);
01238
01239 /*
01240 * Get the command reply (ACK|NACK + state report)
01241 */
01242 return roto_recv_cmdreply(cmd);
01243
01244 }
|
|
||||||||||||||||
|
Definition at line 510 of file rototalk.c. References roto_conn::conn_socketfd, g_roto_conn, iam, logDebug(), logError(), roto_complete_cmd(), roto_config, roto_recv_cmdreply(), roto_send_command(), roto_verbose, and rotocmd. 00511 {
00512 rotocmd cmd;
00513 int err;
00514 char minibuffer[4096];
00515
00516 if (g_roto_conn.conn_socketfd<0) {
00517 logError("roto_send_autosave_config: not connected");
00518 return rototalk_err_notconnected;
00519 }
00520
00521 if (roto_verbose>1)
00522 logDebug(2,"roto_send_autosave_config: stream \"%s\" - %d rec, %d sec",
00523 stream,nrec,nsec);
00524
00525 /* format the config */
00526 sprintf(minibuffer,"config autosave: %s = %d rec %d sec",stream,nrec,nsec);
00527
00528 /*
00529 * Send "command" in fashion similar to run control protocol
00530 */
00531 cmd = roto_complete_cmd(roto_config,iam);
00532 err = roto_send_command(cmd,minibuffer,strlen(minibuffer));
00533 if (err) return err;
00534 /*
00535 * Get the command reply (ACK|NACK + state report)
00536 */
00537 return roto_recv_cmdreply(cmd);
00538 }
|
|
||||||||||||
|
Definition at line 604 of file rototalk.c. References roto_conn::conn_socketfd, g_roto_conn, iam, logDebug(), logError(), roto_complete_cmd(), roto_config, roto_recv_cmdreply(), roto_send_command(), roto_verbose, and rotocmd. 00605 {
00606 rotocmd cmd;
00607 int err;
00608 char minibuffer[4096];
00609
00610 if (g_roto_conn.conn_socketfd<0) {
00611 logError("roto_send_basketsize_config: not connected");
00612 return rototalk_err_notconnected;
00613 }
00614
00615 if (roto_verbose>1)
00616 logDebug(2,"roto_send_basketsize_config: stream \"%s\" - basketsize %d",
00617 stream,bsize);
00618
00619 /* format the config */
00620 sprintf(minibuffer,"config basketsize: %s = %d ",stream,bsize);
00621
00622 /*
00623 * Send "command" in fashion similar to run control protocol
00624 */
00625 cmd = roto_complete_cmd(roto_config,iam);
00626 err = roto_send_command(cmd,minibuffer,strlen(minibuffer));
00627 if (err) return err;
00628 /*
00629 * Get the command reply (ACK|NACK + state report)
00630 */
00631 return roto_recv_cmdreply(cmd);
00632 }
|
|
||||||||||||||||
|
Definition at line 1103 of file rototalk.c. References cmdword, roto_conn::conn_socketfd, datastart, g_roto_conn, logError(), roto_reallocate_sendbuffer(), roto_writen(), sendbuffer, sendbuffer_size, and sizeword. Referenced by roto_close_connection(), roto_open_connection(), roto_request_shutdown(), roto_send_autosave_config(), roto_send_basketsize_config(), roto_send_compress_config(), roto_send_record(), roto_set_named_file_status(), and roto_set_std_file_status(). 01104 {
01105
01106 int has_data = ( nsendbytes>0 && buffer );
01107 int databytes = nsendbytes + sizeof(long int); /* includes byte count */
01108 int totmsgsize = databytes + sizeof(long int); /* includes command */
01109 int nsent = 0;
01110 int realloc_status;
01111
01112 if (g_roto_conn.conn_socketfd<0) {
01113 logError("roto_send_command: not connected");
01114 return rototalk_err_notconnected;
01115 }
01116
01117 if ( has_data ) cmd |= roto_datatofollow;
01118
01119 errno = 0;
01120
01121 /*
01122 * Compose send buffer with command and bytes-to-follow prepended
01123 * to the actual data, first making sure that the buffer is large enough
01124 */
01125 if (sendbuffer_size < totmsgsize) {
01126 realloc_status = roto_reallocate_sendbuffer(totmsgsize);
01127 /* don't try to use more than we could allocate */
01128 if (sendbuffer_size<totmsgsize)
01129 totmsgsize = sendbuffer_size;
01130 }
01131
01132 *cmdword = cmd;
01133 if ( has_data) {
01134 *sizeword = databytes;
01135 memcpy(datastart,buffer,nsendbytes);
01136 }
01137 else
01138 totmsgsize = sizeof(long int); /* no data -> message is only command */
01139
01140 /*
01141 * Send the whole works in one shot (command + byte count + data)
01142 */
01143 nsent = roto_writen(g_roto_conn.conn_socketfd,
01144 sendbuffer,totmsgsize);
01145
01146 if (nsent != totmsgsize) return rototalk_err_badsendcmd;
01147 return rototalk_success;
01148 }
|
|
||||||||||||
|
Definition at line 559 of file rototalk.c. References roto_conn::conn_socketfd, g_roto_conn, iam, logDebug(), logError(), roto_complete_cmd(), roto_config, roto_recv_cmdreply(), roto_send_command(), roto_verbose, and rotocmd. 00560 {
00561 rotocmd cmd;
00562 int err;
00563 char minibuffer[4096];
00564
00565 if (g_roto_conn.conn_socketfd<0) {
00566 logError("roto_send_compress_config: not connected");
00567 return rototalk_err_notconnected;
00568 }
00569
00570 if (roto_verbose>1)
00571 logDebug(2,"roto_send_compress_config: stream \"%s\" - compress %d",
00572 stream,level);
00573
00574 /* format the config */
00575 sprintf(minibuffer,"config compress: %s = %d ",stream,level);
00576
00577 /*
00578 * Send "command" in fashion similar to run control protocol
00579 */
00580 cmd = roto_complete_cmd(roto_config,iam);
00581 err = roto_send_command(cmd,minibuffer,strlen(minibuffer));
00582 if (err) return err;
00583 /*
00584 * Get the command reply (ACK|NACK + state report)
00585 */
00586 return roto_recv_cmdreply(cmd);
00587 }
|
|
||||||||||||
|
Definition at line 465 of file rototalk.c. References roto_conn::conn_nrec_sent, roto_conn::conn_socketfd, g_roto_conn, iam, logDebug(), logError(), roto_complete_cmd(), roto_recbuff, roto_recv_cmdreply(), roto_send_command(), roto_verbose, and rotocmd. Referenced by send_bogus_stuff(), BeamData::send_data(), send_whole_file(), and RotoClient::SendRecordBuffer(). 00466 {
00467 rotocmd cmd;
00468 int err;
00469
00470 if (g_roto_conn.conn_socketfd<0) {
00471 logError("roto_send_record: not connected");
00472 return rototalk_err_notconnected;
00473 }
00474
00475 g_roto_conn.conn_nrec_sent++;
00476
00477 if (roto_verbose>2)
00478 logDebug(3,"roto_send_record: record %d, %d bytes",
00479 g_roto_conn.conn_nrec_sent,nbytes);
00480
00481 /*
00482 * Send "command" in fashion similar to run control protocol
00483 */
00484 cmd = roto_complete_cmd(roto_recbuff,iam);
00485 err = roto_send_command(cmd,buffer,nbytes);
00486 if (err) return err;
00487 /*
00488 * Get the command reply (ACK|NACK + state report)
00489 */
00490 return roto_recv_cmdreply(cmd);
00491 }
|
|
|
Definition at line 366 of file rototalk.c. References roto_conn::conn_socketfd, g_roto_conn, logError(), logWarn(), and roto_verbose. Referenced by main(), and roto_open_connection(). 00367 {
00368 int err;
00369
00370 /*
00371 * complain if we aren't actually connected
00372 */
00373 if (g_roto_conn.conn_socketfd<0) {
00374 logError("roto_set_connection_nodelay: not connected");
00375 return rototalk_err_notconnected;
00376 }
00377
00378 err = setsockopt(g_roto_conn.conn_socketfd,IPPROTO_TCP,TCP_NODELAY,
00379 (char*)&val, sizeof(val));
00380
00381 if (roto_verbose>0 && err)
00382 logWarn("roto_set_connection_nodelay returned %d",err);
00383
00384 return err;
00385 }
|
|
||||||||||||
|
Definition at line 1002 of file rototalk.c. References roto_conn::conn_socketfd, g_roto_conn, iam, logError(), logInfo(), logNotice(), MINOS_DCS, roto_complete_cmd(), roto_recv_cmdreply(), roto_send_command(), and roto_verbose. Referenced by roto_close_named_file(), and roto_open_named_file(). 01003 {
01004
01005 const char* which_mode = "uknown request";
01006 char minibuffer[1024];
01007 int* iptr = (int*) minibuffer;
01008 char* cptr = minibuffer+sizeof(int);
01009 int fnlen, nbytes, err;
01010
01011 /*
01012 * Make sure that the command is "open" or "close"
01013 */
01014 if (cmd == roto_openf) {
01015 which_mode = "open";
01016 }
01017 else if (cmd == roto_closef) {
01018 which_mode = "close";
01019 }
01020 else {
01021 logError("roto_set_named_file_status: unknown mode 0x%8.8lx",cmd);
01022 return rototalk_err_illegalmethod;
01023 }
01024
01025 if (g_roto_conn.conn_socketfd<0) {
01026 logError("roto_%s_named_file: not connected",which_mode);
01027 return rototalk_err_notconnected;
01028 }
01029
01030 /*
01031 * server expects a mini-buffer with one of:
01032 * DCP: detector run subrun
01033 * DCS,BEAMMON: detector sec nsec
01034 * but we'll pass
01035 * (MINOS_DCS|roto_datatofollow) "filename"
01036 */
01037
01038 /* signal that we're giving a file name, not normal 4 int buffer */
01039 *iptr = MINOS_DCS | roto_datatofollow;
01040 /* copy the filename into the buffer */
01041 fnlen = strlen(fname);
01042 strcpy(cptr,fname);
01043 cptr[fnlen] = 0; /* whack in trailing \0 */
01044 nbytes = sizeof(int) + fnlen + 1;
01045
01046 if (roto_verbose>1)
01047 logNotice("roto_%s_named_file '%s' (%d bytes)",
01048 which_mode,cptr,nbytes);
01049
01050 /*
01051 * Send "command" in fashion similar to run control protocol
01052 */
01053 cmd = roto_complete_cmd(cmd,iam);
01054 err = roto_send_command(cmd,minibuffer,nbytes);
01055 if (err) return err;
01056
01057 if (roto_verbose>1)
01058 logInfo("roto_%s_named_file '%s' requested",which_mode,fname);
01059
01060 /*
01061 * Get the command reply (ACK|NACK + state report)
01062 */
01063 return roto_recv_cmdreply(cmd);
01064
01065 }
|
|
||||||||||||||||||||||||
|
Definition at line 910 of file rototalk.c. References roto_conn::conn_socketfd, g_roto_conn, iam, logError(), logInfo(), MINOS_ROOTER_BEAMMON, MINOS_ROOTER_DCP, MINOS_ROOTER_DCS, roto_complete_cmd(), roto_recv_cmdreply(), roto_send_command(), and roto_verbose. Referenced by roto_close_beammonfile(), roto_close_daqfile(), roto_close_dcsfile(), roto_open_beammonfile(), roto_open_daqfile(), and roto_open_dcsfile(). 00912 {
00913
00914 int err;
00915 const char* which_mode = "uknown request";
00916 const char* which_entity = "unknown-type";
00917 int minibuffer[4];
00918
00919 /*
00920 * Make sure that the command is "open" or "close"
00921 */
00922 if (cmd == roto_openf) {
00923 which_mode = "open";
00924 }
00925 else if (cmd == roto_closef) {
00926 which_mode = "close";
00927 }
00928 else {
00929 logError("roto_set_std_file_status: unknown mode 0x%8.8lx",cmd);
00930 return rototalk_err_illegalmethod;
00931 }
00932
00933 /*
00934 * Make sure it is tagged as either DCP (ie. DAQ) or DCS
00935 */
00936 switch (entity) {
00937 case MINOS_ROOTER_DCP:
00938 which_entity = "daq";
00939 break;
00940 case MINOS_ROOTER_DCS:
00941 which_entity = "dcs";
00942 break;
00943 case MINOS_ROOTER_BEAMMON:
00944 which_entity = "beammon";
00945 break;
00946 default:
00947 logError("roto_set_std_file_status: unknown entity 0x%8.8x",entity);
00948 return rototalk_err_badsender;
00949 break;
00950 }
00951
00952 if (g_roto_conn.conn_socketfd<0) {
00953 logError("roto_%s_%sfile: not connected",which_mode,which_entity);
00954 return rototalk_err_notconnected;
00955 }
00956
00957 /*
00958 * server expects a mini-buffer with one of:
00959 * DCP: detector run subrun
00960 * DCS,BEAMMON: detector sec nsec
00961 */
00962 minibuffer[0] = entity;
00963 minibuffer[1] = detector;
00964 minibuffer[2] = tag1;
00965 minibuffer[3] = tag2;
00966
00967 /*
00968 * Send "command" in fashion similar to run control protocol
00969 */
00970 cmd = roto_complete_cmd(cmd,iam);
00971 err = roto_send_command(cmd,(char*)minibuffer,4*sizeof(int));
00972 if (err) return err;
00973
00974 if (roto_verbose>1)
00975 logInfo("roto_%s_%sfile det %d tag1 %d tag2 %d\n",
00976 which_mode,which_entity,detector,tag1,tag2);
00977
00978 /*
00979 * Get the command reply (ACK|NACK + state report)
00980 */
00981 return roto_recv_cmdreply(cmd);
00982
00983 }
|
|
||||||||||||||||
|
Definition at line 1411 of file rototalk.c. Referenced by roto_send_command(). 01412 {
01413 int nleft, nwritten;
01414
01415 nleft = nbytes;
01416 while (nleft > 0) {
01417 nwritten = write(fd, ptr, nleft);
01418 if (nwritten<=0) return nwritten; /* error */
01419 nleft -= nwritten;
01420 ptr += nwritten;
01421 }
01422 return (nbytes-nleft);
01423
01424 }
|
|
|
Definition at line 95 of file rototalk.c. Referenced by roto_reallocate_sendbuffer(), and roto_send_command(). |
|
|
Definition at line 97 of file rototalk.c. Referenced by roto_reallocate_sendbuffer(), and roto_send_command(). |
|
|
Referenced by roto_close_beammonfile(), and roto_open_beammonfile(). |
|
|
|
Referenced by roto_close_dcsfile(), and roto_open_dcsfile(). |
|
|
Definition at line 47 of file rototalk.c. Referenced by roto_close_connection(), roto_open_connection(), roto_request_shutdown(), roto_send_autosave_config(), roto_send_basketsize_config(), roto_send_compress_config(), roto_send_record(), roto_set_named_file_status(), and roto_set_std_file_status(). |
|
|
Initial value: MINOS_ROOTER_ROOTER << RC_FROM_BITPOS | \ MINOS_ROOTER_UNABLE_TO << RC_TYPE_BITPOS | \ END_OF_MINOS_ROOTER_COMMAND_TYPES Definition at line 80 of file rototalk.c. Referenced by roto_recv_cmdreply(). |
|
|
Initial value: MINOS_ROOTER_ROOTER << RC_FROM_BITPOS | \ MINOS_ROOTER_STATE_REPORT << RC_TYPE_BITPOS | \ END_OF_MINOS_ROOTER_STATES Definition at line 84 of file rototalk.c. Referenced by roto_recv_cmdreply(). |
|
|
Definition at line 105 of file rototalk.c. Referenced by roto_recv_cmdreply(). |
|
|
Definition at line 122 of file rototalk.c. Referenced by roto_close_beammonfile(), roto_close_daqfile(), roto_close_dcsfile(), and roto_close_named_file(). |
|
|
Definition at line 125 of file rototalk.c. Referenced by roto_send_autosave_config(), roto_send_basketsize_config(), and roto_send_compress_config(). |
|
|
Definition at line 119 of file rototalk.c. Referenced by roto_open_connection(). |
|
|
Definition at line 156 of file rototalk.c. |
|
|
Definition at line 120 of file rototalk.c. Referenced by roto_close_connection(). |
|
|
Definition at line 121 of file rototalk.c. Referenced by roto_open_beammonfile(), roto_open_daqfile(), roto_open_dcsfile(), and roto_open_named_file(). |
|
|
Definition at line 123 of file rototalk.c. Referenced by roto_send_record(). |
|
|
Definition at line 124 of file rototalk.c. Referenced by roto_request_shutdown(). |
|
|
Definition at line 44 of file rototalk.c. Referenced by main(), roto_close_connection(), roto_open_connection(), roto_request_shutdown(), roto_send_autosave_config(), roto_send_basketsize_config(), roto_send_compress_config(), roto_send_record(), roto_set_connection_nodelay(), roto_set_named_file_status(), and roto_set_std_file_status(). |
|
|
Definition at line 94 of file rototalk.c. Referenced by roto_reallocate_sendbuffer(), and roto_send_command(). |
|
|
Definition at line 93 of file rototalk.c. Referenced by roto_reallocate_sendbuffer(), and roto_send_command(). |
|
|
Definition at line 96 of file rototalk.c. Referenced by roto_reallocate_sendbuffer(), and roto_send_command(). |
1.3.9.1