⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 connection.c

📁 This a framework to test new ideas in transmission technology. Actual development is a LDPC-coder in
💻 C
字号:
/***************************************************************************         connection.c  -  Connections                            -------------------    begin                :  2002    authors              :  Linus Gasser    emails               :  linus.gasser@epfl.ch ***************************************************************************//***************************************************************************                                 Changes                                 ------- date - name - description 02-09-11 - ineiti- begin  **************************************************************************//*************************************************************************** *                                                                         * *   This program is free software; you can redistribute it and/or modify  * *   it under the terms of the GNU General Public License as published by  * *   the Free Software Foundation; either version 2 of the License, or     * *   (at your option) any later version.                                   * *                                                                         * ***************************************************************************//** * @short Connection is the database that is responsible of * keeping track of all connections. *//** * Debugging priorities * * LVL 0 : Error messages only * LVL 1 : Important status messages * LVL 2 : Not too much traffic * LVL 3 : A bit more detailed * LVL 4 : S P A M - all we can do * * This way you can increase or decreas the level of debugging * messages depending on what you're doing. */#define DBG_LVL 0#define EXPORT_SYMTAB#include "system.h"#include "debugging.h"#include "connection.h"#include "memory.h"#include "cdb.h"#include "sdb.h"#include "connection_local.h"//----------------------------------------------------------------------// Interface functions//----------------------------------------------------------------------/** * @short Adds a connection between two subsystems */swr_conn swr_conn_add( swr_sdb_id sender,                       int output,                       swr_sdb_id receiver,                       int input ) {  connection_t conn_tmp;  // Initialise a lot of stuff  if ( conn_get_ids( &conn_tmp,                     sender, receiver, output, input ) < 0 )    goto conn_invalid;  PR_DBG( 4, "Got IDs\n" );  switch( conn_send( &conn_tmp ) ) {  case -1:    goto conn_invalid;  case -2:    goto conn_invalid_rcv;  case -3:    goto conn_invalid_rcv_snd;  }  PR_DBG( 4, "Sent IDs\n" );  ENTRY( conn_next_id ) = conn_tmp;  return conn_next_id;conn_invalid_rcv_snd:  swr_sdb_send_msg( conn_tmp.receiver, SUBS_MSG_DISCONNECT, &conn_tmp.rrcv, -1 );conn_invalid_rcv:  swr_sdb_send_msg( conn_tmp.sender, SUBS_MSG_DISCONNECT, &conn_tmp.rsend, -1 );conn_invalid:  return SWR_CONN_INVALID;}/** * @short Deletes a connection */int swr_conn_delete( swr_conn id ) {  connection_t *conn_tmp;  if ( ENTRY( id ).ID != id ) {    PR_DBG( 0,"ERROR: id not valid\n" );    return SWR_CONN_INVALID;  }  conn_tmp = &ENTRY( id );  swr_sdb_send_msg( conn_tmp->sender, SUBS_MSG_DISCONNECT, &conn_tmp->rsend, -1 );  swr_sdb_send_msg( conn_tmp->receiver, SUBS_MSG_DISCONNECT, &conn_tmp->rrcv, -1 );  conn_tmp->ID = -1;  return 0;}/** * @short Writes maximum size connection-ids in ids and * returns the total number of ids. */int swr_conn_list( swr_conn *ids, int size ) {  int i, tot=0;  for ( i=0; i<MAX_CONNECTIONS; i++ ) {    if ( ENTRY(i).ID != -1 ) {      if ( tot < size ) {        ids[tot] = ENTRY(i).ID;      }      tot++;    }  }  return tot;}/** * @short More detail about one connection */int swr_conn_detail_sender( swr_sdb_id id,                            int port_in,                            swr_sdb_id *sender,                            int *output ) {  swr_sdb_t *sdb;  // Do some error-checking first  sdb = swr_sdb_get_struct( id );  if ( !sdb ) {    PR_DBG( 0, "Receiving-id not valid\n" );    return SWR_CONN_INVALID;  }  if ( sdb->cdb_desc->inputs.nbr_ports <= port_in ) {    PR_DBG( 0, "Input-port number invalid\n" );    return SWR_CONN_INVALID;  }  // And then read out the values directly from the structures  if ( sender )    *sender = sdb->port_in[port_in].sdb_id;  if ( output )    *output = sdb->port_in[port_in].port;  return 0;}int swr_conn_detail_receiver( swr_sdb_id id,                              int port_out,                              swr_sdb_id *receiver,                              int *input ) {  swr_sdb_t *sdb;  // Do some error-checking first  sdb = swr_sdb_get_struct( id );  if ( !sdb ) {    PR_DBG( 0, "Sending-id not valid\n" );    return SWR_CONN_INVALID;  }  if ( sdb->cdb_desc->outputs.nbr_ports <= port_out ) {    PR_DBG( 0, "Output-port number invalid\n" );    return SWR_CONN_INVALID;  }  // And then read out the values directly from the structures  if ( receiver )    *receiver = sdb->port_out[port_out].sdb_id;  if ( input )    *input = sdb->port_out[port_out].port;  return 0;}/** * @short Remove all connections from/to this subsystem */int swr_conn_sdb_remove( swr_sdb_id id ) {  int i, tot=0;  for ( i=0; i<MAX_CONNECTIONS; i++ ) {    if ( ENTRY(i).ID != -1 ) {      if ( ( ENTRY(i).sender == id ) ||           ( ENTRY(i).receiver == id ) ) {        swr_conn_delete( i );        tot++;      }    }  }  return ( tot > 0 ) - 1;}/** * This function is called when the module is loaded */int swr_conn_init(void) {  int i;  conn_table = swr_malloc( sizeof( connection_t ) * MAX_CONNECTIONS );  if ( !conn_table )    goto setup_conn_table_failed;  for ( i=0; i < MAX_CONNECTIONS; i++ ) {    ENTRY( i ).ID = -1;  }  conn_next_id = 0;  PR_DBG( 2, "%i connections initialised\n", MAX_CONNECTIONS );  return 0;setup_conn_table_failed:  PR_DBG( 0, "Connection init failed\n" );  return 1;}/** * This function is called when the module is unloaded. */void swr_conn_cleanup(void) {  if ( conn_table ) {    swr_free( conn_table );  } else {    PR_DBG( 0, "Error while freeing conn_table\n" );  }  PR_DBG( 2, "Connections cleaned up\n" );}EXPORT_SYMBOL(swr_conn_add);EXPORT_SYMBOL(swr_conn_delete);EXPORT_SYMBOL(swr_conn_list);EXPORT_SYMBOL(swr_conn_detail_sender);EXPORT_SYMBOL(swr_conn_detail_receiver);EXPORT_SYMBOL(swr_conn_sdb_remove);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -