Example #1
0
pwr_tTime wb_orep::modTime()
{
  pwr_tTime t = ohTime();
  pwr_tTime rbt = rbTime();
  pwr_tTime dbt = dbTime();

  if ( time_Acomp( &rbt, &t) == 1)
    t = rbt;
  if ( time_Acomp( &dbt, &rbt) == 1)
    t = dbt;
  return t;
}
Example #2
0
/**
 * Adds a remote class volume.
 */
void cvolcm_AddClassVolume(
    pwr_tStatus* sts, gdb_sNode* np, const net_sGvolume* vp)
{
  gdb_sCclassVolume *ccvp, *rp;
  gdb_sVolume* cvp;

  gdb_AssumeLocked;
  pwr_Assert(vp != NULL);

  ccvp = pool_Alloc(sts, gdbroot->pool, sizeof(*ccvp));
  if (ccvp == NULL)
    return;

  ccvp->key.nid = vp->nid;
  ccvp->key.vid = vp->vid;
  ccvp->time = net_NetTimeToTime(&vp->time);

  cvp = hash_Search(sts, gdbroot->vid_ht, &vp->vid);
  if (cvp == NULL) /* This volume doesn't exist locally, but we may create it
                      later on */
    ccvp->equalClasses = 0;
  else {
    pwr_tTime t = net_NetTimeToTime(&cvp->g.time);
    ccvp->equalClasses = time_Acomp(&ccvp->time, &t) == 0 ? 1 : 0;
  }

  rp = hash_Insert(sts, gdbroot->ccvol_ht, ccvp);
  if (rp == NULL) { /* This was previously a bugcheck but obviously can occur */
    pool_Free(NULL, gdbroot->pool, ccvp);
    return;
  }

  pool_QinsertPred(NULL, gdbroot->pool, &ccvp->ccvol_ll, &np->ccvol_lh);
}
Example #3
0
int compTime(sKey d1, sKey d2)
{
  if(time_Acomp( &(d1.EventTime), &(d2.EventTime)) < 0 )
  {
    return 1;
  }
  return 0;
}
Example #4
0
static void time_PeriodSec( pwr_tTime *from, pwr_tTime *to, pwr_tTime *center, int sec)
{
  pwr_tStatus sts;
  pwr_tTime current;

  sts = time_GetTime( &current);
  to->tv_sec = center->tv_sec + sec/2;
  to->tv_nsec = center->tv_nsec;
  if ( time_Acomp( to, &current) == 1)
    *to = current;
  from->tv_sec = to->tv_sec - sec;
  from->tv_nsec = to->tv_nsec;
}
Example #5
0
void
subcm_CheckTimeout ()
{
  pool_sQlink		*cl;
  sub_sClient		*cp;
  pwr_tTime		curtim;
  pwr_tTime		restim;
  pwr_tDeltaTime	tmotim;
  pwr_tInt32		n;
  pwr_tInt32		i;

  gdb_AssumeLocked;

  gdbroot->db->tmocnt++;  /* Statistics */

  time_GetTime( &curtim);

  /* Calculate # of remote object clients to process this time */

  n = gdbroot->db->subt_lc;
  if (n == 0) n = MIN(1, gdbroot->db->subt_lc);

  for (i=0; i<n; i++) {

    /* Temporarily remove the first entry from the queue for processing.  */

    cl = pool_QremoveSucc(NULL, gdbroot->pool, &gdbroot->db->subt_lh);
    cp = pool_Qitem(cl, sub_sClient, subt_ll);

    /* Find out if the client has timed out */

    if (!cp->old) {
      /* cp->tmo in 10ths of seconds */
      tmotim.tv_sec = cp->tmo / 10;
      tmotim.tv_nsec = (cp->tmo - tmotim.tv_sec * 10) * 100000000;
      time_Aadd(&restim, &cp->lastupdate, &tmotim);       

      /* curtim >= tmotim + lastupdate */
      if (time_Acomp(&curtim, &restim) >= 0) 
	subc_SetOld(cp);
    } /* If it was old already */

    /* Reinsert the entry last in the queue.  */
    
    pool_QinsertPred(NULL, gdbroot->pool, cl, &gdbroot->db->subt_lh);
  }
}
Example #6
0
pwr_tTime wb_orep::treeModTime()
{
  pwr_tStatus sts;
  pwr_tTime t = modTime();
  pwr_tTime tchild;
  wb_orep *after;

  for ( wb_orep *child = first( &sts); 
        ODD(sts);
	child = after) {
    child->ref();

    tchild = child->treeModTime();
    if ( time_Acomp( &tchild, &t) == 1)
      t = tchild;

    after = child->after( &sts);
    child->unref();
  }
  return t;
}
Example #7
0
static void
scan_nodes ()
{
  LstLink(sNode) *nl;
  pwr_tStatus sts;
  pwr_tBoolean Old;
  pwr_tTime LastUpdate, Timeout, CurrentTime;
  pwr_tDeltaTime Delta;
  pwr_tBoolean LinkUp;

  time_GetTime(&CurrentTime);

  for (nl = LstFir(&node_l); nl != LstEnd(&node_l); nl = LstNex(nl)) {
    sNode *np = LstObj(nl);
    pwr_sClass_NodeLinkSup  *o = np->o;
    LinkUp = 0;
    sts = gdh_GetSubscriptionOldness (o->SubId, &Old, &LastUpdate, NULL);
    if (ODD(sts)) {
      /* IF (CurrentTime < LastUpdate + TimeoutTime) THEN LinkUp */
      Delta.tv_sec = o->TimeoutTime;
      Delta.tv_nsec = 0;
      time_Aadd(&Timeout, &LastUpdate, &Delta);
      if (time_Acomp(&CurrentTime, &Timeout) < 0) 
	LinkUp = 1;
      o->SystemStatus = *np->subvalue;
    }

    if (o->LinkUp && !LinkUp) {
      o->LinkUp = 0;
      o->DownTime = CurrentTime;
      o->SystemStatus = PWR__NETTIMEOUT;
    } else if (!o->LinkUp && LinkUp) {
      o->LinkUp = 1;
      o->UpTime = CurrentTime;
      o->UpCount++;
    }

    detect(o, 1, np);
  }
}
Example #8
0
/**
 * Adds a remote class volume.
 */
