/** Function  oyFilterNode_ShowConnector
 *  @memberof oyFilterNode_s
 *  @brief    Get a connector description from a filter module
 *
 *  The path to obtain a new connector.
 *  The filter can say it has more connectors to provide for a certain kind of
 *  static connector eigther described in oyCMMapi4_s::inputs or
 *  oyCMMapi4_s::outputs.
 *
 *  @param[in]   node                the module filter node
 *  @param[in]   as_pos              the according oyConnector_s
 *  @param[in]   is_plug             select from 0 - plugs or 1 - sockets
 *  @return                          the new oyConnector_s
 *
 *  @version Oyranos: 0.1.10
 *  @since   2008/07/28 (Oyranos: 0.1.8)
 *  @date    2008/12/27
 */
OYAPI oyConnector_s * OYEXPORT
             oyFilterNode_ShowConnector (
                                       oyFilterNode_s    * node,
                                       int                 as_pos,
                                       int                 is_plug )
{
  oyConnector_s * pattern = 0;
  oyObject_s object = 0;

  oyFilterNode_s_ ** node_ = (oyFilterNode_s_**)&node;

  if(!node || !(*node_)->core || node->type_ != oyOBJECT_FILTER_NODE_S ||
     !(*node_)->api7_)
    return 0;

  object = oyObject_New ();

  if(is_plug)
  {
    if((*node_)->api7_->plugs_n <= (size_t)as_pos &&
       as_pos < oyFilterNode_EdgeCount( node, 1, 0 ))
      as_pos = (*node_)->api7_->plugs_n - 1;

    if((*node_)->api7_->plugs_n > (size_t)as_pos)
    {
      if((*node_)->api7_->plugs[as_pos] && (*node_)->api7_->plugs[as_pos]->copy)
      {
        pattern = (oyConnector_s*) (*node_)->api7_->plugs[as_pos]->copy( (oyStruct_s*) (*node_)->api7_->plugs[as_pos], object );
        if(oy_debug_objects >= 0)
          oyObjectDebugMessage_( (*node_)->api7_->plugs[as_pos]->oy_, __func__,
                                 oyStructTypeToText((*node_)->api7_->plugs[as_pos]->type_) );
      } else
      {
        pattern = oyConnector_Copy( (*node_)->api7_->plugs[as_pos], object );
      }
    }
  } else {
    if((*node_)->api7_->sockets_n <= (size_t)as_pos &&
       as_pos < oyFilterNode_EdgeCount( node, 0, 0 ))
      as_pos = (*node_)->api7_->sockets_n - 1;

    if((*node_)->api7_->sockets_n > (size_t)as_pos)
    {
      if((*node_)->api7_->sockets[as_pos] && (*node_)->api7_->sockets[as_pos]->copy)
      {
        pattern = (oyConnector_s*) (*node_)->api7_->sockets[as_pos]->copy( (oyStruct_s*) (*node_)->api7_->sockets[as_pos], object );
        if(oy_debug_objects >= 0)
          oyObjectDebugMessage_( (*node_)->api7_->sockets[as_pos]->oy_, __func__,
                                 oyStructTypeToText((*node_)->api7_->sockets[as_pos]->type_) );
      } else
      {
        pattern = oyConnector_Copy( (*node_)->api7_->sockets[as_pos], object );
      }
    }
  }

  oyObject_Release( &object );

  return pattern;
}
/** Function  oyFilterNode_GetData
 *  @memberof oyFilterNode_s
 *  @brief    Get process data from a filter socket
 *
 *  @param[in]     node                filter node
 *  @param[in]     socket_pos          position of socket
 *  @return                            the data
 *
 *  @version Oyranos: 0.1.10
 *  @since   2009/03/05 (Oyranos: 0.1.10)
 *  @date    2009/03/05
 */
oyStruct_s *   oyFilterNode_GetData  ( oyFilterNode_s    * node,
                                       int                 socket_pos )
{
  oyFilterNode_s * s = node;
  oyStruct_s * data = 0;
  oyFilterSocket_s * socket = 0;

  if(!s)
    return 0;

  oyCheckType__m( oyOBJECT_FILTER_NODE_S, return 0 );

  socket = oyFilterNode_GetSocket( node, socket_pos );
  if(socket)
    data = oyFilterSocketPriv_m(socket)->data;

  oyFilterSocket_Release( &socket );

  if(data && data->copy)
  {
    data = data->copy( data, 0 );
    if(oy_debug_objects >= 0)
      oyObjectDebugMessage_( data->oy_, __func__, oyStructTypeToText(data->type_) );
  }

  return data;
}
Ejemplo n.º 3
0
/** @fn       oyConnectorImaging_Copy
 *  @memberof oyConnectorImaging_s
 *  @brief    Copy or Reference a ConnectorImaging object
 *
 *  The function is for copying and for referencing. The reference is the most
 *  often used way, which saves resourcs and time.
 *
 *  @param[in]     connectorimaging                 ConnectorImaging struct object
 *  @param         object              NULL - means reference,
 *                                     the optional object triggers a real copy
 */
OYAPI oyConnectorImaging_s* OYEXPORT
  oyConnectorImaging_Copy( oyConnectorImaging_s *connectorimaging, oyObject_s object )
{
  oyConnectorImaging_s_ * s = (oyConnectorImaging_s_*) connectorimaging;

  if(s)
    oyCheckCType__m( oyOBJECT_CONNECTOR_IMAGING_S, return 0 )

  s = oyConnectorImaging_Copy_( s, object );

  if(oy_debug_objects >= 0)
    oyObjectDebugMessage_( s?s->oy_:NULL, __func__, "oyConnectorImaging_s" );

  return (oyConnectorImaging_s*) s;
}
Ejemplo n.º 4
0
/** @fn       oyCMMapis_Copy
 *  @memberof oyCMMapis_s
 *  @brief    Copy or Reference a CMMapis object
 *
 *  The function is for copying and for referencing. The reference is the most
 *  often used way, which saves resourcs and time.
 *
 *  @param[in]     cmmapis                 CMMapis struct object
 *  @param         object              NULL - means reference,
 *                                     the optional object triggers a real copy
 */
OYAPI oyCMMapis_s* OYEXPORT
  oyCMMapis_Copy( oyCMMapis_s *cmmapis, oyObject_s object )
{
  oyCMMapis_s_ * s = (oyCMMapis_s_*) cmmapis;

  if(s)
    oyCheckType__m( oyOBJECT_CMM_APIS_S, return 0 )

  s = oyCMMapis_Copy_( s, object );

  if(oy_debug_objects >= 0)
    oyObjectDebugMessage_( s?s->oy_:NULL, __func__, "oyCMMapis_s" );

  return (oyCMMapis_s*) s;
}
/** Function  oyFilterNode_SetData
 *  @memberof oyFilterNode_s
 *  @brief    Set process data to a filter socket
 *
 *  @param[in,out] node                filter node
 *  @param[in]     data                data
 *  @param[in]     socket_pos          position of socket
 *  @param[in]     object              a object to not only set a reference
 *  @return                            error
 *
 *  @version Oyranos: 0.1.10
 *  @since   2009/03/05 (Oyranos: 0.1.10)
 *  @date    2009/03/05
 */
int            oyFilterNode_SetData  ( oyFilterNode_s    * node,
                                       oyStruct_s        * data,
                                       int                 socket_pos,
                                       oyObject_s        * object )
{
  oyFilterNode_s * s = node;
  oyFilterSocket_s_ * socket = 0;

  if(!s)
    return 0;

  oyCheckType__m( oyOBJECT_FILTER_NODE_S, return 0 );

  socket = (oyFilterSocket_s_*)oyFilterNode_GetSocket( node, socket_pos );

  if(socket)
  {
    if(socket->data && socket->data->release)
      socket->data->release( &socket->data );

    if(data && data->copy)
    {
      socket->data = data->copy( data, object );
      if(oy_debug_objects >= 0)
        oyObjectDebugMessage_( socket->data->oy_, __func__, oyStructTypeToText(socket->data->type_) );
    } else
      socket->data = data;

    oyFilterSocket_Release( (oyFilterSocket_s **) &socket );
  } else
  {
    WARNc_S("Node has no socket. Can not assign data.");
    return -1;
  }

  return 0;
}
/** Function  oyFilterNode_Connect
 *  @memberof oyFilterNode_s
 *  @brief    Connect two nodes by a edge
 *
 *  @param         input               the node to provide a socket
 *  @param         socket_nick         name of socket
 *  @param         output              the node providing a plug
 *  @param         plug_nick           name of plug
 *  @param         flags               unused
 *  @return                            error
 *
 *  @version Oyranos: 0.1.10
 *  @since   2009/02/26 (Oyranos: 0.1.10)
 *  @date    2009/02/26
 */
int            oyFilterNode_Connect  ( oyFilterNode_s    * input,
                                       const char        * socket_nick,
                                       oyFilterNode_s    * output,
                                       const char        * plug_nick,
                                       int                 flags OY_UNUSED )
{
  oyFilterNode_s_ * s = (oyFilterNode_s_*)input;
  int error = !s;
  oyFilterPlug_s * out_plug = 0;
  oyFilterSocket_s * output_socket = 0,
                   * in_socket = 0;
  int pos, out_pos;

  oyCheckType__m( oyOBJECT_FILTER_NODE_S, return 1 )
  s = (oyFilterNode_s_*)output;
  oyCheckType__m( oyOBJECT_FILTER_NODE_S, return 1 )

  if(error <= 0)
  {
    if(error <= 0 &&
       (!s->core || !s->core->api4_))
    {
      WARNcc2_S( s, "%s: %s",
      _("attempt to add a incomplete filter"), s->relatives_ );
      error = 1;
    }
    if(error <= 0 &&
       !oyFilterNode_EdgeCount( input, 0, OY_FILTEREDGE_FREE ))
    {
      WARNcc2_S( input, "%s: %s", "input node has no free socket",
                 oyFilterCore_GetName( (oyFilterCore_s*)oyFilterNodePriv_m(input)->core, oyNAME_NAME) );
      error = 1;
    }

    if(error <= 0)
    {
      if(socket_nick)
        pos = oyFilterNode_GetConnectorPos( input, 0, socket_nick, 0,
                                            0 );
      else
        pos = 0;
      if(pos >= 0)
        in_socket = oyFilterNode_GetSocket( input, pos );

      if(plug_nick)
        out_pos = oyFilterNode_GetConnectorPos( output, 1, plug_nick, 0,
                                                OY_FILTEREDGE_FREE );
      else
        out_pos = 0;

      if(out_pos >= 0)
        out_plug = oyFilterNode_GetPlug( output, out_pos );

      if(!out_plug)
      {
        WARNcc3_S( output, "\n  %s: \"%s\" %s", "Could not find plug for filter",
                   oyFilterCore_GetName( (oyFilterCore_s*)oyFilterNodePriv_m(output)->core, oyNAME_NAME), socket_nick );
        error = 1;
      }

      if(error <= 0)
      {
        if(oyFilterNode_ConnectorMatch( input, pos, out_plug ))
          output_socket = oyFilterNode_GetSocket( output, 0 );
        else
        {
          WARNcc3_S( input, "\n  %s: %s -> %s", "Filter connectors do not match",
                     oyFilterNodePriv_m(input)->relatives_, oyFilterNodePriv_m(output)->relatives_ );
          error = 1;
        }
      }

      if(error <= 0 && output_socket && !oyFilterSocketPriv_m(output_socket)->data &&
         in_socket && oyFilterSocketPriv_m(in_socket)->data)
      {
        oyFilterSocketPriv_m(output_socket)->data = oyFilterSocketPriv_m(in_socket)->data->copy(
                                                      oyFilterSocketPriv_m(in_socket)->data,
                                                      0 );
        if(oy_debug_objects >= 0)
          oyObjectDebugMessage_( oyFilterSocketPriv_m(output_socket)->data->oy_, __func__,
                                 oyStructTypeToText(oyFilterSocketPriv_m(output_socket)->data->type_) );
      }

      if(error <= 0)
      {
        oyFilterPlug_s_  * out_plug_ = (oyFilterPlug_s_*) out_plug;
        oyFilterSocket_s_* in_socket_ = (oyFilterSocket_s_*)in_socket;
        error = oyFilterPlug_ConnectIntoSocket( &out_plug, &in_socket );
        if(error <= 0)
        {
          oyFilterNode_Release( (oyFilterNode_s**) &out_plug_->node );
          out_plug_->node = (oyFilterNode_s_*) oyFilterNode_Copy( output, NULL );
          oyFilterNode_Release( (oyFilterNode_s**) &in_socket_->node );
          in_socket_->node = (oyFilterNode_s_*) oyFilterNode_Copy( input, NULL );
        }
      }

    } else
      WARNcc2_S( input, "%s: %d", _("?? Nothing to add ??"),
                 oyObject_GetId(input->oy_));
  }
  oyFilterSocket_Release( &output_socket );

  return error;
}
/** Function oyStruct_ObserverAdd
 *  @memberof oyObserver_s
 *  @brief   send a signal to a Observer object
 *
 *  @param[in]     model               the to be observed model
 *  @param[in]     observer            the in observation intereressted object
 *  @param[in]     user_data           additional static informations
 *  @param[in]     signalFunc          the signal handler;
 *                                     defaults to oyStructSignalForward_
 *  @return                            0 - fine; 1 - error
 *
 *  @version Oyranos: 0.1.10
 *  @since   2009/10/26 (Oyranos: 0.1.10)
 *  @date    2010/06/25
 */
