FACT++  1.0
int execute_service ( int  req_id)

Definition at line 1397 of file dis.c.

References serv::address, COMMAND, req_ent::conn_id, exit_ent::conn_id, copy_swap_buffer_out(), Curr_conn_id, Debug_on, req_ent::delay_delete, dim_print_date_time(), dis_get_n_clients(), DIS_HEADER, DIS_STAMPED_HEADER, dna_write_nowait(), req_ent::first_time, req_ent::format, serv::format_data, Memory::free(), serv::id, id_get_ptr(), Last_n_clients, Memory::malloc(), MAX_NAME, serv::name, Net_conns, NET_CONNECTION::node, serv::quality, DIS_STAMPED_PACKET::quality, release_conn(), req_ent::req_id, DIS_STAMPED_PACKET::reserved, req_ent::service_id, DIS_STAMPED_PACKET::service_id, req_ent::service_ptr, size, serv::size, DIS_STAMPED_PACKET::size, sprintf(), SRC_DIS, STAMPED, str, serv::tag, NET_CONNECTION::task, DIS_STAMPED_PACKET::time_stamp, req_ent::to_delete, req_ent::type, serv::type, serv::user_millisecs, serv::user_routine, and serv::user_secs.

Referenced by dis_insert_request(), dis_report_service(), and do_update_service().