void 
cvolcm_AddClassVolume(
  pwr_tStatus		*sts,
  gdb_sNode		*np,
  const net_sGvolume	*vp
)
{
  gdb_sCclassVolume	*ccvp;
  gdb_sVolume		*cvp;
  

  gdb_AssumeLocked;
  pwr_Assert(vp != NULL);



  ccvp = pool_Alloc(sts, gdbroot->pool, sizeof(*ccvp));
  if (ccvp == NULL) return;

  ccvp->key.nid = vp->nid;
  ccvp->key.vid = vp->vid;
  ccvp->time = net_NetTimeToTime(&vp->time);
  
  cvp = hash_Search(sts, gdbroot->vid_ht, &vp->vid);
  if (cvp == NULL) /* This volume doesn't exist locally, but we may create it later on */
    ccvp->equalClasses = 0;
  else {
    pwr_tTime t = net_NetTimeToTime( &cvp->g.time);
    ccvp->equalClasses = time_Acomp(&ccvp->time, &t) == 0 ? 1 : 0;
  }
  
  ccvp = hash_Insert(sts, gdbroot->ccvol_ht, ccvp);
  if (ccvp == NULL) errh_Bugcheck(GDH__WEIRD, "adding cached class volume");
  
  pool_QinsertPred(NULL, gdbroot->pool, &ccvp->ccvol_ll, &np->ccvol_lh);

}
Example #9
0
void wb_build::webgraph( pwr_tOid oid)
{
  pwr_tFileName dest_fname;
  pwr_tFileName src_fname;
  pwr_tCmd	cmd;
  pwr_tString80	java_name;
  pwr_tString80	name;
  pwr_tTime	dest_time, src_time;
  int 		check_hierarchy = cdh_ObjidIsNotNull( m_hierarchy);
  int 		hierarchy_found = 0;
  int 		is_frame, is_applet;
  char		jname[80];
  pwr_tStatus  	fsts;
  int		jexport;
  int 		found;
  pwr_tFileName found_file, file_spec;
  pwr_tFileName graph_name, dir;
  char		dev[80], type[80];
  int		version;
  pwr_tString80	appletsignature = "";
  char 		*s;

  wb_object o = m_session.object(oid);
  if ( !o) {
    m_sts = o.sts();
    return;
  }

  // Check that no ancestor is a LibHier
  for ( wb_object p = o.parent(); p.oddSts(); p = p.parent()) {
    if ( p.cid() == pwr_eClass_LibHier) {
      m_sts = PWRB__INLIBHIER;
      return;
    }
    if ( check_hierarchy && cdh_ObjidIsEqual( m_hierarchy, p.oid()))
      hierarchy_found = 1;
  }

  if ( check_hierarchy && !hierarchy_found) {
    m_sts = PWRB__NOBUILT;
    return;
  }

  wb_attribute a = m_session.attribute( oid, "RtBody", "Name");
  if ( !a) {
    m_sts = a.sts();
    return;
  }

  a.value( java_name);
  if ( !a) {
    m_sts = a.sts();
    return;
  }

  if ( isupper(java_name[0])) {
    cdh_ToLower( java_name, java_name);
    java_name[0] = toupper(java_name[0]);

    // Get the .pwg file for this javaname
    strcpy( graph_name, cdh_Low(java_name));
    sprintf( name, "$pwrp_pop/%s.pwg", graph_name);

    dcli_translate_filename( name, name);
    m_sts = dcli_file_time( name, &src_time);
    if ( evenSts()) {
      // Search in all pwg files
      found = 0;
      strcpy( file_spec, "$pwrp_pop/*.pwg");
      for ( fsts = dcli_search_file( file_spec, found_file, DCLI_DIR_SEARCH_INIT);
	    ODD(fsts);
	    fsts = dcli_search_file( file_spec, found_file, DCLI_DIR_SEARCH_NEXT)) {
	
	fsts = grow_IsJava( found_file, &is_frame, &is_applet, jname);
	if ( EVEN(fsts)) continue;
	
	if ( is_frame && strcmp( jname, java_name) == 0) {
	  dcli_parse_filename( found_file, dev, dir, graph_name, type, &version);
	  strcpy( name, found_file);
	  found = 1;
	  break;
	}      
      }
      dcli_search_file( file_spec, found_file, DCLI_DIR_SEARCH_END);

      if ( !found) {
	char msg[200];
	sprintf( msg, "Graph for %s not found", java_name);
	MsgWindow::message('E', msg, msgw_ePop_Yes, oid);
	m_sts = PWRB__NOBUILT;
	return;
      }
    }

    m_sts = dcli_file_time( name, &src_time);
    if ( evenSts()) return;

    // Check exported java frame
    jexport = 0;
    sprintf( dest_fname, "$pwrp_pop/%s.java", java_name);
    dcli_translate_filename( dest_fname, dest_fname);
    fsts = dcli_file_time( dest_fname, &dest_time);
    if ( opt.force || EVEN(fsts) || time_Acomp( &src_time, &dest_time) == 1)
      jexport = 1;


    if ( jexport) {
      if ( !m_wnav) {
	sprintf( cmd, "Build:    WebGraph  Unable to export java in this environment %s", java_name);
	MsgWindow::message('W', cmd, msgw_ePop_No, oid);
      }
      else {
	// Get signature from WebHandler
	for ( wb_object p = o.parent(); p.oddSts(); p = p.parent()) {
	  if ( p.cid() == pwr_cClass_WebHandler) {
	    wb_attribute a = m_session.attribute( p.oid(), "RtBody", "AppletSignature");
	    if ( !a) {
	      m_sts = a.sts();
	      return;
	    }

	    a.value( appletsignature);
	    if ( !a) {
	      m_sts = a.sts();
	      return;
	    }
	    dcli_trim( appletsignature, appletsignature);
	    break;
	  }
	}
	

	Ge *gectx = m_wnav->ge_new( graph_name, 1);
	if ( strcmp( appletsignature, "") == 0)
	  strcpy( cmd, "export java");
	else
	  sprintf( cmd, "export java /signature=\"%s\"", appletsignature);
	m_sts = gectx->command( cmd);
	if ( evenSts()) {
	  msg_GetMsg( m_sts, cmd, sizeof(cmd));
	  MsgWindow::message('E', cmd, msgw_ePop_Yes, oid);
	  m_sts = PWRB__NOBUILT;
	  delete gectx;
	  return;
	}
	delete gectx;

	sprintf( cmd, "Build:    WebGraph  Export java %s", java_name);
	MsgWindow::message('I', cmd, msgw_ePop_No, oid);
	
	m_sts = PWRB__SUCCESS;
      }
    }
  }
  else {
    // Copy from $pwrp_pop to $pwrp_web

    strcpy( graph_name, cdh_Low(java_name));

    cdh_ToLower( graph_name, graph_name);

    strcpy( src_fname, "$pwrp_pop/");
    strcat( src_fname, graph_name);

    if ( strstr( src_fname, ".pwg") == 0)
      strcat( src_fname, ".pwg");

    dcli_translate_filename( src_fname, src_fname);
    m_sts = dcli_file_time( src_fname, &src_time);
    if ( evenSts()) {
      m_sts = PWRB__NOBUILT;
      return;
    }

    strcpy( dest_fname, "$pwrp_web/");
    strcat( dest_fname, graph_name);

    if ( strstr( dest_fname, ".pwg") == 0)
      strcat( dest_fname, ".pwg");

    dcli_translate_filename( dest_fname, dest_fname);
    m_sts = dcli_file_time( dest_fname, &dest_time);
    if ( opt.force || evenSts() || src_time.tv_sec > dest_time.tv_sec) {
      sprintf( cmd, "cp %s %s", src_fname, dest_fname);
      system( cmd);
      sprintf( cmd, "Build:    WebGraph copy $pwrp_pop/%s -> $pwrp_web", graph_name);
      MsgWindow::message( 'I', cmd, msgw_ePop_No, oid);
      
      strcpy( name, graph_name);
      if (( s = strrchr( name, '.')))
	*s = 0;
      wb_log::log( wlog_eCategory_GeBuild, name, 0);
      m_sts = PWRB__SUCCESS;
    }
    else
      m_sts = PWRB__NOBUILT;

  }
}
Example #10
0
void wb_build::xttgraph( pwr_tOid oid)
{
  pwr_tFileName src_fname, dest_fname;
  pwr_tCmd	cmd;
  pwr_tString80	action;
  pwr_tString80	name;
  pwr_tTime	dest_time, src_time;
  int 		check_hierarchy = cdh_ObjidIsNotNull( m_hierarchy);
  int 		hierarchy_found = 0;
  int 		is_frame, is_applet;
  char 		java_name[80];
  pwr_tStatus  	fsts;
  int		jexport;
  char		*s;

  wb_object o = m_session.object(oid);
  if ( !o) {
    m_sts = o.sts();
    return;
  }

  // Check that no ancestor is a LibHier
  for ( wb_object p = o.parent(); p.oddSts(); p = p.parent()) {
    if ( p.cid() == pwr_eClass_LibHier) {
      m_sts = PWRB__INLIBHIER;
      return;
    }
    if ( check_hierarchy && cdh_ObjidIsEqual( m_hierarchy, p.oid()))
      hierarchy_found = 1;
  }

  if ( check_hierarchy && !hierarchy_found) {
    m_sts = PWRB__NOBUILT;
    return;
  }

  wb_attribute a = m_session.attribute( oid, "RtBody", "Action");
  if ( !a) {
    m_sts = a.sts();
    return;
  }

  a.value( &action);
  if ( !a) {
    m_sts = a.sts();
    return;
  }

  if ( strstr( action, ".pwg")) {
    strcpy( src_fname, "$pwrp_pop/");
    strcat( src_fname, action);
    dcli_translate_filename( src_fname, src_fname);
    m_sts = dcli_file_time( src_fname, &src_time);
    if ( evenSts()) {
      m_sts = PWRB__NOBUILT;
      return;
    }

    strcpy( dest_fname, "$pwrp_exe/");
    strcat( dest_fname, action);
    dcli_translate_filename( dest_fname, dest_fname);
    m_sts = dcli_file_time( dest_fname, &dest_time);
    if ( opt.force || evenSts() || src_time.tv_sec > dest_time.tv_sec) {
      sprintf( cmd, "cp %s %s", src_fname, dest_fname);
      system( cmd);
      sprintf( cmd, "Build:    XttGraph copy $pwrp_pop/%s -> $pwrp_exe", action);
      MsgWindow::message( 'I', cmd, msgw_ePop_No, oid);

      strcpy( name, action);
      if (( s = strrchr( name, '.')))
	*s = 0;
      wb_log::log( wlog_eCategory_GeBuild, name, 0);
      m_sts = PWRB__SUCCESS;
    }
    else
      m_sts = PWRB__NOBUILT;

    jexport = 0;
    fsts = grow_IsJava( src_fname, &is_frame, &is_applet, java_name);
    if ( EVEN(fsts)) {
      m_sts = fsts;
      return;
    }
    if ( (is_frame || is_applet)  && 
	 strcmp( java_name, "") == 0) {
      // Java name is not yet set, use the default java name
      strcpy( java_name, action);
      if ( (s = strchr( java_name, '.')) != 0)
	*s = 0;
      java_name[0] = _toupper( java_name[0]);
    }
    if ( is_frame) {
      // Check exported java frame
      sprintf( dest_fname, "$pwrp_pop/%s.java", java_name);
      dcli_translate_filename( dest_fname, dest_fname);
      fsts = dcli_file_time( dest_fname, &dest_time);
      if ( opt.force || EVEN(fsts) || time_Acomp( &src_time, &dest_time) == 1)
	jexport = 1;
    }
    if ( is_applet) {
      // Check exported java applet
      sprintf( dest_fname, "$pwrp_pop/%s_A.java", java_name);
      dcli_translate_filename( dest_fname, dest_fname);
      fsts = dcli_file_time( dest_fname, &dest_time);
      if ( opt.force || EVEN(fsts) || time_Acomp( &src_time, &dest_time) == 1)
	jexport = 1;
    }
    if ( jexport) {
      if ( !m_wnav) {
	sprintf( cmd, "Build:    XttGraph  Unable to export java in this environment %s", action);
	MsgWindow::message('W', cmd, msgw_ePop_No, oid);
      }
      else {
	Ge *gectx = m_wnav->ge_new( action, 1);
	strcpy( cmd, "export java");
	m_sts = gectx->command( cmd);
	if ( evenSts()) {
	  msg_GetMsg( m_sts, cmd, sizeof(cmd));
	  MsgWindow::message('E', cmd, msgw_ePop_Yes, oid);
	  m_sts = PWRB__NOBUILT;
	  delete gectx;
	  return;
	}

	sprintf( cmd, "Build:    XttGraph  Export java %s", action);
	MsgWindow::message('I', cmd, msgw_ePop_No, oid);

	delete gectx;

	m_sts = PWRB__SUCCESS;
      }
    }
  }
}
Example #11
0
void wb_build::classvolume( pwr_tVid vid)
{
  pwr_tCmd cmd;
  pwr_tFileName fname;
  pwr_tObjName name;
  pwr_tTime wbl_time, dbs_time, h_time;
  pwr_tStatus fsts;
  pwr_tStatus sumsts = PWRB__NOBUILT;

  wb_log::push();

  if ( !opt.manual) {
    // Build all ClassDef
    classlist( pwr_eClass_ClassDef);
    if ( evenSts()) return;
    if ( sumsts == PWRB__NOBUILT && m_sts != PWRB__NOBUILT)
      sumsts = m_sts;
  }

  wb_log::pull();

  if ( vid == 0) {
    // Build current volume
    cdh_ToLower( name, m_session.name());
  }
  else {
    wb_env env = m_session.env();
    wb_volume v = env.volume(vid);
    if ( !v) {
      m_sts = v.sts();
      return;
    }
    strcpy( name, v.name());
  }

  // Get time for wb_load file
  sprintf( fname, "$pwrp_db/%s.wb_load", name);
  dcli_translate_filename( fname, fname);
  m_sts = dcli_file_time( fname, &wbl_time);
  if ( evenSts())
    return;

  // Get time for dbs file
  sprintf( fname, "$pwrp_load/%s.dbs", name);
  dcli_translate_filename( fname, fname);
  fsts = dcli_file_time( fname, &dbs_time);

  // Get time for classvolumes
  wb_merep *merep = ((wb_erep *)m_session.env())->merep();
  pwr_tTime mtime = pwr_cNTime;
  pwr_tTime t;
  pwr_tStatus sts;
  for ( wb_mvrep *mvrep = merep->volume( &sts);
	ODD(sts);
	mvrep = merep->nextVolume( &sts, mvrep->vid())) {
    if ( m_session.vid() == mvrep->vid())
      continue;
    // Check only system class and manufact class volumes
    if ( mvrep->vid() > cdh_cSystemClassVolMax &&
	 (mvrep->vid() < cdh_cManufactClassVolMin ||
	  mvrep->vid() > cdh_cManufactClassVolMax))
      continue;

    mvrep->time( &t);
    if ( time_Acomp( &t, &mtime) == 1)
      mtime = t;
  }


  // Create new loadfile
  if ( opt.force || EVEN(fsts) || wbl_time.tv_sec > dbs_time.tv_sec ||
       mtime.tv_sec > dbs_time.tv_sec) {
    sprintf( cmd, "create snapshot/file=\"$pwrp_db/%s.wb_load\"", name);
    m_sts = m_wnav->command( cmd);
    sumsts = m_sts;
  }
  else
    m_sts = sumsts;

  // Get time for struct file
  sprintf( fname, "$pwrp_inc/pwr_%sclasses.h", name);
  dcli_translate_filename( fname, fname);
  fsts = dcli_file_time( fname, &h_time);

  // Create new struct file
  if ( opt.force || EVEN(fsts) || wbl_time.tv_sec > h_time.tv_sec) {
    sprintf( cmd, "create struct/file=\"$pwrp_db/%s.wb_load\"", name);
    m_sts = m_wnav->command( cmd);
    sumsts = m_sts;
  }
  else
    m_sts = sumsts;

  if ( sumsts != PWRB__NOBUILT) {
    char msg[80];

    sprintf( msg, "Build:    Volume   %s", name);
    MsgWindow::message('I', msg, msgw_ePop_No);
  }
}
Example #12
0
pwr_tStatus	tlog_diff( 	char *filestr, 
				char *output, 
				char *timestr, 
				int parallell, 
				int attribute, 
				int text, 
				int ttext,
				int noorder, 
				int exact,
				char *since_str,
				char *before_str
)
{
	char		saved_filename[80];
	char		filename[80];
	FILE		*outfile;
	int		sts;
	tlog_t_linelist	*new_list;
	tlog_t_linelist	*old_list;
	int		new_list_count;
	int		old_list_count;
	float		time;
	int		nr;
	diff_ctx	ctx;
	char		modulestr[80];
	char		cmd[100];
	char		new_filename[80];
	char		old_filename[80];
	char		wild_filename[80];
	char		dev[80];
	char		dir[80];
	char		file[80];
	char		type[80];
	int		version;
	int		first;
	pwr_tTime	file_time;
	int		file_size;
	int		file_version;
	pwr_tTime	before_time;
	pwr_tTime	since_time;
	int		diff_count;
	unsigned long	search_ctx;

	tlog_get_defaultfilename( filestr, wild_filename, ".tlog", "pwrp_tlog:");

	diff_count = 0;
	first = 1;
	for(;;)
	{
	  if ( first)
	  {
	    /* Get the first file */
	    search_ctx = 0;
	    sts = dir_search_file( &search_ctx, wild_filename, filename);
	    if (EVEN(sts)) return sts;

	    /* At least one file is found */
	    if ( output != NULL)
	    {
	      /* Open the output file */
	      outfile = fopen( output, "w");
	      if ( !outfile )
	        return TLOG__FILEOPEN;
	    }
	    else
	      outfile = 0;

	    if ( timestr != NULL)
	    {
	      /* Convert to float */
	      nr = sscanf( timestr, "%f", &time);
	      if ( nr != 1)
	        return TLOG__TIMESYNTAX;
 	    }
	    else
	      time = 0.5;

	    if ( before_str != NULL)
	    {
	      sts = tlog_qual_to_time( before_str, &before_time);
	      if (EVEN(sts)) return TLOG__BEFOREQUAL;
	    }

	    if ( since_str != NULL)
	    {
	      sts = tlog_qual_to_time( since_str, &since_time);
	      if (EVEN(sts)) return TLOG__SINCEQUAL;
	    }

	    first = 0;
	  }
	  else
	  {
	    /* Get the next file */
	    sts = dir_search_file( &search_ctx, wild_filename, filename);
	    if (EVEN(sts)) break;

/*	    fprintf( outfile, ""); */
	  }

	  sts = dir_get_fileinfo( filename, (pwr_tTime *) &file_time, &file_size,
			&file_version, NULL);
	  if (EVEN(sts)) return sts;

	  if ( since_str != NULL)
	  {
	    if ( time_Acomp( &file_time, &since_time) < 0)
	      continue;
	  }
	  if ( before_str != NULL)
	  {
	    if ( time_Acomp( &file_time, &before_time) > 0)
	      continue;
	  }

	  sts = dir_parse_filename( filename, dev, dir, file, type, 
		&version);
	  strcpy( saved_filename, "pwrp_stlog:");
	  strcat( saved_filename, file);
	  strcat( saved_filename, type);

	  /* Read the new file 	*/
	  new_list_count = 0;
	  sts = tlog_insert_file( filename, &new_list, &new_list_count,
		new_filename);
	  if ( EVEN(sts))
	  {
	    if ( outfile)
	    {
	      fprintf( outfile, "\n\n\nNew file: %s\n", new_filename);
	      fprintf( outfile, "%%TLOG-E-NEWOPEN, Unable to open new file\n");
	    }
	    else
	    {
	      printf( "\n\n\nNew file: %s\n", new_filename);
	      printf( "%%TLOG-E-NEWOPEN, Unable to open new file\n");
	    }
	    continue;
	  }
	  if ( outfile)
	    fprintf( outfile, "\n\n\nNew file: %s\n", new_filename);
	  else
	    printf( "\n\n\nNew file: %s\n", new_filename);

	  /* Read the old file 	*/
	  old_list_count = 0;
	  sts = tlog_insert_file( saved_filename, &old_list, &old_list_count,
		old_filename);
	  if ( EVEN(sts)) 
	  {
	    if ( outfile)
	    {
	      fprintf( outfile, "Old file: %s\n", old_filename);
	      fprintf( outfile, "%%TLOG-E-OLDOPEN, Unable to open old file\n");
	    }
	    else
	    {
	      printf( "Old file: %s\n", old_filename);
	      printf( "%%TLOG-E-OLDOPEN, Unable to open old file\n");
	    }
	    free( new_list);
	    continue;
	  }
	  if ( outfile)
	    fprintf( outfile, "Old file: %s\n", old_filename);
	  else
	    printf( "Old file: %s\n", old_filename);

	  ctx = calloc( 1, sizeof( *ctx));

	  ctx->max_difftime = time;
	  ctx->new_list = new_list;
	  ctx->old_list = old_list;
	  ctx->old_list_count = old_list_count;
	  ctx->new_list_count = new_list_count;
	  ctx->outfile = outfile;
	  ctx->parallell = parallell;
	  ctx->attribute = attribute;
	  ctx->text = text;
	  ctx->ttext = ttext;
	  ctx->noorder = noorder;
	  ctx->exact = exact;
	  strcpy( ctx->new_filename, new_filename);
	  strcpy( ctx->old_filename, old_filename);

	  sts = tlog_lists_cmp( ctx);
	  if ( EVEN(sts)) return sts;

	  diff_count++;
	  free( new_list);
	  free( old_list);
	  free( ctx);
	}
	if ( outfile)
	  fclose( outfile);

        sts = dir_search_file_end( &search_ctx);

	if ( diff_count == 0)
	  if ( outfile)
	    fprintf( outfile, "No files found\n");
	  else
	    printf( "No files found\n");

	return TLOG__SUCCESS;
}
Example #13
0
int XttTCurve::get_data( pwr_tStatus *sts, pwr_tTime from, pwr_tTime to)
{
  pwr_tDeltaTime trange;
  int from_idx, to_idx;
  pwr_tDeltaTime diff;
  pwr_tFloat32 timerange;
  int interval;
  

  load_data( sts, &arefv[0]);
  if ( EVEN(*sts))
    return 0;

  // Calculate interval
  if ( time_Acomp( &from, &tc.last_time) > 0 ||
       time_Acomp( &to, &tc.first_time) < 0)
    // No samples in this interval
    return 0;

  time_Adiff( &diff, &tc.last_time, &tc.first_time);
  timerange = time_DToFloat( 0, &diff);
  if ( time_Acomp( &from, &tc.first_time) < 0) {
    from = tc.first_time;
    from_idx = 0;
  }
  else {
    time_Adiff( &diff, &from, &tc.first_time);
    from_idx = time_DToFloat( 0, &diff) * tc.timebuf_samples / timerange;
  }

  if ( time_Acomp( &to, &tc.last_time) >= 0)
    to_idx = tc.timebuf_samples;
  else {
    time_Adiff( &diff, &tc.last_time, &to);
    to_idx = tc.timebuf_samples - time_DToFloat( 0, &diff) * tc.timebuf_samples / timerange;
  }

  interval = (to_idx - from_idx) / 1000 + 1;

  rows = (to_idx - from_idx) / interval;
  if ( from_idx + rows * interval > tc.timebuf_samples)
    rows = (tc.timebuf_samples - from_idx) / interval;

  // Create data for time axis
  gcd = new GeCurveData( curve_eDataType_DsTrend);

  gcd->x_data[0] = (double *) calloc( 1, 8 * rows);
  if ( tc.timeelement_size == 4) {
    for ( int i = 0; i < rows; i++)
      gcd->x_data[0][i] = (double) (*((unsigned int *)tc.tbuf + from_idx + i * interval));
  }
  else {
    for ( int i = 0; i < rows; i++)
      gcd->x_data[0][i] = (double)(*((unsigned int *)tc.tbuf + 2*from_idx + 2*i*interval)) + 
	(double)1e-9 * (*((unsigned int *)tc.tbuf + 2*from_idx + 2*i*interval + 1));
  }

  strcpy( gcd->x_name, "Time");
  gcd->x_axis_type[0] = curve_eAxis_x;
  strcpy( gcd->x_format[0], "%10t");


  for ( int j = 0; j < tc.bufcnt; j++) {

    strncpy( gcd->y_name[j], tc.name[j], sizeof(gcd->y_name[0]));
    gcd->rows[j] = rows;
    
    gcd->y_data[j] = (double *) calloc( 1, 8 * rows);

    for ( int i = 0; i < rows; i++) {
      if ( i >= tc.buf_samples[j])
	break;
      switch ( tc.type[j]) {
      case pwr_eType_Int64:
	gcd->y_data[j][i] = *((pwr_tInt32 *)tc.vbuf[j] + from_idx + i*interval);
	break;
      case pwr_eType_Int32:
	gcd->y_data[j][i] = *((pwr_tInt32 *)tc.vbuf[j] + from_idx + i*interval);
	break;
      case pwr_eType_Int16:
	gcd->y_data[j][i] = *((pwr_tInt32 *)tc.vbuf[j] + from_idx + i*interval);
	break;
      case pwr_eType_Int8:
	gcd->y_data[j][i] = *((pwr_tInt32 *)tc.vbuf[j] + from_idx + i*interval);
	break;
      case pwr_eType_UInt64:
	gcd->y_data[j][i] = *((pwr_tUInt32 *)tc.vbuf[j] + from_idx + i*interval);
	break;
      case pwr_eType_UInt32:
	gcd->y_data[j][i] = *((pwr_tUInt32 *)tc.vbuf[j] + from_idx + i*interval);
	break;
      case pwr_eType_UInt16:
	gcd->y_data[j][i] = *((pwr_tUInt32 *)tc.vbuf[j] + from_idx + i*interval);
	break;
      case pwr_eType_UInt8:
	gcd->y_data[j][i] = *((pwr_tUInt32 *)tc.vbuf[j] + from_idx + i*interval);
	break;
      case pwr_eType_Float32:
	gcd->y_data[j][i] = *((pwr_tFloat32 *)tc.vbuf[j] + from_idx + i*interval);
	break;
      case pwr_eType_Float64:
	gcd->y_data[j][i] = *((pwr_tFloat64 *)tc.vbuf[j] + from_idx + i*interval);
	break;
      case pwr_eType_Boolean:
	gcd->y_data[j][i] = *((pwr_tBoolean *)tc.vbuf[j] + from_idx + i*interval);
	break;
      default: 
	*sts = SEV__CURVETYPE;
	return 0;
    }
    }
  }

  gcd->y_axis_type[0] = curve_eAxis_y;

  gcd->cols = tc.bufcnt;

  gcd->get_borders();
  gcd->get_default_axis();

  if ( to.tv_sec != 0 && from.tv_sec != 0) {
    time_Adiff( &trange, &to, &from);
    if ( time_DToFloat( 0, &trange) < 600)
      strcpy( gcd->x_format[0], "%10t");
    else
      strcpy( gcd->x_format[0], "%11t");
  }
  else
    strcpy( gcd->x_format[0], "%11t");
    

  gcd->select_color( 0);

  if ( curve) {
    curve->set_curvedata( gcd);  // This will free the old gcd 
    curve->configure_curves();
    curve->configure_axes();
    curve->redraw();
  }
  *sts = XNAV__SUCCESS;
  return 1;
}
Example #14
0
void time_NextPeriod( time_ePeriod period, pwr_tTime *prev_from, pwr_tTime *prev_to,
		      pwr_tTime *from, pwr_tTime *to)
{
  int	    sts;
  pwr_tTime current;

  sts = time_GetTime( &current);

  switch ( period) {
  case time_ePeriod_OneSecond:
  case time_ePeriod_LastSecond:
    *to = *from = *prev_to;
    to->tv_sec += 1;
    if ( time_Acomp( &current, to) != 1) {
      *to = current;
      from->tv_sec = current.tv_sec - 1;
      from->tv_nsec = current.tv_nsec;
    }
    break;
  case time_ePeriod_10Seconds:
  case time_ePeriod_Last10Seconds:
    *to = *from = *prev_to;
    to->tv_sec += 10;
    if ( time_Acomp( &current, to) != 1) {
      *to = current;
      from->tv_sec = current.tv_sec - 10;
      from->tv_nsec = current.tv_nsec;
    }
    break;
  case time_ePeriod_OneMinute:
  case time_ePeriod_LastMinute:
    *to = *from = *prev_to;
    to->tv_sec += 60;
    if ( time_Acomp( &current, to) != 1) {
      *to = current;
      from->tv_sec = current.tv_sec - 60;
      from->tv_nsec = current.tv_nsec;
    }
    break;
  case time_ePeriod_10Minutes:
  case time_ePeriod_Last10Minutes:
    *to = *from = *prev_to;
    to->tv_sec += 600;
    if ( time_Acomp( &current, to) != 1) {
      *to = current;
      from->tv_sec = current.tv_sec - 600;
      from->tv_nsec = current.tv_nsec;
    }
    break;
  case time_ePeriod_OneHour:
  case time_ePeriod_LastHour:
    *to = *from = *prev_to;
    to->tv_sec += 3600;
    if ( time_Acomp( &current, to) != 1) {
      *to = current;
      from->tv_sec = current.tv_sec - 3600;
      from->tv_nsec = current.tv_nsec;
    }
    break;
  case time_ePeriod_OneDay:
  case time_ePeriod_Today:
  case time_ePeriod_Yesterday:
    *to = *from = *prev_to;
    to->tv_sec += ONEDAY;
    if ( time_Acomp( &current, to) != 1) {
      *to = current;
      from->tv_sec = current.tv_sec - ONEDAY;
      from->tv_nsec = current.tv_nsec;
    }
    break;
  case time_ePeriod_OneWeek:
  case time_ePeriod_ThisWeek:
  case time_ePeriod_LastWeek:
    *to = *from = *prev_to;
    to->tv_sec += 7 * ONEDAY;
    if ( time_Acomp( &current, to) != 1) {
      *to = current;
      from->tv_sec = current.tv_sec - 7 * ONEDAY;
      from->tv_nsec = current.tv_nsec;
    }
    break;
  case time_ePeriod_OneMonth:
  case time_ePeriod_ThisMonth:
  case time_ePeriod_LastMonth:
    time_PeriodMonth( prev_to, from, to, 0);
    to->tv_sec += prev_to->tv_sec - from->tv_sec;
    *from = *prev_to;
    if ( time_Acomp( &current, to) != 1) {
      *to = current;
      from->tv_sec = current.tv_sec - 30 * ONEDAY;
      from->tv_nsec = current.tv_nsec;
    }
    break;
  case time_ePeriod_OneYear:
  case time_ePeriod_ThisYear:
    time_PeriodYear( prev_to, from, to, 0);
    to->tv_sec += prev_to->tv_sec - from->tv_sec;
    *from = *prev_to;
    if ( time_Acomp( &current, to) != 1) {
      *to = current;
      from->tv_sec = current.tv_sec - 365 * ONEDAY;
      from->tv_nsec = current.tv_nsec;
    }
    break;
    break;
  case time_ePeriod_AllTime:
    time_Period( period, from, to, 0, 1);
    break;
  case time_ePeriod_UserDefined:
    // Same lenth of intervall as before
    *to = *from = *prev_to;
    to->tv_sec += prev_to->tv_sec - prev_from->tv_sec;
    if ( time_Acomp( &current, to) != 1) {
      *to = current;
      from->tv_sec = current.tv_sec - (prev_to->tv_sec - prev_from->tv_sec);
      from->tv_nsec = current.tv_nsec;
    }
    break;
  default: ;
  }
}
Example #15
0
pwr_tUInt32 bck_WaitBackup (
		void *context,
		pwr_tBoolean timeout)
{
  pwr_tUInt32 sts;
  pwr_tObjid objid;
  pwr_tInt32 c;
  pwr_tTime t;
  pwr_tVaxTime tmo;
  pwr_tVaxTime tmptime;
  pwr_sClass_Backup_Conf *backup_confp;	/* Backup_Conf object pointer */
  $DESCRIPTOR (timeunitdsc, "0 0:0:0.1");	/* 0.1 second units */
  int cycletime;

#ifdef OS_ELN
  pwr_tInt32 res;
  pwr_tVaxTime *tmop;
#endif

#ifdef OS_VMS
  $DESCRIPTOR (efcname, BCK_EFC_NAME);
#endif

/*
 * Initialize
 */

#ifdef OS_ELN
  if (!areas_mapped) {
    BCK_MAP_AREAS;
    areas_mapped = TRUE;
  }
#endif

/*
 * Find the local Backup_Conf object
 */

  sts = gdh_GetClassList (pwr_cClass_Backup_Conf, &objid);
  while (ODD (sts)) {
    sts = gdh_ObjidToPointer (objid, (pwr_tAddress *)&backup_confp);
    if (ODD (sts)) break;
    sts = gdh_GetNextObject (objid, &objid);
  }
  if (EVEN (sts)) return sts;		/* Something wrong, quit */

/*
 * Pick up argument information
 */

  if (context == NULL) time_GetTime(&t);
  else {
    t = *(pwr_tTime *)context;
    free (context);
  }

#ifdef OS_ELN
  tmop = NULL;
#else
  timed_out = FALSE;  
  sts = sys$ascefc (BCK_EFC, &efcname, 0, 0);
  if (EVEN (sts)) lib$signal (sts);			/* BUG */
#endif

  if (timeout) {
    cycletime = backup_confp->CycleSlow * 2;
    if (cycletime == 0) cycletime = BCK_DEFAULT_SLOW * 2;

#ifdef OS_ELN
    tmo = eln$time_value (&timeunitdsc);
#else
    sts = sys$bintim (&timeunitdsc, &tmo);
    if (EVEN (sts)) lib$signal (sts);		/* BUG, should not happen */
#endif

    lib$mult_delta_time (
		&cycletime,		/* multiplier */
		&tmo);			/* delta_time (modified) */
    sys$gettim (&tmptime);
    lib$add_times (&tmo, &tmptime, &tmo); /* Make absolute time */

#ifdef OS_ELN
    tmop = &tmo;
#else
    sts = sys$setimr (BCK_WRITE_DONE, &tmo, &astrtn, 4711, 0);
    if (EVEN (sts)) lib$signal (sts);			/* BUG */
#endif
  }

/*
 * Loop, and wait for things to happen
 */

  while (TRUE) {
#ifdef OS_ELN
    ker$clear_event (NULL, bck_write_done);
    ker$wait_any (NULL, &res, tmop, bck_write_done);

    /* Check for timeout */

    if (res == 0) return SS$_TIMEOUT;
#else

    sts = sys$clref (BCK_WRITE_DONE);
    if (EVEN (sts)) lib$signal (sts);			/* BUG */
    sts = sys$waitfr (BCK_WRITE_DONE);
    if (EVEN (sts)) lib$signal (sts);			/* BUG */

    /* Check for timeout */

    if (timed_out) return SS$_TIMEOUT;

#endif

    /* Check if both cycles done */

    if (time_Acomp(&backup_confp->ObjTimeSlow, &t) < 0) 
        continue;
    if (time_Acomp(&backup_confp->ObjTimeFast, &t) < 0) 
        continue;

    break;

  } /* Loop */

#ifdef OS_VMS
  sys$cantim (4711, 0);
#endif

  return 1;	/* Done. */

} /* bck_WaitBackup */
Example #16
0
void wb_build::webhandler( pwr_tOid oid)
{
  pwr_tTime	modtime;
  pwr_tString80 file_name, name;
  pwr_tFileName fname;
  pwr_tTime 	ftime;
  pwr_tTime	xtthelp_time, html_time;
  char 		*s;
  pwr_tStatus   fsts;

  wb_object o = m_session.object(oid);
  if ( !o) {
    m_sts = o.sts();
    return;
  }

  modtime = o.modTime();

  wb_attribute a = m_session.attribute( oid, "RtBody", "FileName");
  if ( !a) {
    m_sts = a.sts();
    return;
  }
  a.value( &file_name);
  if ( !a) {
    m_sts = a.sts();
    return;
  }
  // Parse the name of the start page
  if ( (s = strrchr( file_name, '/')) ||
       (s = strrchr( file_name, '<')) ||
       (s = strrchr( file_name, ':')))
    strcpy( name, s+1);
  else
    strcpy( name, file_name);

  if ( (s = strrchr( name, '.')))
    *s = 0;

  sprintf( fname, "$pwrp_web/%s_opwin_menu.html", name);
  dcli_translate_filename( fname, fname);
  fsts = dcli_file_time( fname, &ftime);

  m_sts = PWRB__NOBUILT;
  if ( opt.force || EVEN(fsts) || time_Acomp( &modtime, &ftime) == 1) {
    // modtime > ftime
    m_sts = Graph::generate_web( (ldh_tSession *)&m_session);
    if ( evenSts()) return;

    char msg[200];
    sprintf( msg, "Build:    WebHandler Webpage generated %s", fname);
    MsgWindow::message( 'I', msg, msgw_ePop_No, oid);
  }

  // Check if xtthelp should be converted to html
  dcli_translate_filename( fname, "$pwrp_exe/xtt_help.dat");
  fsts = dcli_file_time( fname, &xtthelp_time);
  if ( EVEN(fsts)) return;
  
  dcli_translate_filename( fname, "$pwrp_web/xtt_help_index.html");
  fsts = dcli_file_time( fname, &html_time);
  if ( opt.force || EVEN(fsts) || time_Acomp( &xtthelp_time, &html_time) == 1) {
    system( "co_convert -d $pwrp_web -t $pwrp_exe/xtt_help.dat");

    char msg[200];
    sprintf( msg, "Build:    WebHandler xtt_help.dat converted to html");
    MsgWindow::message( 'I', msg, msgw_ePop_No, oid);
    m_sts = PWRB__SUCCESS;
  }

  // Generate wb history html file
  pwr_tCmd cmd;
  strcpy( cmd, "generate history");
  m_wnav->command( cmd);

}
Example #17
0
void time_Period( time_ePeriod period, pwr_tTime *from, pwr_tTime *to, pwr_tTime *center, 
		  int daybreak)
{
  int	    sts;
  pwr_tTime current;

  switch ( period) {
  case time_ePeriod_OneSecond:
    if ( !center) {
      time_Period( time_ePeriod_LastSecond, from, to, center, daybreak);
      return;
    }
    time_PeriodSec( from, to, center, 1);
    break;
  case time_ePeriod_10Seconds:
    if ( !center) {
      time_Period( time_ePeriod_10Seconds, from, to, center, daybreak);
      return;
    }
    time_PeriodSec( from, to, center, 10);
    break;
  case time_ePeriod_OneMinute:
    if ( !center) {
      time_Period( time_ePeriod_LastMinute, from, to, center, daybreak);
      return;
    }
    time_PeriodSec( from, to, center, 60);
    break;
  case time_ePeriod_10Minutes:
    if ( !center) {
      time_Period( time_ePeriod_Last10Minutes, from, to, center, daybreak);
      return;
    }
    time_PeriodSec( from, to, center, 600);
    break;
  case time_ePeriod_OneHour:
    if ( !center) {
      time_Period( time_ePeriod_LastHour, from, to, center, daybreak);
      return;
    }
    time_PeriodSec( from, to, center, 3600);
    break;
  case time_ePeriod_OneDay:
    if ( !center) {
      time_Period( time_ePeriod_LastHour, from, to, center, daybreak);
      return;
    }
    time_PeriodSec( from, to, center, ONEDAY);
    break;
  case time_ePeriod_OneWeek:
    if ( !center) {
      time_Period( time_ePeriod_LastWeek, from, to, center, daybreak);
      return;
    }
    time_PeriodSec( from, to, center, 7 * ONEDAY);
    break;
  case time_ePeriod_OneMonth:
    if ( !center) {
      time_Period( time_ePeriod_LastMonth, from, to, center, daybreak);
      return;
    }
    time_PeriodMonth( center, from, to, 0);
    int middle = from->tv_sec + (to->tv_sec - from->tv_sec) / 2;
    int half = middle - from->tv_sec;
    if ( center->tv_sec >= middle - ONEDAY/2 &&
	 center->tv_sec <= middle + ONEDAY/2)
      return;

    if ( center->tv_sec < middle) {
      // Take period from previous month
      time_PeriodMonth( center, from, to, 1);
      middle = from->tv_sec + (to->tv_sec - from->tv_sec) / 2;
      half = middle - from->tv_sec;
    }
    to->tv_sec = center->tv_sec + half;
    from->tv_sec = center->tv_sec - half;

    sts = time_GetTime( &current);
    if ( time_Acomp( to, &current) == 1) {
      from->tv_sec = current.tv_sec - (to->tv_sec - from->tv_sec);
      from->tv_nsec = current.tv_sec;
      *to = current;
    }
    break;
  case time_ePeriod_LastSecond:
    sts = time_GetTime( to);
    from->tv_sec = to->tv_sec - 1;
    from->tv_nsec = to->tv_nsec;
    break;
  case time_ePeriod_Last10Seconds:
    sts = time_GetTime( to);
    from->tv_sec = to->tv_sec - 10;
    from->tv_nsec = to->tv_nsec;
    break;
  case time_ePeriod_LastMinute:
    sts = time_GetTime( to);
    from->tv_sec = to->tv_sec - 60;
    from->tv_nsec = to->tv_nsec;
    break;
  case time_ePeriod_Last10Minutes:
    sts = time_GetTime( to);
    from->tv_sec = to->tv_sec - 600;
    from->tv_nsec = to->tv_nsec;
    break;
  case time_ePeriod_LastHour:
    sts = time_GetTime( to);
    from->tv_sec = to->tv_sec - 3600;
    from->tv_nsec = to->tv_nsec;
    break;
  case time_ePeriod_Today:
    sts = time_GetTime( from);
    *to = *from;

    time_PreviousDayBreak( from, from);

    if ( daybreak) {
      to->tv_sec += ONEDAY;
      time_PreviousDayBreak( to, to);
    }
    break;
  case time_ePeriod_Yesterday:
    sts = time_GetTime( to);
    time_PreviousDayBreak( to, to);
    
    from->tv_sec = to->tv_sec - ONEDAY;
    from->tv_nsec = 0;
    break;
  case time_ePeriod_ThisWeek:
    sts = time_GetTime( &current);

    sts = time_PeriodPreviousWeek( &current, 0, from);

    *to = current;
    if ( daybreak) {
      to->tv_sec += ONEDAY;
      time_PreviousDayBreak( to, to);
    }
    break;
  case time_ePeriod_LastWeek:
    sts = time_GetTime( &current);

    sts = time_PeriodPreviousWeek( &current, from, to);
    break;
  case time_ePeriod_ThisMonth:
    sts = time_GetTime( &current);

    sts = time_PeriodMonth( &current, 0, from, 1);

    *to = current;
    if ( daybreak) {
      to->tv_sec += ONEDAY;
      time_PreviousDayBreak( to, to);
    }
    break;
  case time_ePeriod_LastMonth:
    sts = time_GetTime( &current);

    sts = time_PeriodMonth( &current, from, to, 1);
    break;
  case time_ePeriod_OneYear:
  case time_ePeriod_ThisYear:
    sts = time_GetTime( &current);

    sts = time_PeriodYear( &current, 0, from, 1);

    *to = current;
    if ( daybreak) {
      to->tv_sec += ONEDAY;
      time_PreviousDayBreak( to, to);
    }
    break;
  default: {
    // time_ePeriod_All: 
    struct tm	*tm;

    sts = time_GetTime( to);
    if ( daybreak) {
      to->tv_sec += ONEDAY;
      time_PreviousDayBreak( to, to);
    }

    time_t sec = to->tv_sec;
    tm = localtime(&sec);
    tm->tm_sec = 0; 
    tm->tm_min = 0; 
    tm->tm_hour = 0; 
    tm->tm_mday = 1; 
    tm->tm_mon = 0; 
    tm->tm_year = 70; 
    from->tv_sec = mktime(tm); 
    from->tv_nsec = 0;    

    break;
  }
  }
}
Example #18
0
void wb_build::webbrowserconfig( pwr_tOid oid)
{
  pwr_tTime	modtime;
  pwr_tFileName fname;
  pwr_tTime 	ftime;
  pwr_tStatus   fsts;
  FILE 		*fp;
  int		i, j;
  int		found;
  char		line[200];
  pwr_tObjName  vname;

  strncpy( vname, m_session.name(), sizeof(vname));

  wb_object o = m_session.object(oid);
  if ( !o) {
    m_sts = o.sts();
    return;
  }

  modtime = o.modTime();

  sprintf( fname, "$pwrp_db/pwrp_cnf_websymbols.dat");
  dcli_translate_filename( fname, fname);
  fsts = dcli_file_time( fname, &ftime);

  m_sts = PWRB__NOBUILT;
  if ( opt.force || EVEN(fsts) || time_Acomp( &modtime, &ftime) == 1) {
    pwr_sClass_WebBrowserConfig body;
    int url_symbols_size = sizeof(body.URL_Symbols)/sizeof(body.URL_Symbols[0]);
    char sym_vect[MAXSYMBOLS][80];
    char value_vect[MAXSYMBOLS][80];
    char volume_vect[MAXSYMBOLS][80];
    int vect_cnt;
    int nr;
    char elemv[3][80];
    
    wb_attribute a = m_session.attribute( oid, "RtBody", "URL_Symbols");
    if ( !a) {
      m_sts = a.sts();
      return;
    }
    a.value( body.URL_Symbols);
    if ( !a) {
      m_sts = a.sts();
      return;
    }

    // Read the file and merge the symbols of this volume with other symbols in the project
    vect_cnt = 0;
    fp = fopen( fname, "r");
    if ( fp) {
      while ( dcli_read_line( line, sizeof( line), fp)) {
	nr = dcli_parse( line, " ", "", (char *)elemv, sizeof( elemv) / sizeof( elemv[0]), 
			 sizeof( elemv[0]), 0);
	if ( nr != 3)
	  continue;

	// Skip old symbols from this volume
	if ( cdh_NoCaseStrcmp( vname, elemv[0]) == 0)
	  continue;

	strcpy( volume_vect[vect_cnt], elemv[0]);
	strcpy( sym_vect[vect_cnt], elemv[1]);
	strcpy( value_vect[vect_cnt], elemv[2]);
	vect_cnt++;
      }
      fclose( fp);
    }

    for ( i = 0; i < url_symbols_size; i++) {
      nr = dcli_parse( body.URL_Symbols[i], " ", "", (char *)elemv, sizeof( elemv) / sizeof( elemv[0]), 
		       sizeof( elemv[0]), 0);
      if ( nr != 2)
	continue;
      
      found = 0;
      for ( j = 0; j < vect_cnt; j++) {
	if ( cdh_NoCaseStrcmp( elemv[0], sym_vect[j]) == 0) {
	  strcpy( value_vect[j], elemv[1]);
	  found = 1;
	  break;
	}
      }
      if ( !found) {
	// Insert first
	for ( j = MIN(vect_cnt,MAXSYMBOLS-1); j > 0; j--) {
	  strcpy( volume_vect[j], volume_vect[j-1]);
	  strcpy( sym_vect[j], sym_vect[j-1]);
	  strcpy( value_vect[j], value_vect[j-1]);
	}
	strcpy( volume_vect[0], vname);
	strcpy( sym_vect[0], elemv[0]);
	strcpy( value_vect[0], elemv[1]);	
	vect_cnt++;
	if ( vect_cnt > MAXSYMBOLS)
	  vect_cnt = MAXSYMBOLS;
      }
    }

    // Write the file
    fp = fopen( fname, "w");
    if ( !fp) {
      char msg[200];
      sprintf( msg, "Build:    Unable to open file %s", fname);
      MsgWindow::message( 'E', msg, msgw_ePop_No, oid);
      return;
    }

    for ( i = 0; i < vect_cnt; i++)
      fprintf( fp, "%s %s %s\n", volume_vect[i], sym_vect[i], value_vect[i]);
    fclose( fp);
  }
}
Example #19
0
int main (int argc, char **argv)
{
  pwr_tStatus	    sts;
  pwr_tObjid	    ObjId;
  pwr_sClass_DsTrendConf *TConfP;
  pwr_tBoolean    InitOK;
  pwr_tTime		CurrentTime, LastScan, NextScan;
  pwr_tDeltaTime	ScanDeltaTime, WaitTime;
  qcom_sQid qini;
  qcom_sQattr qAttr;
  int tmo;
  char mp[2000];
  qcom_sQid qid = qcom_cNQid;
  qcom_sGet get;
  int swap = 0;
  trend_tCtx ctx;

  errh_Init("pwr_trend", errh_eAnix_trend);
  errh_SetStatus( PWR__SRVSTARTUP);

  sts = gdh_Init("ds_trend");
  If_Error_Log_Exit(sts, "gdh_Init");

  if (!qcom_Init(&sts, 0, "pwr_trend")) {
    errh_Fatal("qcom_Init, %m", sts);
    exit(sts);
  } 

  qAttr.type = qcom_eQtype_private;
  qAttr.quota = 100;
  if (!qcom_CreateQ(&sts, &qid, &qAttr, "events")) {
    errh_Fatal("qcom_CreateQ, %m", sts);
    exit(sts);
  } 

  qini = qcom_cQini;
  if (!qcom_Bind(&sts, &qid, &qini)) {
    errh_Fatal("qcom_Bind(Qini), %m", sts);
    exit(-1);
  }

  ctx = (trend_tCtx) calloc( 1, sizeof(trend_sCtx));

  /* Wait until local nethandler has started */
  while(EVEN(gdh_NethandlerRunning()))
    sleep(1);

  /* Fetch ScanTime */
  sts = gdh_GetClassList(pwr_cClass_DsTrendConf, &ObjId);
  if (EVEN(sts)) {
    errh_Info("Couldn't get the DsTrendConf object. Used ScanTime = 1 s");
    ctx->scantime = 1;
    ctx->scantime_tc = 1.0;
  } 
  else {
    gdh_ObjidToPointer(ObjId, (pwr_tAddress *)&TConfP);
    ctx->scantime = TConfP->ScanTime;
    if ( ctx->scantime > 3600)
      ctx->scantime = 3600;
    else if ( ctx->scantime < 1)
      ctx->scantime = 1;

    ctx->scantime_tc = TConfP->ScanTime;
    if ( ctx->scantime_tc > 3600)
      ctx->scantime_tc = 3600;
  }
  ctx->dstrend_multiple = (int) (ctx->scantime / ctx->scantime_tc + 0.5);

  aproc_RegisterObject( ObjId);

  InitOK = FALSE;
  sts = InitTrendList( ctx);
  if ( EVEN(sts)) { 
    /* This should be removed when we can wait for init messages. */
    errh_SetStatus(0);
    errh_Info("No DsTrend objects configured");
    exit(0);
  }

  /* If even sts, just wait for init message */

  time_GetTimeMonotonic(&LastScan);
  time_FloatToD( &ScanDeltaTime, ctx->scantime_tc);

  aproc_TimeStamp( ctx->scantime, 5.0);
  errh_SetStatus( PWR__SRUN);

  for (;;) {

    time_GetTimeMonotonic(&CurrentTime);
    time_Aadd(&NextScan, &LastScan, &ScanDeltaTime);
    if (time_Acomp(&CurrentTime, &NextScan) < 0) { 
      time_Adiff(&WaitTime, &NextScan, &CurrentTime);
      tmo = 1000 * time_DToFloat( 0, &WaitTime);

      get.maxSize = sizeof(mp);
      get.data = mp;
      qcom_Get( &sts, &qid, &get, tmo);
      if (sts == QCOM__TMO || sts == QCOM__QEMPTY) {
	if ( !swap)
	  StoreData( ctx);
      } 
      else {
	ini_mEvent  new_event;
	qcom_sEvent *ep = (qcom_sEvent*) get.data;

	new_event.m  = ep->mask;
	if (new_event.b.oldPlcStop && !swap) {
	  swap = 1;
	  errh_SetStatus( PWR__SRVRESTART);
	  CloseTrendList( ctx);
	} 
	else if (new_event.b.swapDone && swap) {
	  swap = 0;
	  sts = InitTrendList( ctx);
	  errh_SetStatus( PWR__SRUN);
	  errh_Info("Warm restart completed");
	}
	else if (new_event.b.terminate) {
	  exit(0);
	}
      }
    }
    else if ( !swap)
      StoreData( ctx);

    LastScan = NextScan;

    aproc_TimeStamp( ctx->scantime, 5.0);
  }

  return 1;
}
Example #20
0
void wb_build::rootvolume( pwr_tVid vid)
{
  pwr_tStatus 		sumsts, plcsts;
  pwr_tOid		oid;
  pwr_tTime		modtime;
  pwr_tObjName		vname;
  pwr_tFileName		fname;
  pwr_tTime		dbs_time, rtt_time;
  pwr_tCmd		cmd;
  char			msg[80];

  wb_log::push();

  if ( !opt.manual) {
    // Build all plcpgm
    classlist( pwr_cClass_plc);
    if ( evenSts()) return;
    plcsts = sumsts = m_sts;

    // Build all XttGraph
    classlist( pwr_cClass_XttGraph);
    if ( evenSts()) return;
    if ( sumsts == PWRB__NOBUILT && m_sts != PWRB__NOBUILT)
      sumsts = m_sts;

    classlist( pwr_cClass_WebHandler);
    if ( evenSts()) return;
    if ( sumsts == PWRB__NOBUILT && m_sts != PWRB__NOBUILT)
      sumsts = m_sts;

    classlist( pwr_cClass_WebBrowserConfig);
    if ( evenSts()) return;
    if ( sumsts == PWRB__NOBUILT && m_sts != PWRB__NOBUILT)
      sumsts = m_sts;

    // Build all WebGraph
    classlist( pwr_cClass_WebGraph);
    if ( evenSts()) return;
    if ( sumsts == PWRB__NOBUILT && m_sts != PWRB__NOBUILT)
      sumsts = m_sts;

    // Build all AppGraph
    classlist( pwr_cClass_AppGraph);
    if ( evenSts()) return;
    if ( sumsts == PWRB__NOBUILT && m_sts != PWRB__NOBUILT)
      sumsts = m_sts;

    classlist( pwr_cClass_Application);
    if ( evenSts()) return;
    if ( sumsts == PWRB__NOBUILT && m_sts != PWRB__NOBUILT)
      sumsts = m_sts;

    classlist( pwr_cClass_PlcProcess);
    if ( evenSts()) return;
    if ( sumsts == PWRB__NOBUILT && m_sts != PWRB__NOBUILT)
      sumsts = m_sts;
  }
  wb_log::pull();

  // Create loadfiles
  oid.oix = 0;
  oid.vid = m_session.vid();
  wb_attribute a = m_session.attribute( oid, "SysBody", "Modified");
  if ( !a) {
    m_sts = a.sts();
    return;
  }

  a.value( &modtime);
  if ( !a) {
    m_sts = a.sts();
    return;
  }

  cdh_ToLower( vname, m_session.name());
  sprintf( fname, "$pwrp_load/%s.dbs", vname);
  dcli_translate_filename( fname, fname);
  m_sts = dcli_file_time( fname, &dbs_time);

  // Get time for classvolumes
  wb_merep *merep = ((wb_vrep *)m_session)->merep();
  pwr_tTime mtime = pwr_cNTime;
  pwr_tTime t;
  pwr_tStatus sts;
  for ( wb_mvrep *mvrep = merep->volume( &sts);
	ODD(sts);
	mvrep = merep->nextVolume( &sts, mvrep->vid())) {
    mvrep->time( &t);
    if ( time_Acomp( &t, &mtime) == 1)
      mtime = t;
  }

  if ( opt.force || opt.manual || evenSts() || time_Acomp( &modtime, &dbs_time) == 1 ||
       time_Acomp( &mtime, &dbs_time) == 1 || plcsts != PWRB__NOBUILT) {
    m_sts = lfu_create_loadfile( (ldh_tSession *) &m_session);
    if ( evenSts()) return;
    m_sts = ldh_CreateLoadFile( (ldh_tSession *) &m_session);
    if ( evenSts()) return;

    sprintf( msg, "Build:    Volume   Loadfiles created volume %s", m_session.name());
    MsgWindow::message('I', msg, msgw_ePop_No);

    wb_log::log( &m_session, wlog_eCategory_VolumeBuild, m_session.vid());

    sumsts = PWRB__SUCCESS;
  }
  else
    m_sts = sumsts;

  cdh_uVolumeId	uvid;
  uvid.pwr = m_session.vid();
  sprintf( fname, "$pwrp_load/" load_cNameRttCrr,
	   uvid.v.vid_3, uvid.v.vid_2, uvid.v.vid_1, uvid.v.vid_0);
  dcli_translate_filename( fname, fname);
  m_sts = dcli_file_time( fname, &rtt_time);
  if ( opt.crossref && ( evenSts() || time_Acomp( &modtime, &rtt_time) == 1)) {
    strcpy( cmd, "create crossreferencefiles");
    m_wnav->command( cmd);
    if ( ODD(sumsts))
      sumsts = PWRB__SUCCESS;
	 
    sprintf( msg, "Build:    Volume   Crossreference file generated volume %s", m_session.name());
    MsgWindow::message('I', msg, msgw_ePop_No);
  }


  m_sts = sumsts;
}
Example #21
0
static void *mb_connect( void *arg)
{
  io_sRack *rp = (io_sRack *)arg;
  io_sServerLocal* local = rp->Local;
  int sts;
  pwr_sClass_Modbus_TCP_Server *op;
  struct sockaddr_in r_addr;
  socklen_t r_addr_len;
  int c_socket;
  mb_sCondata *condata;
  int idx;
  int found;
  int i;
  
  op = (pwr_sClass_Modbus_TCP_Server *) rp->op;


  while ( 1) {
    /* Wait for client connect request */
    r_addr_len = sizeof(r_addr);

    c_socket = accept( local->s, (struct sockaddr *) &r_addr, &r_addr_len);
    if ( c_socket < 0) {
      errh_Error( "Error accept IO modbus tcp server %s, %d", rp->Name, local->s);
      continue;
    }
    if ( op->DisableServer)
      continue;

    errh_Info( "Connection accepted for IO modbus tcp server %s, %d", rp->Name, c_socket);

    /* Close other connections to this address */
    for ( i = 0; i < MB_MAX_CONNECTIONS; i++) {
      if ( local->connections[i].occupied && 
	   r_addr_len == local->connections[i].addrlen &&
	   r_addr.sin_family == local->connections[i].addr.sin_family &&
	   memcmp( &r_addr.sin_addr, &local->connections[i].addr.sin_addr, sizeof(r_addr.sin_addr)) == 0) {
	mb_close_connection( rp, i);
      }
    }
    

    /* Find next empty in connection list */
    found = 0;
    for ( i = 0; i < MB_MAX_CONNECTIONS; i++) {
      if ( !local->connections[i].occupied) {
	found = 1;
	idx = i;
	break;
      }
    }

    if ( !found) {
      /* Remove the oldest connection */
      int oldest_idx = 0;

      for ( i = 1; i < MB_MAX_CONNECTIONS; i++) {
	if ( time_Acomp( &local->connections[i].last_req_time, &local->connections[oldest_idx].last_req_time) < 0)
	  oldest_idx = i;
      }
      mb_close_connection( rp, oldest_idx);
      errh_Info( "Connection closed, IO modbus tcp server %s, %d", rp->Name, local->s);
      idx = oldest_idx;
    }

    local->connections[idx].c_socket = c_socket;
    local->connections[idx].occupied = 1;
    time_GetTime( &local->connections[idx].last_req_time);
    local->connections[idx].addrlen = r_addr_len;
    memcpy( &local->connections[idx].addr, &r_addr, r_addr_len);

    /* Create a thread for this connection */
    condata = (mb_sCondata *) malloc( sizeof(mb_sCondata));
    condata->rp = rp;
    condata->idx = idx;
    

    sts = thread_Create( &local->connections[idx].t, 0, mb_receive, (void *)condata);
    if ( EVEN(sts)) {
      local->connections[idx].occupied = 0;
      errh_Error( "Error creating thread IO modbus tcp server %s, %d", rp->Name, local->s);
      free( condata);
      continue;
    }
  }
  return 0;
}
Example #22
0
/** Handle GetCclass message */
void
cmvolsm_GetCclass (
  qcom_sGet		*get
  )
{
  pwr_tStatus		sts;
  pwr_tStatus		lsts;
  int			size;
  net_sGetCclassR	*rmp = NULL;
  net_sGetCclass	*mp = get->data;
  qcom_sPut		put;
  gdb_sAttribute        *ap;
  net_sCattribute       *cap;
  gdb_sClass            *cp;
  gdb_sObject           *cop;
  int                   i;  
  pwr_tBoolean          equal = FALSE;
  const int		maxacnt = ((net_cSizeLarge - sizeof(*rmp)) / sizeof(rmp->attr[0])) + 1;  
  int			maxaidx;
  int			acnt;
  pwr_tTime		mp_time;

  gdb_AssumeUnlocked;

  gdb_ScopeLock {
    
    cp = hash_Search(&sts, gdbroot->cid_ht, &mp->cid);
    if (cp == NULL) 
      break;
    
    cop = pool_Address(NULL, gdbroot->pool, cp->cor);
    mp_time = net_NetTimeToTime(&mp->time);
    if (time_Acomp(&mp_time, &cop->u.n.time) == 0) {
      equal = TRUE;
      size = sizeof(*rmp);
    } else {
      acnt = MIN(maxacnt, cp->acount - mp->aidx);
      maxaidx = acnt + mp->aidx;
      size = sizeof(*rmp) + MAX(0, (acnt - 1)) * sizeof(rmp->attr[0]);
    }
  

    rmp = net_Alloc(&sts, &put, size, net_eMsg_getCclassR);
    if (rmp == NULL) {
      errh_Error("cmvolsm_GetCclass. net_Alloc, size %d, cid %d, error %m", size, mp->cid, sts);
      break;
    }
    
    rmp->ver = net_cVersion;
    rmp->sts = 1;
    rmp->equal = equal;      


    if (equal) {
      rmp->acntmsg = 0;
      rmp->cclass.size = 0;
      rmp->cclass.acount = 0;

      break;
    }    

    rmp->cclass.cid = mp->cid;
    rmp->cclass.time = net_TimeToNetTime(&cop->u.n.time);
    rmp->cclass.size = cp->size;
    rmp->cclass.acount = cp->acount;

    for (i = mp->aidx, ap = &cp->attr[mp->aidx], cap = rmp->attr; 
         i < maxaidx; 
         i++, ap++, cap++
    ) {
      cap->aix = ap->aix;
      cap->flags = ap->flags;
      cap->type = ap->type;
      cap->offs = ap->offs;
      cap->size = ap->size;
      cap->elem = ap->elem;
      cap->moffset = ap->moffset;
    }

    rmp->acntmsg = acnt;
    rmp->saidx = mp->aidx;
    rmp->naidx = (i == cp->acount) ? UINT_MAX : i;

  } gdb_ScopeUnlock;


  if (EVEN(sts)) {    
    rmp = net_Alloc(&lsts, &put, sizeof(*rmp), net_eMsg_getCclassR);
    if (EVEN(lsts)) {
      errh_Error("cmvolsm_GetCclass. net_Alloc, size %d, cid %d, error %m", sizeof(*rmp), mp->cid, lsts);
      return;
    }
    rmp->ver = net_cVersion;
  }  


  if (EVEN(sts))
    rmp->sts = sts;
  else 
    rmp->sts = 1;

  net_Reply(&lsts, get, &put, 0);  
}