OYAPI int  OYEXPORT
           oyStruct_ObserverAdd      ( oyStruct_s        * model,
                                       oyStruct_s        * observer,
                                       oyStruct_s        * user_data,
                                       oyObserver_Signal_f signalFunc )
{
  oyObserver_s * s = 0,
               * obs = 0;
  int error = !model || !observer;
  oyStructList_s * list = 0;
  int n,i, found;

  if(!signalFunc)
    signalFunc = oyStructSignalForward_;

  /* add to model */
  if(!error)
    list = oyStruct_ObserverListGet_( model, OY_SIGNAL_OBSERVERS );
  if(!error && list)
  {
    found = 0;
    n = oyStructList_Count( list );
    for(i = 0; i < n; ++i)
    {
      obs = (oyObserver_s*) oyStructList_GetType( list,
                                                  i, oyOBJECT_OBSERVER_S );
      if(observer == obs->observer && obs->signal == signalFunc)
        ++found;
    }

    /* add new oyObserver_s */
    if(found == 0)
    {
      s = oyObserver_New( 0 );
      if(observer)
        s->observer = observer->copy( observer, 0 );
      s->model = model->copy( model, 0 );
      if(user_data)
        s->user_data = user_data->copy( user_data, 0 );
      s->signal = signalFunc;
      if(oy_debug_objects >= 0)
      {
        if(s->observer)
          oyObjectDebugMessage_( s->observer->oy_, __func__,
                                 oyStructTypeToText(s->observer->type_) );
        if(s->model)
          oyObjectDebugMessage_( s->model->oy_, __func__,
                                 oyStructTypeToText(s->model->type_) );
        if(s->user_data)
          oyObjectDebugMessage_( s->user_data->oy_, __func__,
                                 oyStructTypeToText(s->user_data->type_) );
      }

      oyStructList_MoveIn( list, (oyStruct_s**)&s, -1, 0 );
    }
  }

  /* add to observer */
  if(!error)
    list = oyStruct_ObserverListGet_( observer, OY_SIGNAL_MODELS );
  if(!error && list)
  {
    found = 0;
    n = oyStructList_Count( list );
    for(i = 0; i < n; ++i)
    {
      obs = (oyObserver_s*) oyStructList_GetType( list,
                                                  i, oyOBJECT_OBSERVER_S );
      if(model == obs->model && obs->signal == signalFunc)
        ++found;
    }

    /* add oyObserver_s */
    if(found == 0 && !s)
    {
      s = oyObserver_New( 0 );
      if(observer)
        s->observer = observer->copy( observer, 0 );
      s->model = model->copy( model, 0 );
      if(user_data)
        s->user_data = user_data->copy( user_data, 0 );
      s->signal = signalFunc;
    }

    if(s)
      oyStructList_MoveIn( list, (oyStruct_s**)&s, -1, 0 );
  }

  return error;
}