Beispiel #1
0
int
TAO_IFR_Server::open_config (void)
{
  if (OPTIONS::instance ()->using_registry ())
    {
#if defined (ACE_WIN32) && !defined (ACE_LACKS_WIN32_REGISTRY)
      HKEY root =
        ACE_Configuration_Win32Registry::resolve_key (
            HKEY_LOCAL_MACHINE,
            "Software\\TAO\\IFR"
          );

      ACE_NEW_THROW_EX (this->config_,
                        ACE_Configuration_Win32Registry (root),
                        CORBA::NO_MEMORY ());
#endif /* ACE_WIN32 && !ACE_LACKS_WIN32_REGISTRY */

      return 0;
    }
  else
    {
      ACE_Configuration_Heap *heap = 0;
      ACE_NEW_THROW_EX (heap,
                        ACE_Configuration_Heap,
                        CORBA::NO_MEMORY ());

      if (OPTIONS::instance ()->persistent ())
        {
          const char *filename = OPTIONS::instance ()->persistent_file ();

          if (heap->open (filename))
            {
              delete heap;
              heap = 0;

              ORBSVCS_ERROR_RETURN ((
                  LM_ERROR,
                  ACE_TEXT ("Error:: Opening persistent heap file '%s'\n"),
                  filename
                ),
                -1
              );
            }
        }
      else
        {
          heap->open ();
        }

      this->config_ = heap;

      return 0;
    }
}
Beispiel #2
0
void MainFrame::OnFileNewTransientHeap(wxCommandEvent& event)
{
  delete m_pConfig;
  ACE_Configuration_Heap* pHeapConfig = new ACE_Configuration_Heap;
  pHeapConfig->open();
  SetNewConfig(pHeapConfig);
}
int
ACE::HTBP::Environment::open_persistent_config (const ACE_TCHAR *persistent_file)
{
  ACE_Configuration_Heap *heap;
  ACE_NEW_RETURN (heap,
                  ACE_Configuration_Heap,
                  -1);
  // do this before trying to open so it isn't leaked if the open fails.
  this->config_ = heap;
  if (persistent_file == 0)
    heap->open();
  else
    if (heap->open (persistent_file) != 0)
      ACE_ERROR_RETURN (( LM_ERROR,
                          ACE_TEXT ("(%P|%t) ACE::HTBP::Environment::")
                          ACE_TEXT ("open_config: %p\n"),
                          persistent_file),
                        -1 );
  return 0;
}
Beispiel #4
0
void MainFrame::OnFileOpenPersistentHeap(wxCommandEvent& event)
{
  wxFileDialog Dlg(this, "Choose a file", "", "", "*.*", wxOPEN);
  if(Dlg.ShowModal() != wxID_OK)
  {
    return;
  }
  delete m_pConfig;
  ACE_Configuration_Heap* pHeapConfig = new ACE_Configuration_Heap;
  pHeapConfig->open(Dlg.GetFilename());
  SetNewConfig(pHeapConfig);
}
Beispiel #5
0
int KSGateway::start_scheduler_algorithm()
{
	std::string config_path = KSGOSUtil::JoinPath(_configuration._basedir,KSG_CONFIG_FILENAME);
	ACE_Configuration_Heap config;
	if(config.open() == -1)
	{
		ACE_ERROR_RETURN((LM_ERROR,ACE_TEXT("读取前置机配置失败")),-1);
	}
	ACE_Ini_ImpExp config_importer(config);

	if(config_importer.import_config(config_path.c_str()) == -1)
	{
		ACE_ERROR_RETURN((LM_ERROR,ACE_TEXT("读取前置机配置失败")),-1);
	}

	ACE_Configuration_Section_Key section;
	if(config.open_section(config.root_section(),ACE_TEXT(KSG_COMMON_SECT)
		,0,section) == -1)
	{
		ACE_ERROR_RETURN((LM_ERROR,ACE_TEXT("读取前置机配置失败")),-1);
	}
	
	ACE_TString v;

	if(config.open_section(config.root_section(),ACE_TEXT(KSG_SCHEDULER_SECT)
		,0,section) == -1)
		ACE_ERROR_RETURN((LM_ERROR,ACE_TEXT("读取前置机配置失败")),-1);

	if(config.get_string_value(section,KSG_SCHD_ALG,v) == -1)
	{
		ACE_ERROR_RETURN((LM_ERROR,ACE_TEXT("读取前置机配置失败")),-1);
	}
	std::string algs = v.c_str();
	std::list<std::string> idstr;
	std::back_insert_iterator<std::list<std::string> > iter(idstr);
	// 从配置中读取需要启动的任务号
	xutil::StringUtil::SpliteString(algs,",",iter);
	int count = 0;
	for(std::list<std::string>::iterator i = idstr.begin();i != idstr.end();++i,++count)
	{
		if(init_scheduler_algorithm(*i))
			return -1;
	}
	ACE_DEBUG((LM_TRACE,"启动[%d]个调度算法",count));
	return 0;
}
Beispiel #6
0
int
Service_Monitor::import_svc_ini(const char* ini_file)
{
	int rc = -1;

	// load ini file
	ACE_Configuration_Heap config;
	config.open();

	ACE_Ini_ImpExp iniIO(config);
	rc = iniIO.import_config(ini_file);
	if ( rc != 0 )
		return rc;

	// clear monitors
	monitors_.clear();
	ini_file_ = "";

	// read ini
	ACE_TString name;
	for(int i = 0;
		config.enumerate_sections(config.root_section(), i, name) == 0;
		++i)
	{
		// not [service] section
		if ( !ACE_OS::ace_isalnum(*(name.c_str())) )
			continue;

		ACE_Configuration_Section_Key sec;
		config.open_section(config.root_section(), name.c_str(), 0, sec);
		
		// read svm
		ACE_TString str_svm;
		config.get_string_value(sec, ACE_TEXT("svm"), str_svm);
		// no svm value
		if ( str_svm.is_empty() )
			continue;

		int monitor_sec = ACE_OS::atoi(str_svm.c_str());
		if ( monitor_sec >= 0 )
			monitors_.insert(std::make_pair(name.c_str(), monitor_sec));
	}

	return rc;
}
Beispiel #7
0
int KSGateway::get_scheduler_alg_thr_count(const std::string &alg_name)
{
	int count = 0;
	std::string config_path = KSGOSUtil::JoinPath(_configuration._basedir,KSG_CONFIG_FILENAME);
	ACE_Configuration_Heap config;
	if(config.open() == -1)
	{
		ACE_ERROR_RETURN((LM_ERROR,ACE_TEXT("读取前置机配置失败")),-1);
	}
	ACE_Ini_ImpExp config_importer(config);

	if(config_importer.import_config(config_path.c_str()) == -1)
	{
		ACE_ERROR_RETURN((LM_ERROR,ACE_TEXT("读取前置机配置失败")),-1);
	}

	ACE_Configuration_Section_Key section;
	if(config.open_section(config.root_section(),ACE_TEXT(KSG_COMMON_SECT)
		,0,section) == -1)
	{
		ACE_ERROR_RETURN((LM_ERROR,ACE_TEXT("读取前置机配置失败")),-1);
	}

	ACE_TString v;

	if(config.open_section(config.root_section(),ACE_TEXT(KSG_SCHEDULER_SECT)
		,0,section) == -1)
		ACE_ERROR_RETURN((LM_ERROR,ACE_TEXT("读取前置机配置失败")),-1);
	

	std::string key_name = alg_name;
	key_name += "_thr_count";
	if(config.get_string_value(section,key_name.c_str(),v) == -1)
	{
		count = 5;
	}
	else
	{
		count = ACE_OS::atoi(v.c_str());
		count = (count <= 0) ? 5 : count;
	}
	
	return count;
}
Beispiel #8
0
int
Service_Monitor::load(const char* ini_file)
{
	int rc = -1;

	// load ini file
	ACE_Configuration_Heap config;
	config.open();

	ACE_Ini_ImpExp iniIO(config);
	rc = iniIO.import_config(ini_file_.c_str());
	if ( rc != 0 )
		return rc;

	// clear monitors
	monitors_.clear();
	ini_file_ = ini_file;

	// read monitors
	ACE_Configuration_Section_Key sec;
	config.open_section(config.root_section(), ACE_TEXT("*"), 0, sec);

	ACE_TString name;
	ACE_Configuration::VALUETYPE val_type;
	for(int i = 0;
		config.enumerate_values(sec, i, name, val_type) == 0;
		++i)
	{
		ACE_TString value;
		config.get_string_value(sec, name.c_str(), value);
		int monitor_sec = ACE_OS::atoi(value.c_str());

		if ( monitor_sec >= 0 )
			monitors_.insert(std::make_pair(name.c_str(), monitor_sec));
	}

	return rc;
}
//---------------------------------------------------------------------------------------------
int HA_ccifs::init ( int argc , ACE_TCHAR *argv[] )
{

               ACE_Trace _( ACE_TEXT( "%D HA_ccifs::init" ) , __LINE__ );



              //command line
              //-------------------------------------------------------------------------------
              static const ACE_TCHAR options[] = ACE_TEXT (":f:");
              ACE_Get_Opt cmd_opts (argc, argv, options, 0);
              if (cmd_opts.long_option
                  (ACE_TEXT ( "config" ), 'f', ACE_Get_Opt::ARG_REQUIRED) == -1)
              { return -1; }

              int option;
              ACE_TCHAR config_file[MAXPATHLEN];
              ACE_OS::strcpy ( config_file, ACE_TEXT ( conf_path.c_str() ) );
              while ( ( option = cmd_opts ()) != EOF)
              switch ( option )
              {
                  case 'f' :

                    ACE_OS::strncpy (config_file , cmd_opts.opt_arg () , MAXPATHLEN );
                    break;

                  case ':':

                    ACE_ERROR_RETURN ( ( LM_ERROR , ACE_TEXT ( "-%c requires an argument\n" )  ,
                                   cmd_opts.opt_opt ()) , -1 );
              default:

                ACE_ERROR_RETURN ( ( LM_ERROR , ACE_TEXT ( "parse error.\n" ) ) ,
                                  - 1);
              }

              //configuration file
              //-------------------------------------------------------------------------------
              ACE_Configuration_Heap config;
              config.open ();
              ACE_Registry_ImpExp config_importer (config);
              if ( config_importer.import_config (config_file) == -1 )
              { ACE_ERROR_RETURN ( ( LM_ERROR , ACE_TEXT ("%p\n") , config_file ) , -1 ); }


              ACE_Configuration_Section_Key dispatcher_section;
              if (config.open_section (config.root_section (),
                                       ACE_TEXT ("HA_ccifs"),
                                       0,
                                       dispatcher_section) == -1)
                ACE_ERROR_RETURN ((LM_ERROR,
                                   ACE_TEXT ("%p\n"),
                                   ACE_TEXT ( "can't open HA_ccifs section"  ) ) ,
                                  -1 );
              //fifo
              u_int dispatcher_port;
              if (config.get_integer_value ( dispatcher_section,
                                             ACE_TEXT ( "fifo" ) ,
                                             dispatcher_port ) == -1 )
              ACE_ERROR_RETURN ((LM_ERROR,
                                   ACE_TEXT ("HA_ccifs fifo")
                                   ACE_TEXT (" does not exist\n") ) ,
                                  -1 );
              //ccifs
              ACE_TString ccifs;
              if (config.get_string_value (  dispatcher_section,
                                             ACE_TEXT ( "ccifs_tmpfs_mount" ) ,
                                             ccifs ) == -1 )
              ACE_ERROR_RETURN ((LM_ERROR,
                                   ACE_TEXT ("HA_ccifs ccifs_mount")
                                   ACE_TEXT (" does not exist\n") ) ,
                                  -1 );

              if( ACE_Thread_Manager::instance()->spawn( ACE_THR_FUNC (ccifs_func) ,
                                                     (void*) this ,
                                                     THR_NEW_LWP  ,
                                                     &m_thread_id ) )
              {
                  ACE_DEBUG
                  ((LM_DEBUG, ACE_TEXT ("(%t) ..spawned ccifs notify thread..\n")));

              }
              else
              {
                   ACE_DEBUG
                  ((LM_DEBUG, ACE_TEXT ("(%t) ..spawning ccifs notify failed..\n")));

              }



              return 0;
}
Beispiel #10
0
// frame constructor
MainFrame::MainFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
: wxFrame((wxFrame *)0, -1, title, pos, size),
  m_pConfig(0)
{
  m_pInstance = this;

  // Create a persistent heap based configuration
  
  ACE_Configuration_Heap* pHeapConfig = new ACE_Configuration_Heap;
  pHeapConfig->open();
  m_pConfig = pHeapConfig;

  // set the frame icon
  SetIcon(wxICON(mondrian));

  // Create Splitter
  m_pSplitter = new wxSplitterWindow(this, -1);
  wxSize sz( m_pSplitter->GetSize() );
  sz.SetWidth(sz.GetWidth() / 2);
  
  // List Control
  m_pListCtrl = new ValueListCtrl(m_pSplitter, -1, wxDefaultPosition, sz);

  // Tree Control
  m_pTreeCtrl = new ConfigTreeCtrl(m_pSplitter, FRAME_TREE, wxDefaultPosition, sz, 
                  wxTR_EDIT_LABELS | wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT);
  m_pTreeCtrl->SetpListCtrl(m_pListCtrl);


  // Setup splitter
  m_pSplitter->SplitVertically(m_pTreeCtrl, m_pListCtrl);
  m_pSplitter->SetMinimumPaneSize(100);
  m_pSplitter->SetSashPosition(size.GetWidth() / 3);
  
  // create a menu bar
  wxMenu *menuFile = new wxMenu("", wxMENU_TEAROFF);
  menuFile->Append(FILE_NEW_PERSISTENT_HEAP, "New Persistent Heap", "Create a new persistent heap");
  menuFile->Append(FILE_NEW_TRANSIENT_HEAP, "New Transient Heap", "Create a new transient heap");
  menuFile->Append(FILE_OPEN_PERSISTENT_HEAP, "Open Persistent Heap", "Open Persistent Heap");
#if defined (ACE_WIN32)
  menuFile->Append(FILE_OPEN_REGISTRY, "Open Win32 Registry", "Open Win32 Registry");
#endif
  menuFile->AppendSeparator();
  menuFile->Append(FILE_IMPORT, "Import from INI file", "Import from INI file");
  menuFile->Append(FILE_EXPORT, "Export to INI file", "Export to INI file");
  menuFile->AppendSeparator();
  menuFile->Append(ABOUT, "&About...\tCtrl-A", "Show about dialog");
  menuFile->AppendSeparator();
  menuFile->Append(QUIT, "E&xit\tAlt-X", "Quit this program");

  // now append the freshly created menu to the menu bar...
  wxMenuBar *menuBar = new wxMenuBar();
  menuBar->Append(menuFile, "&File");

  // ... and attach this menu bar to the frame
  SetMenuBar(menuBar);

#if wxUSE_STATUSBAR
  CreateStatusBar(2);
  SetStatusText("Ready");
#endif // wxUSE_STATUSBAR
}
Beispiel #11
0
// Listing 1 code/ch19
int
HA_Status::init (int argc, ACE_TCHAR *argv[])
{
  static const ACE_TCHAR options[] = ACE_TEXT (":f:");
  ACE_Get_Opt cmd_opts (argc, argv, options, 0);
  if (cmd_opts.long_option
      (ACE_TEXT ("config"), 'f', ACE_Get_Opt::ARG_REQUIRED) == -1)
    return -1;
  int option;
  ACE_TCHAR config_file[MAXPATHLEN];
  ACE_OS::strcpy (config_file, ACE_TEXT ("HAStatus.conf"));
  while ((option = cmd_opts ()) != EOF)
    switch (option)
      {
      case 'f':
        ACE_OS::strncpy (config_file,
                         cmd_opts.opt_arg (),
                         MAXPATHLEN);
        break;
      case ':':
        ACE_ERROR_RETURN ((LM_ERROR,
                           ACE_TEXT ("-%c requires an argument\n"),
                           cmd_opts.opt_opt ()),
                          -1);
      default:
        ACE_ERROR_RETURN ((LM_ERROR,
                           ACE_TEXT ("Parse error.\n")),
                          -1);
      }

  ACE_Configuration_Heap config;
  config.open ();
  ACE_Registry_ImpExp config_importer (config);
  if (config_importer.import_config (config_file) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("%p\n"),
                       config_file),
                      -1);

  ACE_Configuration_Section_Key status_section;
  if (config.open_section (config.root_section (),
                           ACE_TEXT ("HAStatus"),
                           0,
                           status_section) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("%p\n"),
                       ACE_TEXT ("Can't open HAStatus section")),
                      -1);

  u_int status_port;
  if (config.get_integer_value (status_section,
                                ACE_TEXT ("ListenPort"),
                                status_port) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("HAStatus ListenPort ")
                       ACE_TEXT ("does not exist\n")),
                      -1);
  this->listen_addr_.set (static_cast<u_short> (status_port));

  if (this->acceptor_.open (this->listen_addr_) != 0)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("HAStatus %p\n"),
                       ACE_TEXT ("accept")),
                      -1);

  return 0;
}
Beispiel #12
0
int KSGConfig::loadConfig(const std::string& file_name)
{
	ACE_Configuration_Heap config;
	if(config.open() == -1)
	{
		ACE_ERROR_RETURN((LM_ERROR,ACE_TEXT("读取前置机配置失败")),-1);
	}
	ACE_Ini_ImpExp config_importer(config);

	if(config_importer.import_config(file_name.c_str()) == -1)
	{
		ACE_ERROR_RETURN((LM_ERROR,ACE_TEXT("读取前置机配置失败")),-1);
	}

	ACE_Configuration_Section_Key section;
	if(config.open_section(config.root_section(),ACE_TEXT(KSG_COMMON_SECT)
		,0,section) == -1)
	{
		ACE_ERROR_RETURN((LM_ERROR,ACE_TEXT("读取前置机配置失败")),-1);
	}
	
	ACE_TString v;

	if(config.get_string_value(section,ACE_TEXT(KSG_MAJOR_VER),v) == -1)
	{
		ACE_ERROR_RETURN((LM_ERROR,ACE_TEXT("读取前置机配置失败")),-1);
	}
	_majorVer = ACE_OS::atoi(v.c_str());
	if(config.get_string_value(section,KSG_MINOR_VER,v) == -1)
	{
		ACE_ERROR_RETURN((LM_ERROR,ACE_TEXT("读取前置机配置失败")),-1);
	}
	_minorVer = ACE_OS::atoi(v.c_str());

	if(config.open_section(config.root_section(),ACE_TEXT(KSG_SERVER_SECT)
		,0,section) == -1 )
		ACE_ERROR_RETURN((LM_ERROR,ACE_TEXT("读取前置机配置失败")),-1);

	
	if(config.get_string_value(section,KSG_SVR_IP,v) == -1)
	{
		ACE_ERROR_RETURN((LM_ERROR,ACE_TEXT("读取前置机配置失败")),-1);
	}
	_drtpSvrIP = v.c_str();
	if(config.get_string_value(section,KSG_SVR_PORT,v) == -1)
		ACE_ERROR_RETURN((LM_ERROR,ACE_TEXT("读取前置机配置失败")),-1);
	_drtpSvrPort = ACE_OS::atoi(v.c_str());
	if(config.get_string_value(section,KSG_SVR_BRANCE_NO,v) == -1)
		ACE_ERROR_RETURN((LM_ERROR,ACE_TEXT("读取前置机配置失败")),-1);
	_drtpNo = ACE_OS::atoi(v.c_str());
	if(config.get_string_value(section,KSG_SVR_MAINFUNC,v) == -1)
		ACE_ERROR_RETURN((LM_ERROR,ACE_TEXT("读取前置机配置失败")),-1);
	_drtpMainFunc = ACE_OS::atoi(v.c_str());
	if(config.get_string_value(section,KSG_SVR_POOL_CONN,v) == -1)
		_drtpPoolMaxCnt = 5;
	else
		_drtpPoolMaxCnt = ACE_OS::atoi(v.c_str());
	if(_drtpPoolMaxCnt < 0)
		_drtpPoolMaxCnt = 5;
	if(_drtpPoolMaxCnt > 30)
		_drtpPoolMaxCnt = 30;

	if(config.get_string_value(section,KSG_SVR_BCC,v) == -1)
		_start_bcc = 0;
	else
		_start_bcc = ACE_OS::atoi(v.c_str());
	
	/// 是否加载卡状态
	if(config.get_string_value(section,KSG_SVR_LOAD_CARD_STATE,v) == -1)
		_loadCardState = 0;
	else
		_loadCardState = ACE_OS::atoi(v.c_str());

	if(config.open_section(config.root_section(),ACE_TEXT(KSG_GATEWAY_SECT)
		,0,section) == -1)
		ACE_ERROR_RETURN((LM_ERROR,ACE_TEXT("读取前置机配置失败")),-1);

	if(config.get_string_value(section,KSG_GW_IP,v) == -1)
		ACE_ERROR_RETURN((LM_ERROR,ACE_TEXT("读取前置机配置失败")),-1);
	_localIP = v.c_str();

	if(config.open_section(config.root_section(),ACE_TEXT(KSG_SCHEDULER_SECT)
		,0,section) == -1)
		ACE_ERROR_RETURN((LM_ERROR,ACE_TEXT("读取前置机配置失败")),-1);

	_runTaskIds = "";
	if(config.get_string_value(section,KSG_SCHD_IDS,v) != -1)
	{
		_runTaskIds = v.c_str();
	}

	_listenerIds = "";
	if(config.get_string_value(section,KSG_LISTENER_IDS,v) != -1)
	{
		_listenerIds = v.c_str();
	}

	if(config.get_string_value(section,"conn_interval",v)==-1)
		_conn_interval = 100;
	else
		_conn_interval = ACE_OS::atoi(v.c_str());

	if(config.get_string_value(section,"reactor_thr_count",v)==-1)
		_reactor_thr_count = 10;
	else
		_reactor_thr_count = ACE_OS::atoi(v.c_str());
	
	if(config.open_section(config.root_section(),ACE_TEXT(KSG_LOG_SECT)
		,0,section) == -1)
		ACE_ERROR_RETURN((LM_ERROR,ACE_TEXT("读取日志配置失败")),-1);
	if(config.get_string_value(section,KSG_LOG_LEVEL,v)!=-1)
	{
		_logLevel = v.c_str();
	}
	if(config.get_string_value(section,KSG_LOG_APPENDER,v)!=-1)
	{
		_logOutput = v.c_str();
	}
	if(config.get_string_value(section,KSG_LOG_FILE,v)!=-1)
	{
		_logFilePath = v.c_str();
	}
	
	if(config.get_string_value(section,KSG_LOG_FILEMAX,v) != -1)
	{
		_log_max_file_size = ACE_OS::atoi(v.c_str());
		if(_log_max_file_size == 0)
			_log_max_file_size = 1024;
		_log_max_file_size *= 1024;
		if(_log_max_file_size <= 0)
			_log_max_file_size = 1024 * 1024;
	}
	if(config.get_string_value(section,KSG_LOG_MAX_COUNT,v) !=-1)
	{
		_log_max_backup = ACE_OS::atoi(v.c_str());
		if(_log_max_backup == 0)
			_log_max_backup = 1;
	}
	return 0;
}