1398 {
1399  int *buffp, size;
1400  register REQUEST *reqp;
1401  register SERVICE *servp;
1402  char str[80], def[MAX_NAME];
1403  int conn_id, last_conn_id;
1404  int *pkt_buffer, header_size, aux;
1405 #ifdef WIN32
1406  struct timeb timebuf;
1407 #else
1408  struct timeval tv;
1409  struct timezone *tz;
1410 #endif
1411  FORMAT_STR format_data_cp[MAX_NAME/4];
1412 
1413  reqp = (REQUEST *)id_get_ptr(req_id, SRC_DIS);
1414  if(!reqp)
1415  return(0);
1416  if(reqp->to_delete)
1417  return(0);
1418  reqp->delay_delete++;
1419  servp = reqp->service_ptr;
1420  conn_id = reqp->conn_id;
1421 
1422 if(Debug_on)
1423 {
1425 printf("Updating %s for %s@%s (req_id = %d)\n",
1426  servp->name,
1427  Net_conns[conn_id].task, Net_conns[conn_id].node,
1428  reqp->req_id);
1429 }
1430 
1431  last_conn_id = Curr_conn_id;
1432  Curr_conn_id = conn_id;
1433  if(servp->type == COMMAND)
1434  {
1435  sprintf(str,"This is a COMMAND Service");
1436  buffp = (int *)str;
1437  size = 26;
1438  sprintf(def,"c:26");
1439  }
1440  else if( servp->user_routine != 0 )
1441  {
1442  if(reqp->first_time)
1443  {
1445  }
1446  (servp->user_routine)( &servp->tag, &buffp, &size,
1447  &reqp->first_time );
1448  reqp->first_time = 0;
1449 
1450  }
1451  else
1452  {
1453  buffp = servp->address;
1454  size = servp->size;
1455  }
1456  Curr_conn_id = last_conn_id;
1457 /* send even if no data but not if negative */
1458  if( size < 0)
1459  {
1460  reqp->delay_delete--;
1461  return(0);
1462  }
1463  if( DIS_STAMPED_HEADER + size > Dis_packet_size )
1464  {
1465  if( Dis_packet_size )
1466  free( Dis_packet );
1468  if(!Dis_packet)
1469  {
1470  reqp->delay_delete--;
1471  return(0);
1472  }
1474  }
1475  Dis_packet->service_id = htovl(reqp->service_id);
1476  if((reqp->type & 0xFF000) == STAMPED)
1477  {
1478  pkt_buffer = ((DIS_STAMPED_PACKET *)Dis_packet)->buffer;
1479  header_size = DIS_STAMPED_HEADER;
1480  if(!servp->user_secs)
1481  {
1482 #ifdef WIN32
1483  ftime(&timebuf);
1484  aux = timebuf.millitm;
1485  Dis_packet->time_stamp[0] = htovl(aux);
1486  Dis_packet->time_stamp[1] = htovl((int)timebuf.time);
1487 #else
1488  tz = 0;
1489  gettimeofday(&tv, tz);
1490  aux = (int)tv.tv_usec / 1000;
1491  Dis_packet->time_stamp[0] = htovl(aux);
1492  Dis_packet->time_stamp[1] = htovl((int)tv.tv_sec);
1493 #endif
1494  }
1495  else
1496  {
1497  aux = /*0xc0de0000 |*/ servp->user_millisecs;
1498  Dis_packet->time_stamp[0] = htovl(aux);
1499  Dis_packet->time_stamp[1] = htovl(servp->user_secs);
1500  }
1501  Dis_packet->reserved[0] = (int)htovl(0xc0dec0de);
1502  Dis_packet->quality = htovl(servp->quality);
1503  }
1504  else
1505  {
1506  pkt_buffer = ((DIS_PACKET *)Dis_packet)->buffer;
1507  header_size = DIS_HEADER;
1508  }
1509  memcpy(format_data_cp, servp->format_data, sizeof(format_data_cp));
1510  size = copy_swap_buffer_out(reqp->format, format_data_cp,
1511  pkt_buffer,
1512  buffp, size);
1513  Dis_packet->size = htovl(header_size + size);
1514  if( !dna_write_nowait(conn_id, Dis_packet, header_size + size) )
1515  {
1516  if(Net_conns[conn_id].write_timedout)
1517  {
1519  if(reqp->delay_delete > 1)
1520  {
1521  printf(" Server (Explicitly) Updating Service %s: Couldn't write to Conn %3d : Client %s@%s\n",
1522  servp->name, conn_id,
1523  Net_conns[conn_id].task, Net_conns[conn_id].node);
1524  }
1525  else
1526  {
1527  printf(" Server Updating Service %s: Couldn't write to Conn %3d : Client %s@%s\n",
1528  servp->name, conn_id,
1529  Net_conns[conn_id].task, Net_conns[conn_id].node);
1530  }
1531  fflush(stdout);
1532  }
1533  if(reqp->delay_delete > 1)
1534  {
1535  reqp->to_delete = 1;
1536  }
1537  else
1538  {
1539  reqp->delay_delete = 0;
1540  release_conn(conn_id, 1, 0);
1541  }
1542  }
1543 /*
1544  else
1545  {
1546  if((reqp->type & 0xFFF) == MONITORED)
1547  {
1548  if(reqp->timr_ent)
1549  dtq_clear_entry(reqp->timr_ent);
1550  }
1551  }
1552 */
1553  if(reqp->delay_delete > 0)
1554  reqp->delay_delete--;
1555  return(1);
1556 }
#define MAX_NAME
Definition: dim.h:182
int user_millisecs
Definition: dis.c:84
char task[MAX_TASK_NAME]
Definition: dim.h:408
DllExp DIM_NOSHARE NET_CONNECTION * Net_conns
Definition: conn_handler.c:32
#define COMMAND
Definition: dim_common.h:10
char str[80]
Definition: test_client.c:7
void * id_get_ptr(int id, SRC_TYPES type)
Definition: conn_handler.c:184
int to_delete
Definition: dis.c:64
int service_id
Definition: dis.c:56
char name[MAX_NAME]
Definition: dis.c:72
int time_stamp[2]
Definition: dim.h:254
int copy_swap_buffer_out(int format, FORMAT_STR *format_data, void *buff_out, void *buff_in, int size)
Definition: copy_swap.c:170
void * malloc()
Definition: EventBuilder.cc:99
int type
Definition: dis.c:74
#define DIS_STAMPED_HEADER
Definition: dim.h:260
static int release_conn(int conn_id, int print_flg, int dns_flag)
Definition: dis.c:2684
char node[MAX_NODE_NAME]
Definition: dim.h:407
#define STAMPED
Definition: dim_common.h:17
int reserved[3]
Definition: dim.h:256
dim_long tag
Definition: dis.c:80
int format
Definition: dis.c:61
FORMAT_STR format_data[MAX_NAME/4]
Definition: dis.c:76
Definition: dis.c:69
int user_secs
Definition: dis.c:83
static int Dis_packet_size
Definition: dis.c:197
static int Curr_conn_id
Definition: dis.c:123
void(* user_routine)()
Definition: dis.c:79
int dna_write_nowait(int conn_id, void *buffer, int size)
Definition: dna.c:412
struct serv * service_ptr
Definition: dis.c:59
int first_time
Definition: dis.c:62
int size
Definition: db_dim_server.c:17
int * address
Definition: dis.c:77
void free(void *mem)
int type
Definition: dis.c:58
int delay_delete
Definition: dis.c:63
void dim_print_date_time()
Definition: utilities.c:134
int req_id
Definition: dis.c:57
static int Debug_on
Definition: dis.c:156
int size
Definition: dis.c:78
#define DIS_HEADER
Definition: dim.h:249
int conn_id
Definition: dis.c:55
int dis_get_n_clients(unsigned service_id)
Definition: dis.c:1865
Definition: dis.c:52
sprintf(name1,"NewService%d", i)
static DIS_STAMPED_PACKET * Dis_packet
Definition: dis.c:196
static int Last_n_clients
Definition: dis.c:150
int quality
Definition: dis.c:82
int service_id
Definition: dim.h:253
int id
Definition: dis.c:73

+ Here is the call graph for this function:

+ Here is the caller graph for this function: