Beispiel #1
0
truefalse CRunner::do_init()
{
  CCfg * l_obj = CCfgX::instance();
  g_term_sns = &m_term_SNs;

  if (!m_pg.login_to_db())
  {
    C_FATAL("fail to connect to database. quitting...\n");
    return C_BAD;
  }
  if (!m_pg.load_term_SNs(&m_term_SNs))
  {
    C_FATAL("fail to get term sn from db. quitting...\n");
    return C_BAD;
  }

  if (l_obj->handleout())
  {
    add_component(m_ping_container = new CPingContainer(this));
    add_component(m_d2m_container = new CD2MContainer(this));
  }
  if (l_obj->pre())
  {
    add_component(m_position_container = new CPositionContainer(this));
    add_component(m_balance_container = new CBalanceContainer(this));
    add_component(m_bs_req_container = new CBsReqContainer(this));
  }
  return C_OK;
}
Beispiel #2
0
std::unique_ptr<nano::seq_con_info_component> nano::collect_seq_con_info (nano::node_observers & node_observers, const std::string & name)
{
	auto composite = std::make_unique<nano::seq_con_info_composite> (name);
	composite->add_component (collect_seq_con_info (node_observers.blocks, "blocks"));
	composite->add_component (collect_seq_con_info (node_observers.wallet, "wallet"));
	composite->add_component (collect_seq_con_info (node_observers.vote, "vote"));
	composite->add_component (collect_seq_con_info (node_observers.account_balance, "account_balance"));
	composite->add_component (collect_seq_con_info (node_observers.endpoint, "endpoint"));
	composite->add_component (collect_seq_con_info (node_observers.disconnect, "disconnect"));
	return composite;
}
Beispiel #3
0
std::unique_ptr<seq_con_info_component> collect_seq_con_info (work_pool & work_pool, const std::string & name)
{
	auto composite = std::make_unique<seq_con_info_composite> (name);

	size_t count = 0;
	{
		std::lock_guard<std::mutex> (work_pool.mutex);
		count = work_pool.pending.size ();
	}
	auto sizeof_element = sizeof (decltype (work_pool.pending)::value_type);
	composite->add_component (std::make_unique<seq_con_info_leaf> (seq_con_info{ "pending", count, sizeof_element }));
	composite->add_component (collect_seq_con_info (work_pool.work_observers, "work_observers"));
	return composite;
}
Beispiel #4
0
ElementLoop& BoundaryTerm::access_element_loop( const std::string& type_name )
{
  // ensure that the fields are present

  link_fields();

  // get the element loop or create it if does not exist

  ElementLoop::Ptr loop;
  Common::Component::Ptr cloop = get_child_ptr( "LOOP" );
  if( is_null( cloop ) )
  {
    const std::string update_vars_type =
        physical_model().get_child( RDM::Tags::update_vars() )
                        .as_type<Physics::Variables>()
                        .type();

    loop = build_component_abstract_type_reduced< FaceLoop >( "FaceLoopT<" + type_name + "," + update_vars_type + ">" , "LOOP");
    add_component(loop);
  }
  else
    loop = cloop->as_ptr_checked<ElementLoop>();


  return *loop;
}
Beispiel #5
0
CSolver& CModel::create_solver( const std::string& builder)
{
  std::string solver_name = CBuilder::extract_reduced_name(builder);

  CSolver::Ptr solver = boost::algorithm::contains( builder, "." ) ?
              build_component_abstract_type< Solver::CSolver >( builder, solver_name ) :
              build_component_abstract_type_reduced< Solver::CSolver >( builder, solver_name );

  add_component(solver);

  return *solver;
}
Handle< common::Action > BoundaryConditions::add_constant_component_bc(const std::string& region_name, const std::string& variable_name, const Uint component_idx, const Real default_value)
{
  MeshTerm<0, VectorField> var(variable_name, m_implementation->m_solution_tag);
  ConfigurableConstant<Real> value("value", "Value for constant boundary condition", default_value);
  
  boost::shared_ptr< common::Action > result = create_proto_action("BC"+region_name+variable_name,
                                                nodes_expression(m_implementation->dirichlet(var[component_idx]) = value));
  
  add_component(result);
  m_implementation->configure_bc(*result, region_name);

  return Handle<common::Action>(result);
}
Beispiel #7
0
void UNIFAQ::UNIFAQMixture::set_components(const std::string &identifier_type, std::vector<std::string> identifiers) {
    components.clear();
    if (identifier_type == "name") {
        // Iterate over the provided names
        for (std::vector<std::string>::const_iterator it = identifiers.begin(); it != identifiers.end(); ++it) {
            // Get and add the component
            UNIFAQLibrary::Component c = library.get_component("name", *it);
            add_component(c);
        }
    }
    else {
        throw CoolProp::ValueError("Cannot understand identifier_type");
    }
}
Beispiel #8
0
CSolver& CModel::create_solver( const std::string& builder)
{
  std::string solver_name = CBuilder::extract_reduced_name(builder);

  CSolver::Ptr solver = boost::algorithm::contains( builder, "." ) ?
              build_component_abstract_type< Solver::CSolver >( builder, solver_name ) :
              build_component_abstract_type_reduced< Solver::CSolver >( builder, solver_name );

  add_component(solver);

  if(!m_implementation->m_physics.expired())
    solver->configure_option_recursively(Tags::physical_model(), m_implementation->m_physics.lock()->uri());

  return *solver;
}
Handle<common::Action> BoundaryConditions::add_constant_bc(const std::string& region_name, const std::string& variable_name)
{
  const VariablesDescriptor& descriptor = find_component_with_tag<VariablesDescriptor>(m_implementation->physical_model().variable_manager(), m_implementation->m_solution_tag);

  boost::shared_ptr< common::Action > result = descriptor.dimensionality(variable_name) == VariablesDescriptor::Dimensionalities::SCALAR ?
    m_implementation->create_constant_scalar_bc(region_name, variable_name) :
    m_implementation->create_constant_vector_bc(region_name, variable_name);


  add_component(result); // Append action

  m_implementation->configure_bc(*result, region_name);

  return Handle<Action>(result);
}
Beispiel #10
0
CSolver& CModel::create_solver( const std::string& builder)
{
  std::string solver_name = Builder::extract_reduced_name(builder);

  boost::shared_ptr< CSolver > solver = boost::algorithm::contains( builder, "." ) ?
              build_component_abstract_type< solver::CSolver >( builder, solver_name ) :
              build_component_abstract_type_reduced< solver::CSolver >( builder, solver_name );

  add_component(solver);

  if(is_not_null(m_implementation->m_physics))
    solver->configure_option_recursively(Tags::physical_model(), m_implementation->m_physics);

  return *solver;
}
Beispiel #11
0
void LSSAction::on_regions_set()
{
  if(m_implementation->m_updating) // avoid recursion
    return;

  m_implementation->m_lss = options().value< Handle<LSS::System> >("lss");
  if(is_null(m_implementation->m_lss))
    return;

  if(is_null(m_dictionary))
    return;

  m_implementation->m_updating = true;

  // Create the LSS if the mesh is set
  if(!m_loop_regions.empty() && !m_implementation->m_lss->is_created())
  {
    VariablesDescriptor& descriptor = find_component_with_tag<VariablesDescriptor>(physical_model().variable_manager(), solution_tag());

    Handle< List<Uint> > gids = m_implementation->m_lss->create_component< List<Uint> >("GIDs");
    Handle< List<Uint> > ranks = m_implementation->m_lss->create_component< List<Uint> >("Ranks");
    Handle< List<Uint> > used_node_map = m_implementation->m_lss->create_component< List<Uint> >("used_node_map");

    std::vector<Uint> node_connectivity, starting_indices;
    boost::shared_ptr< List<Uint> > used_nodes = build_sparsity(m_loop_regions, *m_dictionary, node_connectivity, starting_indices, *gids, *ranks, *used_node_map);
    add_component(used_nodes);

    // This comm pattern is valid only over the used nodes for the supplied regions
    PE::CommPattern& comm_pattern = *create_component<PE::CommPattern>("CommPattern");
    comm_pattern.insert("gid",gids->array(),false);
    comm_pattern.setup(Handle<PE::CommWrapper>(comm_pattern.get_child("gid")),ranks->array());

    CFdebug << "Creating LSS for " << starting_indices.size()-1 << " blocks with descriptor " << solution_tag() << ": " << descriptor.description() << CFendl;
    m_implementation->m_lss->create(comm_pattern, descriptor.size(), node_connectivity, starting_indices);
    CFdebug << "Finished creating LSS" << CFendl;
    configure_option_recursively(solver::Tags::regions(), options().option(solver::Tags::regions()).value());
    configure_option_recursively("lss", m_implementation->m_lss);
  }

  // Update the regions of any owned initial conditions
  BOOST_FOREACH(const Handle<Component>& ic, m_created_initial_conditions)
  {
    ic->options().set(solver::Tags::regions(), options().option(solver::Tags::regions()).value());
  }
Beispiel #12
0
void UNIFAC::UNIFACMixture::set_components(const std::string &identifier_type, std::vector<std::string> identifiers) {
    components.clear();
    N = identifiers.size();
    if (identifier_type == "name") {
        // Iterate over the provided names
        for (std::vector<std::string>::const_iterator it = identifiers.begin(); it != identifiers.end(); ++it) {
            // Get and add the component
            UNIFACLibrary::Component c = library.get_component("name", *it);
            add_component(c);
        }
    }
    else {
        throw CoolProp::ValueError("Cannot understand identifier_type");
    }
    /// Calculate the parameters X and theta for the pure components, which does not depend on temperature nor molar fraction
    pure_data.clear();
    for (std::size_t i = 0; i < N; ++i) {
        const UNIFACLibrary::Component &c = components[i];
        ComponentData cd;
        double summerxq = 0;
        cd.group_count = 0;
        for (std::size_t j = 0; j < c.groups.size(); ++j) {
            const UNIFACLibrary::ComponentGroup &cg = c.groups[j];
            double x = static_cast<double>(cg.count);
            double theta = static_cast<double>(cg.count*cg.group.Q_k);
            cd.X.insert(std::pair<int, double>(cg.group.sgi, x));
            cd.theta.insert(std::pair<int, double>(cg.group.sgi, theta));
            cd.group_count += cg.count;
            summerxq += x*cg.group.Q_k;
        }
        /// Now come back through and divide by the total # groups for this fluid
        for (std::map<std::size_t, double>::iterator it = cd.X.begin(); it != cd.X.end(); ++it) {
            it->second /= cd.group_count;
            //printf("X^(%d)_{%d}: %g\n", static_cast<int>(i + 1), static_cast<int>(it->first), it->second);
        }
        /// Now come back through and divide by the sum(X*Q) for this fluid
        for (std::map<std::size_t, double>::iterator it = cd.theta.begin(); it != cd.theta.end(); ++it) {
            it->second /= summerxq;
            //printf("theta^(%d)_{%d}: %g\n", static_cast<int>(i+1), static_cast<int>(it->first), it->second);
        }
        pure_data.push_back(cd);
    }
}
Beispiel #13
0
static void component_row_activate_cb (GtkTreeView *view, GtkTreePath *path,
  GtkTreeViewColumn *column, gpointer null) 
{
  GtkTreeSelection *sel;
  GtkTreeIter iter;
  struct component *c;
  GtkTreeModel *model;

  sel = gtk_tree_view_get_selection (view);

  if (gtk_tree_selection_get_selected (sel, &model, &iter)) {
    gtk_tree_model_get (model, &iter, 1, &c, -1);
    add_component (c);
  }

  gtk_widget_destroy (component_dialog);
  component_dialog = NULL;
  choose_button = NULL; 
}
/** @brief The library entry point. It must have the same name for each
  * library fo the components loaded by the ST static component loader.
  *
  * This function fills the version, the component name and if existing also the roles
  * and the specific names for each role. This base function is only an explanation.
  * For each library it must be implemented, and it must fill data of any component
  * in the library
  *
  * @param stComponents pointer to an array of components descriptors.If NULL, the
  * function will return only the number of components contained in the library
  *
  * @return number of components contained in the library
  */
int omx_component_library_Setup(stLoaderComponentType **stLoader)
{
  int i;

  DEBUG(DEB_LEV_FUNCTION_NAME, "In %s \n",__func__);

  if (stLoader == NULL) {
    DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s \n",__func__);
    return NUM_COMPONENTS; // Return Number of Components
  }

  for(i = 0; i < sizeof(stComponents) / sizeof(stComponent); i++)
    add_component(stLoader[i],
		  stComponents[i].role,
		  stComponents[i].name,
		  stComponents[i].constructor);

  DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s \n",__func__);

  return NUM_COMPONENTS;
}
RDM::BoundaryTerm& BoundaryConditions::create_boundary_condition( const std::string& type,
                                                                  const std::string& name,
                                                                  const std::vector<URI>& regions )
{
  boost::shared_ptr< RDM::BoundaryTerm > bterm = build_component_abstract_type<RDM::BoundaryTerm>(type,name);

  add_component( bterm ); // stays owned here

  // place link either in the weak or strong bcs

  if ( bterm->is_weak() )
    m_weak_bcs->add_link( *bterm );
  else
    m_strong_bcs->add_link( *bterm );

  bterm->options().configure_option("regions" , regions);

  bterm->options().configure_option( RDM::Tags::mesh(), m_mesh);
  bterm->options().configure_option( RDM::Tags::solver() , m_solver);
  bterm->options().configure_option( RDM::Tags::physical_model() , m_physical_model);

  return *bterm;
}
Beispiel #16
0
static void component_response_cb(GtkWidget *d, int response, 
  GtkTreeSelection *sel)
{
  GtkTreeModel *model;
  GtkTreeIter iter;
  GValue val;
  struct component *c;

  switch (response) {
    case AP_RESPONSE_CHOOSE:
      gtk_tree_selection_get_selected (sel, &model, &iter);
      val.g_type = 0;
      gtk_tree_model_get_value (model, &iter, 1, &val);
      c = g_value_get_pointer(&val);
      add_component (c);
    case GTK_RESPONSE_CLOSE:
    case GTK_RESPONSE_CANCEL:
    case GTK_RESPONSE_DELETE_EVENT:
      gtk_widget_destroy(d);
      component_dialog = NULL;
      choose_button = NULL;
      break;
  }
}
Beispiel #17
0
CActionDirector& CActionDirector::append(const CAction::Ptr& action)
{
  Component::Ptr existing_child = get_child_ptr(action->name());
  if(is_null(existing_child))
  {
    if(action->has_parent())
    {
      CLink& action_link = create_component<CLink>(action->name());
      action_link.link_to(action);
    }
    else
    {
      add_component(action);
    }
    on_action_added(*action);
  }
  else
  {
    // If a child with the given name existed, check that it corresponds to the supplied action
    CAction::Ptr existing_action = boost::dynamic_pointer_cast<CAction>(existing_child);

    if(is_null(existing_action))
      throw ValueExists(FromHere(), "A component named " + action->name() + " already exists in " + uri().string() + ", but it is not a CAction");

    if(existing_action != action)
      throw ValueExists(FromHere(), "An action named " + action->name() + " already exists in " + uri().string() + ", but it is different from the appended action");
  }

  Option& actions_prop = option("ActionOrder");
  std::vector<std::string> actions; actions_prop.put_value(actions);

  actions.push_back(action->name());
  actions_prop.change_value(actions);

  return *this;
}
Beispiel #18
0
// ==========================================================================
// CONSTRUCTOR
// ==========================================================================
gm_tools_screen::gm_tools_screen()
    : pimpl_(std::make_shared<impl>())
{
    pimpl_->bestiary_page_           = std::make_shared<bestiary_page>();
    pimpl_->beast_editor_            = std::make_shared<beast_editor>();
    pimpl_->encounters_page_         = std::make_shared<encounters_page>();
    pimpl_->encounter_editor_        = std::make_shared<encounter_editor>();
    pimpl_->delete_beast_dialog_     = std::make_shared<delete_confirmation_dialog>();
    pimpl_->delete_encounter_dialog_ = std::make_shared<delete_confirmation_dialog>();

    pimpl_->bestiary_tab_card_ = munin::make_card();
    pimpl_->bestiary_tab_card_->add_face(pimpl_->bestiary_page_, bestiary_face);
    pimpl_->bestiary_tab_card_->add_face(pimpl_->beast_editor_, beast_editor_face);
    pimpl_->bestiary_tab_card_->add_face(pimpl_->delete_beast_dialog_, delete_beast_face);
    pimpl_->bestiary_tab_card_->select_face(bestiary_face);

    pimpl_->encounter_tab_card_ = munin::make_card();
    pimpl_->encounter_tab_card_->add_face(pimpl_->encounters_page_, encounters_face);
    pimpl_->encounter_tab_card_->add_face(pimpl_->encounter_editor_, encounter_editor_face);
    pimpl_->encounter_tab_card_->add_face(pimpl_->delete_encounter_dialog_, delete_encounter_face);
    pimpl_->encounter_tab_card_->select_face(encounters_face);

    pimpl_->bestiary_page_->on_edit.connect(
        [this](auto beast){pimpl_->on_edit_beast();});
    pimpl_->bestiary_page_->on_new.connect([this]{pimpl_->on_new_beast();});
    pimpl_->bestiary_page_->on_clone.connect(
        [this](auto beast){pimpl_->on_clone_beast();});
    pimpl_->bestiary_page_->on_fight.connect(on_fight_beast);
    pimpl_->bestiary_page_->on_delete.connect(
        [this](auto beast){pimpl_->on_delete_beast();});
    
    pimpl_->beast_editor_->on_save.connect([this]{pimpl_->on_save_beast();});
    pimpl_->beast_editor_->on_revert.connect([this]{pimpl_->on_revert_beast();});
    
    pimpl_->encounters_page_->on_new.connect([this]{pimpl_->on_new_encounter();});
    pimpl_->encounters_page_->on_edit.connect(
        [this](auto encounter){pimpl_->on_edit_encounter();});
    pimpl_->encounters_page_->on_clone.connect(
        [this](auto encounter){pimpl_->on_clone_encounter();});
    pimpl_->encounters_page_->on_fight.connect(on_fight_encounter);
    pimpl_->encounters_page_->on_delete.connect(
        [this](auto encounter){pimpl_->on_delete_encounter();});
    
    pimpl_->encounter_editor_->on_save.connect(
        [this]{pimpl_->on_save_encounter();});
    pimpl_->encounter_editor_->on_revert.connect(
        [this]{pimpl_->on_revert_encounter();});
    
    pimpl_->delete_beast_dialog_->on_delete_confirmation.connect(
        [this]{pimpl_->on_delete_beast_confirmation();});
    pimpl_->delete_beast_dialog_->on_delete_rejection.connect(
        [this]{pimpl_->on_delete_beast_rejection();});
    
    pimpl_->delete_encounter_dialog_->on_delete_confirmation.connect(
        [this]{pimpl_->on_delete_encounter_confirmation();});
    pimpl_->delete_encounter_dialog_->on_delete_rejection.connect(
        [this]{pimpl_->on_delete_encounter_rejection();});
    
    pimpl_->back_button_ = munin::make_button("Back");
    pimpl_->back_button_->on_click.connect(on_back);

    pimpl_->tabbed_panel_ = munin::make_tabbed_panel();
    pimpl_->tabbed_panel_->insert_tab("Bestiary", pimpl_->bestiary_tab_card_);
    pimpl_->tabbed_panel_->insert_tab("Encounters", pimpl_->encounter_tab_card_);

    auto content = get_container();
    content->set_layout(munin::make_compass_layout());
    content->add_component(pimpl_->tabbed_panel_, munin::COMPASS_LAYOUT_CENTRE);
    content->add_component(
        munin::view(
            munin::make_compass_layout(),
            pimpl_->back_button_, munin::COMPASS_LAYOUT_WEST,
            munin::make_background_fill(), munin::COMPASS_LAYOUT_CENTRE),
        munin::COMPASS_LAYOUT_SOUTH);
}
static void handle_msg(int fd, struct msg* m)
{
    switch (m->type) {
    case MSG_GET_HANDLE: {
        struct comp* c = (struct comp*) malloc(sizeof(struct comp));
        fprintf(stderr, "ILSRV: GetHandle '%s'\n", m->cmd.get_handle.name);
        m->result = OMX_GetHandle(&c->real_handle, m->cmd.get_handle.name, c, &callbacks);
        m->cmd.get_handle.out_srv_handle = (int) c;
        c->client_handle = m->cmd.get_handle.in_client_handle;
        c->client_fd     = fd;
        c->state         = OMX_StateLoaded;
        strncpy(c->name, m->cmd.get_handle.name, sizeof(c->name));
        c->name[sizeof(c->name)-1]=0;
        add_component(c);
        fprintf(stderr, "ILSRV: %08X [%20s] --> %s%s\n", c->real_handle, last_part(c->name), m->result == OMX_ErrorNone ? "" : "ERROR ", adm_log_err2str(m->result));
        return;
    }

    case MSG_SET_PARAM:{
        struct comp* c = (struct comp*) m->cmd.param.srv_handle;
        verify_component(c);
        fprintf(stderr, "ILSRV: %08X [%20s] SetParam %s\n", c->real_handle, last_part(c->name), adm_log_index2str(m->cmd.param.index));
        m->result = OMX_SetParameter(c->real_handle, (OMX_INDEXTYPE) m->cmd.param.index, m->cmd.param.buf); // TODO: Protect
        fprintf(stderr, "ILSRV: --> %s %s\n", m->result == OMX_ErrorNone ? "" : "ERROR ", adm_log_err2str(m->result));
        return;
    }
    case MSG_GET_PARAM:{
        struct comp* c = (struct comp*) m->cmd.param.srv_handle;
        verify_component(c);
        fprintf(stderr, "ILSRV: %08X [%20s] GetParam %s\n", c->real_handle, last_part(c->name), adm_log_index2str(m->cmd.param.index));
        m->result = OMX_GetParameter(c->real_handle, (OMX_INDEXTYPE)m->cmd.param.index, m->cmd.param.buf); // TODO: Protect
        fprintf(stderr, "ILSRV: --> %s %s\n", m->result == OMX_ErrorNone ? "" : "ERROR ", adm_log_err2str(m->result));
        return;
    }

    case MSG_GET_CONFIG:{
        struct comp* c = (struct comp*) m->cmd.param.srv_handle;
        verify_component(c);
        fprintf(stderr, "ILSRV: %08X [%20s] GetConfig %s\n", c->real_handle, last_part(c->name), adm_log_index2str(m->cmd.param.index));
        m->result = OMX_GetConfig(c->real_handle, (OMX_INDEXTYPE)m->cmd.param.index, m->cmd.param.buf); // TODO: Protect
        fprintf(stderr, "ILSRV: --> %s %s\n", m->result == OMX_ErrorNone ? "" : "ERROR ", adm_log_err2str(m->result));
        return;
    }

    case MSG_SET_CONFIG: {
        struct comp* c = (struct comp*) m->cmd.param.srv_handle;
        verify_component(c);
        fprintf(stderr, "ILSRV: %08X [%20s] SetConfig %s\n", c->real_handle, last_part(c->name), adm_log_index2str(m->cmd.param.index));
        m->result = OMX_SetConfig(c->real_handle, (OMX_INDEXTYPE)m->cmd.param.index, m->cmd.param.buf); // TODO: Protect
        fprintf(stderr, "ILSRV: --> %s %s\n", m->result == OMX_ErrorNone ? "" : "ERROR ", adm_log_err2str(m->result));
        return;
    }

    case MSG_FREE_HANDLE: {
        struct comp* c = (struct comp*) m->cmd.free_handle.srv_handle;
        verify_component(c);
        if (c->state != OMX_StateLoaded) {
            fprintf(stderr, "ILSRV: FreeHandle called for %X which is in wrong state (%s)\m", c->real_handle, adm_log_state2str(c->state));
            error_found();
        }
        fprintf(stderr, "ILSRV: %08X [%20s] Freehandle (internal=%X)\n", c->real_handle, last_part(c->name), c);
        m->result = OMX_FreeHandle(c->real_handle);
        fprintf(stderr, "ILSRV: --> %s %s\n", m->result == OMX_ErrorNone ? "" : "ERROR ", adm_log_err2str(m->result));
        del_component(c);
        memset(c, 0xFE, sizeof(*c));
        free(c);
        return;
    }

    case MSG_SEND_COMMAND: {
        struct comp* c = (struct comp*) m->cmd.free_handle.srv_handle;
        verify_component(c);
        if (m->cmd.command.cmd == OMX_CommandStateSet) {
            fprintf(stderr, "ILSRV: %08X [%20s] SendCommand StateSet %s\n", c->real_handle, last_part(c->name), adm_log_state2str((OMX_STATETYPE) m->cmd.command.nParam1));
        } else {
            fprintf(stderr, "ILSRV: %08X [%20s] SendCommand StateSet %s 0x%X\n", c->real_handle, last_part(c->name), adm_log_cmd2str(m->cmd.command.cmd), m->cmd.command.nParam1);
        }

        m->result = OMX_SendCommand(c->real_handle, m->cmd.command.cmd, m->cmd.command.nParam1, 0);
        fprintf(stderr, "ILSRV: --> %s %s\n", m->result == OMX_ErrorNone ? "" : "ERROR ", adm_log_err2str(m->result));
        return;
    }

    case MSG_SETUP_TUNNEL: {
        struct comp* c_in = (struct comp*) m->cmd.tunnel.srv_handle_in;
        struct comp* c_out = (struct comp*) m->cmd.tunnel.srv_handle_out;
        verify_component(c_in);
        verify_component(c_out);

        fprintf(stderr, "ILSRV: SetupTunnel %08X [%20s].%d --> %08X [%20s].%d\n", c_out->real_handle, last_part(c_out->name), m->cmd.tunnel.port_out, c_in->real_handle, last_part(c_in->name), m->cmd.tunnel.port_in);
        m->result = OMX_SetupTunnel(c_out->real_handle, m->cmd.tunnel.port_out, c_in->real_handle, m->cmd.tunnel.port_in);
        fprintf(stderr, "ILSRV: --> %s %s\n", m->result == OMX_ErrorNone ? "" : "ERROR ", adm_log_err2str(m->result));
        return;
    }

    case MSG_GET_STATE: {
        struct comp* c = (struct comp*) m->cmd.get_state.in_srv_handle;
        verify_component(c);
        fprintf(stderr, "ILSRV: %08X [%20s] GetState\n", c->real_handle, last_part(c->name));
        m->result = OMX_GetState(c->real_handle, &m->cmd.get_state.out_state);
        fprintf(stderr, "ILSRV: --> %s %s %s\n", m->result == OMX_ErrorNone ? "" : "ERROR ", adm_log_err2str(m->result), adm_log_state2str(m->cmd.get_state.out_state));
        return;
    }

    case MSG_ALLOC_BUFFER: {
        struct comp* c = (struct comp*) m->cmd.alloc_buffer.in_srv_handle;
        verify_component(c);

        OMX_BUFFERHEADERTYPE* bufhdr;
        fprintf(stderr, "ILSRV: %08X [%20s] AllocBuf port=%d size=%d\n", c->real_handle, last_part(c->name), m->cmd.alloc_buffer.port, m->cmd.alloc_buffer.size);
        m->result = OMX_AllocateBuffer(c->real_handle, &bufhdr, m->cmd.alloc_buffer.port,
                     (void*) m->cmd.alloc_buffer.in_client_buf_hdr, m->cmd.alloc_buffer.size);

        if (m->result == OMX_ErrorNone) {
            memcpy(&m->cmd.alloc_buffer.out_buf_hdr, bufhdr, sizeof(OMX_BUFFERHEADERTYPE));
            m->cmd.alloc_buffer.out_srv_buf_hdr = (int) bufhdr;
            add_bufhdr(bufhdr);
        }
        fprintf(stderr, "ILSRV: --> %s %s\n", m->result == OMX_ErrorNone ? "" : "ERROR ", adm_log_err2str(m->result));
        return;
    }

    case MSG_EMPTY_BUFFER: {
        struct comp* c = (struct comp*) m->cmd.empty_buffer.in_srv_handle;
        verify_component(c);

        OMX_BUFFERHEADERTYPE* client_bufhdr = (OMX_BUFFERHEADERTYPE*) &m->cmd.empty_buffer.in_buf_hdr;
        OMX_BUFFERHEADERTYPE* bufhdr = (OMX_BUFFERHEADERTYPE*) client_bufhdr->pPlatformPrivate;

        verify_bufhdr(bufhdr);

        if (bufhdr->nAllocLen <= sizeof(m->cmd.empty_buffer.in_buf)) {
            bufhdr->nOffset    = client_bufhdr->nOffset;
            bufhdr->nTimeStamp = client_bufhdr->nTimeStamp;
            bufhdr->nFilledLen = client_bufhdr->nFilledLen;
            bufhdr->nFlags     = client_bufhdr->nFlags;

            memcpy(bufhdr->pBuffer, &m->cmd.empty_buffer.in_buf, bufhdr->nAllocLen);
            fprintf(stderr, "ILSRV: %08X [%20s] EmptyBuffer port=%d size=%d\n", c->real_handle, last_part(c->name), bufhdr->nInputPortIndex, bufhdr->nAllocLen);
            m->result = OMX_EmptyThisBuffer(c->real_handle, bufhdr);
            fprintf(stderr, "ILSRV: --> %s %s\n", m->result == OMX_ErrorNone ? "" : "ERROR ", adm_log_err2str(m->result));
        } else {
            assert(0);
        }

        return;
    }

    case MSG_FILL_BUFFER: {
        struct comp* c = (struct comp*) m->cmd.empty_buffer.in_srv_handle;
        verify_component(c);

        OMX_BUFFERHEADERTYPE* client_bufhdr = (OMX_BUFFERHEADERTYPE*) &m->cmd.fill_buffer.in_buf_hdr;
        OMX_BUFFERHEADERTYPE* bufhdr = (OMX_BUFFERHEADERTYPE*) client_bufhdr->pPlatformPrivate;

        verify_bufhdr(bufhdr);

        fprintf(stderr, "ILSRV: %08X [%20s] FillBuffer port=%d size=%d\n", c->real_handle, last_part(c->name), bufhdr->nOutputPortIndex, bufhdr->nAllocLen);
        m->result = OMX_FillThisBuffer(c->real_handle, bufhdr);
        fprintf(stderr, "ILSRV: --> %s %s\n", m->result == OMX_ErrorNone ? "" : "ERROR ", adm_log_err2str(m->result));

        return;
    }

    case MSG_FREE_BUFFER: {
        struct comp* c = (struct comp*) m->cmd.empty_buffer.in_srv_handle;
        verify_component(c);

        OMX_BUFFERHEADERTYPE* bufhdr = (OMX_BUFFERHEADERTYPE*) m->cmd.free_buffer.in_srv_buf_hdr;
        verify_bufhdr(bufhdr);

        del_bufhdr(bufhdr);
        fprintf(stderr, "ILSRV: %08X [%20s] FreeBuffer\n", c->real_handle, last_part(c->name));
        m->result = OMX_FreeBuffer(c->real_handle, m->cmd.free_buffer.in_port, bufhdr);
        fprintf(stderr, "ILSRV: --> %s %s\n", m->result == OMX_ErrorNone ? "" : "ERROR ", adm_log_err2str(m->result));
        return;
    }

    default:
       fprintf(stderr, "ILSRV: Unhandled request received\n");
       m->result = OMX_ErrorNotImplemented;
       error_found();
       return;
    }
static gboolean press_callback(GtkWidget* widget,GdkEventButton* event,gpointer data)
{
	double mx=event->x;
	double my=event->y;
	double width=gtk_widget_get_allocated_width(widget);
	double height=gtk_widget_get_allocated_height(widget);
	double spacing=MIN((width-2*gutter)/grid.width,(height-2*gutter)/grid.height);
	mx-=width/2.0;
	my-=height/2.0;
	mx=mx/spacing;
	my=my/spacing;
	mx+=grid.width/2.0;
	my+=grid.height/2.0;
	int ia,ib;
	double da,db;
	int i;
	ia=0;ib=0;
	da=db=grid.width+grid.height;
	for(i=0;i<grid.map.vcount;i++){
		double x=grid.map.vertices[i].id%(grid.width+1);
		double y=(int)(grid.map.vertices[i].id/(grid.width+1));
		double d=sqrt((x-mx)*(x-mx)+(y-my)*(y-my));
		if(d<da){
			db=da;
			ib=ia;
			da=d;
			ia=i;
		}else if(d<db){
			db=d;
			ib=i;
		}
	}
	int A=MIN(grid.map.vertices[ia].id,grid.map.vertices[ib].id);
	int B=MAX(grid.map.vertices[ia].id,grid.map.vertices[ib].id);

	if(draw_state==PLACE_WIRE){
		Component c;
		c.type=WIRE;
		c.A=A;
		c.B=B;
		add_component(c);
	}
	if(draw_state==PLACE_RESISTOR){
		Component c;
		c.type=RESISTOR;
		c.A=A;
		c.B=B;
		c.data=calloc(1,sizeof(double));
		*(double*)c.data=10;
		add_component(c);
	}
	if(draw_state==PLACE_BATTERY){
		Component c;
		c.type=BATTERY;
		c.A=A;
		c.B=B;
		c.data=calloc(1,sizeof(double));
		*(double*)c.data=5;
		add_component(c);
	}if(draw_state==DELETE){
		for(i=0;i<grid.map.ccount;i++){
			if((grid.map.components[i].A==A)&&(grid.map.components[i].B==B)){
				remove_component(i);
				break;
			}
		}
	}if(draw_state==EDIT){
		for(i=0;i<grid.map.ccount;i++){
			if((grid.map.components[i].A==A)&&(grid.map.components[i].B==B)){
				edit_dialog(grid.map.components+i);
				break;
			}
		}
	}
	calculate();
	//gtk_widget_queue_draw_area(widget,0,0,width,height);
	gtk_widget_queue_draw(widget);
	return TRUE;
}