Пример #1
0
//
// Create a new foe window
// SG 09.02.91 : Create a new toplevel widget and give it an pixmap icon
// SG : 13.02.91 Fetch a caution box and save the id of the widget in the 
//               foe context for futher use
// SG : 24.02.91 Fetch a widget ( again !) . This time a message box
// SG : 24.03.91 Send the routine the desired position (x_top , y_top) 
// and the desired size ( width_adb , height_adb ) for the window to be created.
// The two first parameters are set to the top level widget
// and the two last paramters are set to the adb widget (see in uil file
// the widget hierarchy )
// SG 14.04.91 A new widget to fetch , the help widget ! 
// SG 2.05.91 New parameter : function ( edit , trace , view , simulate ..)
// to indicate which neted events and which menu entries should be alllowed.
//
pwr_tStatus WFoeMotif::create_window( int x_top,
				 int y_top,
				 int width_adb,
				 int height_adb, 
				 ldh_tSesContext ldhsession,
				 foe_eFuncAccess function_access)
{
  Arg	args[20];
  int	sts;
  Widget *children;
  int i, num_children;
  XmString   	TitleStr;
  Dimension icon_w, icon_h;

  /* DRM database hierarchy related variables */
  MrmHierarchy s_MrmH;
  MrmType dclass;
  char		uid_filename[200] = {"pwr_exe:wb_foe.uid"};
  char		*uid_filename_p = uid_filename;
  static Atom	MwmDeleteWind = 0;
  static char translations[] = "\
<FocusIn>: foe_inputfocus()\n";
  static XtTranslations compiled_translations = NULL;

  static XtActionsRec actions[] =
    {
      {(char*) "foe_inputfocus",      (XtActionProc) action_inputfocus}
    };
       
  sts = dcli_translate_filename( uid_filename, uid_filename);
  if ( EVEN(sts)) {
    printf( "** pwr_exe is not defined\n");
    exit(0);
  }

  /*
   * Now start the module creation
   */

  /* Save the context structure in the widget */
  XtSetArg (args[0], XmNuserData, (XtPointer) this);

  /*
   * Create a new main widget
   */
  /*
   * Open the UID files (the output of the UIL compiler) in the hierarchy
   * Register the items DRM needs to bind for us.
   * Create a new neted-widget
   * Close the hierarchy
   * Compile the additional button translations and augment and add actions
   */ 
  sts = MrmOpenHierarchy( 1, &uid_filename_p, NULL, &s_MrmH);
  if (sts != MrmSUCCESS) {
    printf("can't open hierarchy\n");
    return 0;
  }

  register_callbacks();

  /* SG 09.02.91 : create the new hierarchy. By the way use a pixmap define
  with help of wb_foe_ptrn.h */

  /* create a pixmap for the icon */
  if ( icon_pixmap == 0 )
    sts = MrmFetchBitmapLiteral(s_MrmH,(char*) "icon",
				XtScreen(parent_wid), XtDisplay(parent_wid),
				&icon_pixmap, &icon_w, &icon_h);  
 
  i=0;
  XtSetArg(args[i],XmNiconName,name);  i++;
  XtSetArg(args[i],XtNiconPixmap,icon_pixmap);  i++;
  
  /* SG 11.02.91 Save the id of the top in the context */ 
  parent_wid = XtCreatePopupShell("plcEditor", 
		     topLevelShellWidgetClass, parent_wid, args, i);

  if (compiled_translations == NULL) 
    XtAppAddActions( XtWidgetToApplicationContext( parent_wid), 
						actions, XtNumber(actions));

  /* the positioning of a top level can only be define after the creation
      of the widget . So i do it know: 
     SG 24.02.91 use the parameters received x and y 
  */

  i=0;
  XtSetArg(args[i],XmNx,x_top);i++;
  XtSetArg(args[i],XmNy,y_top);i++;
  XtSetArg(args[i],XtNallowShellResize,TRUE), i++;

  if ( ! map_window) {
    XtSetArg(args[i],XmNmappedWhenManaged,FALSE); i++;
  }

  XtSetValues( parent_wid, args, i);

  XtSetArg (args[0], XmNuserData, (XtPointer) this);

  /* now that we have a top level we can get the main window */
  sts = MrmFetchWidgetOverride(s_MrmH, (char*) "foe_window", parent_wid ,
		name, args, 1,
		&widgets.foe_window, &dclass);
  if (sts != MrmSUCCESS) printf("can't fetch foedit widget\n");

  /* SG 24.02.91 Set the width and hight desired for the main window to his
	child the adb widget */
  i=0;
  XtSetArg(args[i],XmNwidth,width_adb);i++;
  XtSetArg(args[i],XmNheight,height_adb);i++;
  XtSetValues( widgets.adb  ,args,i);

  /* SG 24.02.91
     Get a litle message box widget that you will make appears when you want by
     calling foe_msgbox
  */

  if (MrmFetchWidget (s_MrmH, 
			(char*) "foe_msgbox", 
			widgets.foe_window,
			&widgets.msgbox,
			&dclass) != MrmSUCCESS)
	printf("can't fetch msgbox \n");

  TitleStr = XmStringCreateLtoR((char*) "PlcEdit Message" , (char*) "ISO8859-1");    
  XtSetArg(args[0],XmNdialogTitle,TitleStr);
  XtSetValues( widgets.msgbox, args, 1);
  XmStringFree(TitleStr);


  /* SG 13.02.91 
     Get a litle caution widget that you will make appears when you want by
     calling foe_popupmsg 
  */

  if (MrmFetchWidget (s_MrmH, 
			(char*) "foe_popupmsg", 
			widgets.foe_window,
			&widgets.caution,
			&dclass) != MrmSUCCESS)
    printf("can't fetch popupmsg\n");

  TitleStr = XmStringCreateLtoR((char*) "PlcEdit Confirm" , (char*) "ISO8859-1");    
  XtSetArg(args[0],XmNdialogTitle,TitleStr);
  XtSetValues( widgets.caution, args, 1);
  XmStringFree(TitleStr);


  /* create the pane widgets */
  /* create the palette module */
  /* SG 07.03.91 put two palletes in the sub pane widget */

  node_palctx = new PalMotif( this, widgets.subpane, "Objects",
		ldhsession, "PlcEditorPalette", 
		&widgets.node_palette, &sts);
  node_palette_managed = 1;

  navctx = new NavMotif( this, widgets.subpane, "Plant",
		ldhsession, "NavigatorW1",
		&widgets.nav_palette, &sts);
  XtUnmanageChild( widgets.nav_palette);

  con_palctx = new PalMotif( this, widgets.subpane, "Connections",
		ldhsession, "PlcEditorConPalette", 
		&widgets.con_palette, &sts);
  XtUnmanageChild( widgets.con_palette);


  /* Turn off traversal for sash widgets */
  XtVaGetValues(widgets.subpane, 
		XmNchildren, &children,
		XmNnumChildren, &num_children,
		NULL);
  for (i = 0; i < num_children; i++) {
    if (XmIsSash(children[i]))
      XtVaSetValues(children[i], XmNtraversalOn, False, NULL);
  }

  /* create the gredit module */
  XtManageChild(widgets.foe_window);


  gre = new WGreMotif( this, widgets.pane, "Name");

  ((WGreMotif *)gre)->new_navigator( widgets.subpane);

  if ( map_window)
    XtPopup(parent_wid, XtGrabNone);
  else
    XtRealizeWidget( parent_wid);

  gre->init();

  /* create the setup ie:
     enable netedevents,
     enable menu entries
     setup backcalls from the gredit module */

  function_setup();

  MrmCloseHierarchy(s_MrmH);

  if (compiled_translations == NULL) 
    compiled_translations = XtParseTranslationTable(translations);
  XtOverrideTranslations( widgets.foe_window, compiled_translations);

  XtUnmanageChild(widgets.textinput);

  if ( !(CoLogin::privilege() & pwr_mPrv_DevPlc ) || 
       (function_access == foe_eFuncAccess_View)) {
    /* Mode Edit and Simulate is not allowed */
    i=0;
    XtSetArg(args[i],XmNsensitive,0); i++;

    XtSetValues( widgets.edit_togg,args,i);
    XtSetValues( widgets.simulate_togg,args,i);
  }

  if (MwmDeleteWind == 0)
    MwmDeleteWind = XInternAtom(XtDisplay(parent_wid), "WM_DELETE_WINDOW", FALSE);

  if (MwmDeleteWind != 0) {
    XtVaSetValues(parent_wid, XmNdeleteResponse, XmDO_NOTHING, NULL);
    XmAddWMProtocolCallback(parent_wid, MwmDeleteWind, 
			    (XtCallbackProc)activate_quit, this);
  }

  CoWowMotif::GetAtoms( parent_wid, 0, &objid_atom, 0);

  /* SG 09.02.91 a top level should always be realized !
   * ML 16.03.94 changed Realize to Popup
   */

  return FOE__SUCCESS;
}
Пример #2
0
int main (int argc, char *argv[])
{
  db_t *database;
  int opt;

  log_debug_flags = DEBUG_TICKER | DEBUG_TAKEOVER | DEBUG_FAME | DEBUG_HERO | DEBUG_ARTEFACT;

  while ((opt = getopt(argc, argv, "C:V")) >= 0)
  {
    switch (opt)
    {
      case 'C':
	config_file = optarg;
	break;
      case 'V':
	puts("$Id: ticker.c 2391 2009-01-12 20:14:20Z root $");
	return 0;
      default:
	return 1;
    }
  }

#ifdef DEBUG_MALLOC
  GC_find_leak = 1;
#endif

  /* init random number generator */
  srand(time(NULL));

  /* init function parser */
  function_setup();

  /* read config file */
  config_read_file(config_file);
  fetch_config_values();

  /* open ticker logfiles */
  if (chdir(ticker_home))
    error("%s: %s", ticker_home, strerror(errno));

  debug_log = log_handler_new(debug_logfile);
  error_log = log_handler_new(error_logfile);
  msg_log   = log_handler_new(msg_logfile);

  log_set_debug_handler(debug_log);
  log_set_warning_handler(error_log);
  log_set_error_handler(error_log);
  message_set_log_handler(msg_log);

  /* connect to the database */
  debug(DEBUG_TICKER, "init");
  write_pidfile(pid_file);

  try {
    database = db_connect(db_host, db_user, db_passwd, db_name);
  } catch (DB_EXCEPTION) {
    error("%s", except_msg);
  } end_try;

  /* read last tick */
  tick_init();

  /* install signal handler */
  signal(SIGTERM, set_finish);
  signal(SIGINT, set_finish);
#ifdef SIGHUP
  signal(SIGHUP, set_reload);
#endif

  /* start the ticker */
  run_ticker(database);

  /* clean up */
  debug(DEBUG_TICKER, "cleanup");

  db_close(database);
  remove(pid_file);
  return 0;
}