当前位置: 首页>>代码示例>>C++>>正文


C++ Host::init方法代码示例

本文整理汇总了C++中Host::init方法的典型用法代码示例。如果您正苦于以下问题:C++ Host::init方法的具体用法?C++ Host::init怎么用?C++ Host::init使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Host的用法示例。


在下文中一共展示了Host::init方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: script_method

//=============================================================================
scx::ScriptRef* HostMapper::script_method(const scx::ScriptAuth& auth,
					  const scx::ScriptRef& ref,
					  const std::string& name,
					  const scx::ScriptRef* args)
{
  if (!auth.admin()) return scx::ScriptError::new_ref("Not permitted");

  if ("add" == name) {
    const scx::ScriptString* a_id =
      scx::get_method_arg<scx::ScriptString>(args,0,"id");
    if (!a_id) {
      return scx::ScriptError::new_ref("add() No host ID specified");
    }
    std::string s_id = a_id->get_string();

    const scx::ScriptString* a_hostname =
      scx::get_method_arg<scx::ScriptString>(args,1,"hostname");
    if (!a_hostname) {
      return scx::ScriptError::new_ref("add() No hostname specified");
    }
    std::string s_hostname = a_hostname->get_string();
    
    const scx::ScriptString* a_path =
      scx::get_method_arg<scx::ScriptString>(args,2,"path");
    if (!a_path) {
      return scx::ScriptError::new_ref("add() No path specified");
    }
    
    HostMap::const_iterator it = m_hosts.find(s_id);
    if (it != m_hosts.end()) {
      return scx::ScriptError::new_ref("add() Host with this ID already exists");
    }
        
    LOG("Adding host '" + s_id + "' hostname '" + s_hostname +
        "' path '" + a_path->get_string() + "'");
    scx::FilePath path = scx::Kernel::get()->get_conf_path() + a_path->get_string();
    Host* host = new Host(m_module, *this, s_id, s_hostname, path.path(), "art");
    host->init();
    m_hosts[s_id] = new Host::Ref(host);
    m_aliases[s_hostname] = s_id;
    return new Host::Ref(host);
  }

  if ("remove" == name) {
    const scx::ScriptString* a_host =
      scx::get_method_arg<scx::ScriptString>(args,0,"id");
    if (!a_host) {
      return scx::ScriptError::new_ref("remove() No host id specified");
    }
    std::string s_hostname = a_host->get_string();

    HostMap::iterator it = m_hosts.find(s_hostname);
    if (it == m_hosts.end()) {
      return scx::ScriptError::new_ref("remove() Host not found");
    }
    
    LOG("Removing host '" + s_hostname + "'");
    delete it->second;
    m_hosts.erase(it);
    return 0;
  }
  
  if ("alias" == name) {
    const scx::ScriptString* a_pattern =
      scx::get_method_arg<scx::ScriptString>(args,0,"pattern");
    if (!a_pattern) {
      return scx::ScriptError::new_ref("map() No pattern specified");
    }
    std::string s_pattern = a_pattern->get_string();
    
    const scx::ScriptString* a_target =
      scx::get_method_arg<scx::ScriptString>(args,1,"target");
    if (!a_target) {
      return scx::ScriptError::new_ref("map() No target specified");
    }
    std::string s_target = a_target->get_string();

    LOG("Mapping host pattern '" + s_pattern + "' to ID '" + s_target + "'"); 
    m_aliases[s_pattern] = s_target;
    return 0;
  }

  if ("redirect" == name) {
    const scx::ScriptString* a_pattern =
      scx::get_method_arg<scx::ScriptString>(args,0,"pattern");
    if (!a_pattern) {
      return scx::ScriptError::new_ref("redirect() No pattern specified");
    }
    std::string s_pattern = a_pattern->get_string();
    
    const scx::ScriptString* a_target =
      scx::get_method_arg<scx::ScriptString>(args,1,"target");
    if (!a_target) {
      return scx::ScriptError::new_ref("redirect() No target specified");
    }
    std::string s_target = a_target->get_string();

    LOG("Redirecting host pattern '" + s_pattern +
        "' to ID '" + s_target + "'"); 
//.........这里部分代码省略.........
开发者ID:sconemad,项目名称:sconeserver,代码行数:101,代码来源:HostMapper.cpp


注:本文中的Host::init方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。