Main Page   Class Hierarchy   Compound List   File List   Compound Members  

C_ChannelControl.cpp

00001 /*
00002  *  This program is free software; you can redistribute it and/or modify
00003  *  it under the terms of the GNU General Public License as published by
00004  *  the Free Software Foundation; either version 2 of the License, or
00005  *  (at your option) any later version.
00006  *
00007  *  This program is distributed in the hope that it will be useful,
00008  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00009  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010  *  GNU General Public License for more details.
00011  *
00012  *  You should have received a copy of the GNU General Public License
00013  *  along with this program; if not, write to the Free Software
00014  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00015  *
00016  * (c)Copyright 2006 Hewlett-Packard Development Company, LP.
00017  *
00018  */
00019 
00020 #include "C_ChannelControl.hpp"
00021 #include "Utils.hpp"
00022 
00023 #include "GeneratorTrace.hpp"
00024 #include "GeneratorError.h"
00025 
00026 #include "set_t.hpp"
00027 
00028 #define XML_CHANNEL_SECTION      (char*)"configuration"
00029 #define XML_CHANNEL_SUBSECTION   (char*)"define"
00030 #define XML_CHANNEL_ENTITY       (char*)"entity"
00031 #define XML_CHANNEL_ENTITY_VALUE (char*)"channel"
00032 #define XML_CHANNEL_NAME         (char*)"name"
00033 #define XML_CHANNEL_GLOBAL       (char*)"global"
00034 #define XML_CHANNEL_GLOBAL_VALUE (char*)"yes"
00035 #define XML_CHANNEL_PROTOCOL     (char*)"protocol"
00036 #define XML_CHANNEL_TRANSPORT    (char*)"transport"
00037 #define XML_CHANNEL_OPEN         (char*)"open-args"
00038 #define XML_CHANNEL_RECONNECT    (char*)"reconnect"
00039 
00040 
00041 typedef struct _channel_info {
00042   int                                m_id             ;
00043   C_ChannelControl::T_ChannelType    m_type           ;
00044   char                              *m_protocol_name  ;
00045   char                              *m_transport_name ;
00046   char                              *m_open_args      ;
00047   char                              *m_name           ;
00048   char                              *m_reconnect      ;
00049 } T_ChannelInfo, *T_pChannelInfo ;
00050 typedef list_t<T_pChannelInfo> T_ChannelInfoList ;
00051 
00052 typedef set_t<int> T_IntSet, *T_pIntSet ;
00053 
00054 C_ChannelControl::C_ChannelControl() {
00055   GEN_DEBUG(1, "C_ChannelControl::C_ChannelControl() start");
00056   NEW_VAR(m_name_map, T_ChannelNameMap());
00057   //  m_name_map->clear() ;
00058   m_channel_table = NULL ;
00059   m_channel_table_size = 0 ;
00060   m_nb_global_channel = 0 ;
00061   NEW_VAR(m_id_gen, C_IdGenerator()) ;
00062   m_channel_to_ctxt_table = NULL ;
00063   m_ctxt_to_channel_table = NULL ;
00064   m_transport_table = NULL ;
00065   m_nb_transport = 0 ;
00066   m_reconnect = false ;
00067   m_sem_reconnect = NULL ;
00068   GEN_DEBUG(1, "C_ChannelControl::C_ChannelControl() end");
00069 }
00070 
00071 bool C_ChannelControl::reconnect() {
00072   return (m_reconnect);
00073 }
00074 
00075 C_ChannelControl::~C_ChannelControl() {
00076 
00077   int L_i ;
00078 
00079   GEN_DEBUG(1, "C_ChannelControl::~C_ChannelControl() start");
00080   if (!m_name_map->empty()) {
00081     m_name_map->erase(m_name_map->begin(), m_name_map->end());
00082   }
00083   DELETE_VAR(m_name_map);
00084   if (m_channel_table_size != 0) {
00085     for (L_i = 0 ; L_i < m_channel_table_size; L_i++) {
00086       FREE_VAR(m_channel_table[L_i]);
00087     }
00088     FREE_TABLE(m_channel_table);
00089     m_channel_table_size = 0 ;
00090   }
00091   DELETE_VAR(m_id_gen) ;
00092   m_nb_global_channel = 0 ;
00093   FREE_TABLE(m_channel_to_ctxt_table);
00094   FREE_TABLE(m_ctxt_to_channel_table);
00095   m_nb_transport = 0 ;
00096   FREE_TABLE(m_transport_table);
00097   DELETE_VAR(m_sem_reconnect);
00098   GEN_DEBUG(1, "C_ChannelControl::~C_ChannelControl() end");
00099 }
00100 
00101 bool C_ChannelControl::fromXml (C_XmlData *P_data, 
00102                                 C_ProtocolControl  *P_protocol_ctrl,
00103                                 C_TransportControl *P_transport_ctrl) {
00104   
00105   bool                          L_ret       = true   ;
00106   T_pXmlData_List               L_sectionList, L_subSectionList            ;
00107   T_XmlData_List::iterator      L_sectionListIt, L_subSectionListIt ;
00108   C_XmlData                    *L_section, *L_subSection ;
00109   char                         *L_entity_value ;
00110   char                         *L_name, 
00111                                *L_open_args,
00112                                *L_transport_name,
00113                                *L_protocol_name ,
00114                                *L_reconnect;
00115   int                           L_channel_id ;
00116   T_ChannelType                 L_channel_type ;
00117   T_pChannelInfo                L_channel_info = NULL ;
00118   T_ChannelInfoList             L_channel_info_list ;
00119   T_ChannelInfoList::iterator   L_it ;
00120   T_pChannelData                L_data ;
00121 
00122   GEN_DEBUG(1, "C_ChannelControl::fromXml() start");
00123 
00124   if (P_data != NULL) {
00125     if ((L_sectionList = P_data->get_sub_data()) != NULL) {
00126       
00127       for(L_sectionListIt  = L_sectionList->begin() ;
00128           L_sectionListIt != L_sectionList->end() ;
00129           L_sectionListIt++) {
00130 
00131         L_section = *L_sectionListIt ;
00132         if (L_section != NULL) {
00133           if (strcmp(L_section->get_name(), XML_CHANNEL_SECTION) == 0) {
00134 
00135             L_subSectionList = L_section->get_sub_data() ;
00136             for(L_subSectionListIt  = L_subSectionList->begin() ;
00137                 L_subSectionListIt != L_subSectionList->end() ;
00138                 L_subSectionListIt++) {
00139               L_subSection = *L_subSectionListIt ;
00140               
00141               if (strcmp(L_subSection->get_name(), XML_CHANNEL_SUBSECTION) == 0) {
00142 
00143                 L_entity_value = L_subSection->find_value(XML_CHANNEL_ENTITY) ;
00144                 if (L_entity_value != NULL) {
00145                   if (strcmp(L_entity_value, XML_CHANNEL_ENTITY_VALUE) == 0) {
00146 
00147                     L_name = L_subSection->find_value(XML_CHANNEL_NAME); 
00148                     if (L_name == NULL) {
00149                       GEN_ERROR(E_GEN_FATAL_ERROR, "[" 
00150                                 << L_name << "] value is mandatory for section ["
00151                                 << XML_CHANNEL_SECTION << "], sub section ["
00152                                 << XML_CHANNEL_SUBSECTION << "]");
00153                       L_ret = false ;
00154                       break ;
00155                     }
00156 
00157                     L_open_args = L_subSection->find_value(XML_CHANNEL_OPEN);
00158                     if (L_open_args == NULL) {
00159                       GEN_ERROR(E_GEN_FATAL_ERROR, "[" 
00160                                 << L_open_args << "] value is mandatory for section ["
00161                                 << XML_CHANNEL_SECTION << "], sub section ["
00162                                 << XML_CHANNEL_SUBSECTION << "]");
00163                       L_ret = false ;
00164                       break ;
00165                     }
00166                     L_protocol_name = L_subSection->find_value(XML_CHANNEL_PROTOCOL);
00167                     if (L_protocol_name == NULL) {
00168                       GEN_ERROR(E_GEN_FATAL_ERROR, "[" 
00169                                 << L_protocol_name << "] value is mandatory for section ["
00170                                 << XML_CHANNEL_SECTION << "], sub section ["
00171                                 << XML_CHANNEL_SUBSECTION << "]");
00172                       L_ret = false ;
00173                       break ;
00174                     }
00175 
00176                     L_reconnect = L_subSection->find_value(XML_CHANNEL_RECONNECT);
00177 
00178                     L_transport_name = L_subSection->find_value(XML_CHANNEL_TRANSPORT);
00179                     if (L_transport_name == NULL) {
00180                       GEN_ERROR(E_GEN_FATAL_ERROR, "[" 
00181                                 << L_transport_name << "] value is mandatory for section ["
00182                                 << XML_CHANNEL_SECTION << "], sub section ["
00183                                 << XML_CHANNEL_SUBSECTION << "]");
00184                       L_ret = false ;
00185                       break ;
00186                     }
00187                     if (L_subSection->find_value(XML_CHANNEL_GLOBAL) != NULL) {
00188                       if (strcmp(L_subSection->find_value(XML_CHANNEL_GLOBAL), XML_CHANNEL_GLOBAL_VALUE) == 0) {
00189                         L_channel_type = E_CHANNEL_GLOBAL ;
00190                       } else {
00191                         L_channel_type = E_CHANNEL_LOCAL ;
00192                       }
00193                     } else {
00194                       L_channel_type = E_CHANNEL_GLOBAL ;
00195                     }
00196 
00197                     // check channel name unicity
00198                     if (m_name_map->find(T_ChannelNameMap::key_type(L_name)) 
00199                         != m_name_map->end()) {
00200                       GEN_ERROR(E_GEN_FATAL_ERROR, 
00201                                 XML_CHANNEL_SECTION << " with name ["
00202                                 << L_name << "] already defined");
00203                       L_ret = false ;
00204                       break ;
00205                     }
00206 
00207                     // check transport and protocol definition
00208                     if (P_protocol_ctrl->get_protocol_id(L_protocol_name) 
00209                         == ERROR_PROTOCOL_UNKNOWN) {
00210                       GEN_ERROR(E_GEN_FATAL_ERROR, 
00211                                 "Protocol ["
00212                                 << L_protocol_name << "] unknown for channel ["
00213                                 << L_name << "]");
00214                       L_ret = false ;
00215                       break ;
00216                     }
00217                     if (P_transport_ctrl->get_transport_id(L_transport_name) 
00218                         == ERROR_TRANSPORT_UNKNOWN) {
00219                       GEN_ERROR(E_GEN_FATAL_ERROR, 
00220                                 "Transport ["
00221                                 << L_transport_name << "] unknown for channel ["
00222                                 << L_name << "]");
00223                       L_ret = false ;
00224                       break ;
00225                     }
00226                     
00227                     L_channel_id = m_id_gen->new_id() ;
00228                     ALLOC_VAR(L_channel_info,
00229                               T_pChannelInfo,
00230                               sizeof(T_ChannelInfo));
00231 
00232                     L_channel_info->m_id = L_channel_id ;
00233                     L_channel_info->m_open_args = L_open_args ;
00234                     L_channel_info->m_protocol_name = L_protocol_name ; 
00235                     L_channel_info->m_transport_name = L_transport_name ; 
00236                     L_channel_info->m_type = L_channel_type ;
00237                     L_channel_info->m_name = L_name ;
00238                     L_channel_info->m_reconnect = L_reconnect ;
00239                     L_channel_info_list.push_back(L_channel_info);
00240                     m_name_map
00241                       ->insert(T_TransportNameMap::value_type(L_name,
00242                                                               L_channel_id)) ;
00243                     
00244                   }
00245 
00246                 }
00247                 
00248               }
00249 
00250             }
00251 
00252           }
00253         }
00254       }
00255 
00256       if (L_ret != false) {
00257         if (!L_channel_info_list.empty()) {
00258           m_channel_table_size = L_channel_info_list.size () ;
00259           ALLOC_TABLE(m_channel_table,
00260                       T_pChannelData*,
00261                       sizeof(T_pChannelData),
00262                       m_channel_table_size);
00263           for (L_it  = L_channel_info_list.begin();
00264                L_it != L_channel_info_list.end()  ;
00265                L_it++) {
00266             L_channel_info = *L_it ;
00267             ALLOC_VAR(m_channel_table[L_channel_info->m_id], 
00268                       T_pChannelData, 
00269                       sizeof(T_ChannelData));
00270             L_data = m_channel_table[L_channel_info->m_id] ;
00271 
00272             L_data->m_id = L_channel_info->m_id ;
00273             L_data->m_type = L_channel_info->m_type ;
00274             L_data->m_protocol_id = P_protocol_ctrl->get_protocol_id(L_channel_info->m_protocol_name) ;
00275             L_data->m_transport_id = P_transport_ctrl->get_transport_id(L_channel_info->m_transport_name) ;
00276             L_data->m_protocol = P_protocol_ctrl->get_protocol(L_channel_info->m_protocol_name) ;
00277             L_data->m_transport = P_transport_ctrl->get_transport(L_channel_info->m_transport_name) ;
00278             L_data->m_open_args = L_channel_info->m_open_args ;
00279             L_data->m_open_status = E_CHANNEL_CLOSED ;
00280 
00281             L_data->m_reconnect = (L_channel_info->m_reconnect == NULL) ?
00282               false : (strcmp(L_channel_info->m_reconnect, "yes") == 0) ;
00283 
00284             if (L_data->m_reconnect == true) { m_reconnect = true ; }
00285 
00286             L_data->m_name = L_channel_info->m_name ;
00287 
00288             if (L_data->m_type == E_CHANNEL_GLOBAL) {
00289               m_nb_global_channel++ ;
00290             }
00291 
00292           }
00293         } else {
00294           GEN_ERROR(E_GEN_FATAL_ERROR,
00295                     "No channel definition found");
00296           L_ret = false ;
00297         }
00298       }
00299 
00300       if (!L_channel_info_list.empty()) {
00301         for (L_it  = L_channel_info_list.begin();
00302              L_it != L_channel_info_list.end()  ;
00303              L_it++) {
00304           if (L_ret == false) { // error
00305             if (m_channel_table_size > 0) {
00306               L_channel_info = *L_it ;
00307               FREE_VAR(m_channel_table[L_channel_info->m_id]);
00308             }
00309           }
00310           FREE_VAR(*L_it);
00311         }
00312         L_channel_info_list.erase(L_channel_info_list.begin(),
00313                                     L_channel_info_list.end());
00314       }
00315 
00316       if (L_ret == false) {
00317         // delete structures
00318         if (m_channel_table_size > 0) {
00319           FREE_TABLE(m_channel_table);
00320           m_channel_table_size = 0 ;
00321         }
00322       }
00323     }
00324   } else {
00325     GEN_ERROR(E_GEN_FATAL_ERROR,
00326               "No channel definition found");
00327     L_ret = false ;
00328   }
00329 
00330   if (L_ret == true) {
00331     create_context_channel () ;
00332     create_transport_table (P_transport_ctrl) ;
00333   }
00334 
00335   NEW_VAR(m_sem_reconnect, C_SemaphoreTimed(1));
00336   
00337   GEN_DEBUG(1, "C_ChannelControl::fromXml() end ret=" << L_ret);
00338   return (L_ret);
00339 }
00340 
00341 C_ChannelControl::T_pChannelData C_ChannelControl::get_channel_data (int P_id) {
00342   T_pChannelData L_ret = NULL ;
00343 
00344   if (P_id < m_channel_table_size) {
00345     L_ret = m_channel_table[P_id] ;
00346   }
00347 
00348   return (L_ret) ;
00349 }
00350 
00351 C_ChannelControl::T_pChannelData C_ChannelControl::get_channel_data (char *P_name) {
00352   T_pChannelData L_ret = NULL ;
00353   int            L_id         ;
00354 
00355   L_id = get_channel_id (P_name) ;
00356   if (L_id != ERROR_CHANNEL_UNKNOWN) {
00357     L_ret = m_channel_table[L_id] ;
00358   }
00359 
00360   return (L_ret) ;
00361 }
00362 
00363 int C_ChannelControl::get_channel_id (char *P_name) {
00364   int                         L_ret = ERROR_CHANNEL_UNKNOWN ;
00365   T_ChannelNameMap::iterator L_it ;
00366 
00367   L_it = m_name_map->find(T_ProtocolNameMap::key_type(P_name)) ;
00368   if (L_it != m_name_map->end()) {
00369     L_ret = L_it->second ;
00370   }
00371   return (L_ret) ;
00372 }
00373 
00374 
00375 char* C_ChannelControl::get_channel_name (int P_id) {
00376   return (m_channel_table[P_id]->m_name);
00377 }
00378 
00379 int C_ChannelControl::check_global_channel () {
00380   int            L_ret = 0 ;
00381   T_OpenStatus   L_status  ;
00382   int            L_i       ;
00383   T_pChannelData L_data    ;
00384 
00385   for(L_i=0; L_i < m_channel_table_size; L_i++) {
00386     L_data = m_channel_table[L_i] ;
00387 
00388     if (L_data->m_type == E_CHANNEL_GLOBAL) {
00389       if (L_data->m_open_status == E_CHANNEL_CLOSED) {
00390         if (L_data->m_reconnect == true) {
00391 
00392           // wait
00393           m_sem_reconnect->P();
00394           m_sem_reconnect->P();
00395 
00396           L_data->m_open_id
00397             = (L_data->m_transport)
00398             ->open(L_data->m_id,
00399                    L_data->m_open_args, 
00400                    &L_status,
00401                    L_data->m_protocol);
00402           GEN_DEBUG(0, "open channel [" << L_i << "] with [" 
00403                     << L_data->m_open_id << "]");
00404           
00405           switch (L_status) {
00406           case E_OPEN_OK:
00407             L_ret ++ ; 
00408             L_data->m_open_status = E_CHANNEL_OPENED ;
00409             break ;
00410           case E_OPEN_DELAYED:
00411             L_data->m_open_status = E_CHANNEL_OPEN_IN_PROGESS ;
00412             break ;
00413           default:
00414             break;
00415           }
00416         }
00417       } else {
00418         L_ret ++ ;
00419       }
00420     }
00421   }
00422   return (L_ret);
00423 }
00424 
00425 
00426 int C_ChannelControl::open_global_channel () {
00427 
00428   int            L_ret = 0 ;
00429   T_OpenStatus   L_status  ;
00430   int            L_i       ;
00431   T_pChannelData L_data    ;
00432 
00433   for(L_i=0; L_i < m_channel_table_size; L_i++) {
00434     L_data = m_channel_table[L_i] ;
00435     if ((L_data->m_open_status == E_CHANNEL_CLOSED)
00436         && (L_data->m_type == E_CHANNEL_GLOBAL)) {
00437       L_data->m_open_id
00438         = (L_data->m_transport)
00439         ->open(L_data->m_id,
00440                L_data->m_open_args, 
00441                &L_status,
00442                L_data->m_protocol);
00443       GEN_DEBUG(0, "open channel [" << L_i << "] with [" 
00444                 << L_data->m_open_id << "]");
00445 
00446       switch (L_status) {
00447       case E_OPEN_OK:
00448         L_ret ++ ; 
00449         L_data->m_open_status = E_CHANNEL_OPENED ;
00450         break ;
00451       case E_OPEN_DELAYED:
00452         //      L_ret ++ ; 
00453         L_data->m_open_status = E_CHANNEL_OPEN_IN_PROGESS ;
00454         break ;
00455       default:
00456         break;
00457       }
00458     }
00459   }
00460   return (L_ret);
00461 }
00462 
00463 
00464 int C_ChannelControl::open_local_channel (int P_id,
00465                                           char *P_args,
00466                                           int *P_table, 
00467                                           T_pOpenStatus P_status) {
00468   int            L_ret  = 0       ;
00469   T_pChannelData L_data           ;
00470 
00471   char          *L_args = NULL    ;
00472 
00473   if (P_id < m_channel_table_size) {
00474     L_data = m_channel_table [P_id] ;
00475 
00476     if ((L_data->m_open_status == E_CHANNEL_CLOSED)
00477         && (L_data->m_type == E_CHANNEL_LOCAL)) {
00478       if (P_args != NULL ) {
00479         L_args = P_args ;
00480       } else {
00481         L_args =  L_data->m_open_args ;
00482       }
00483       L_ret
00484         = (L_data->m_transport)
00485         ->open(L_data->m_id,
00486                L_args, 
00487                P_status,
00488                L_data->m_protocol);
00489       P_table[P_id] = L_ret ;
00490     }
00491   }
00492     
00493   return (L_ret);
00494 }
00495 
00496 void C_ChannelControl::create_context_channel() {
00497 
00498   int L_nb_local_channel, L_i, L_j ;
00499 
00500   L_nb_local_channel = m_channel_table_size - m_nb_global_channel ;
00501   if (L_nb_local_channel > 0) {
00502     ALLOC_TABLE(m_channel_to_ctxt_table,
00503                 int*,
00504                 sizeof(int),
00505                 m_channel_table_size);
00506     ALLOC_TABLE(m_ctxt_to_channel_table,
00507                 int*,
00508                 sizeof(int),
00509                 L_nb_local_channel);
00510     L_j = 0 ;
00511     for (L_i = 0; L_i < m_channel_table_size; L_i++) {
00512       if (m_channel_table[L_i]->m_type == E_CHANNEL_LOCAL) {
00513         m_ctxt_to_channel_table[L_j] = L_i ;
00514         m_channel_to_ctxt_table[L_i] = L_j ;
00515       } else {
00516         m_channel_to_ctxt_table[L_i] = -1 ;
00517       }
00518     }
00519   }
00520 }
00521 
00522 int C_ChannelControl::nb_channel () {
00523   return (m_channel_table_size) ;
00524 }
00525 
00526 int C_ChannelControl::nb_global_channel () {
00527   return (m_nb_global_channel) ;
00528 }
00529 
00530 int C_ChannelControl::open_id_from_channel_id (int P_id, int *P_table) {
00531   int L_ret = -1 ;
00532 
00533   if (P_id < m_channel_table_size) {
00534     if (m_channel_table[P_id]->m_type == E_CHANNEL_LOCAL) {
00535       L_ret = P_table[m_channel_to_ctxt_table[P_id]];
00536     } else {
00537       L_ret = m_channel_table[P_id]->m_open_id ;
00538     }
00539   }
00540   return (L_ret);
00541 }
00542 
00543 int C_ChannelControl::send_to_channel(int P_id, int *P_table, 
00544                                       C_MessageFrame *P_msg) {
00545   
00546   int          L_ret       ;
00547 
00548   if (P_table[P_id] == -1) {
00549     P_table[P_id] = m_channel_table[P_id]->m_open_id ;
00550   }
00551 
00552   L_ret = (m_channel_table[P_id]->m_transport)->send_message(P_table[P_id], 
00553                                                              P_msg);
00554   
00555   return (L_ret) ;
00556 }
00557 
00558 void C_ChannelControl::create_transport_table(C_TransportControl *P_transport_ctrl) {
00559   
00560   T_pIntSet          L_set ;
00561   T_IntSet::iterator L_it ;
00562   int                L_i, L_id ;
00563   
00564   NEW_VAR(L_set, T_IntSet());
00565 
00566   for(L_i = 0; L_i < m_channel_table_size; L_i++) {
00567     L_id = m_channel_table[L_i]->m_transport_id ;
00568     L_it = L_set->find(L_id) ;
00569     if (L_it == L_set->end()) { L_set->insert(L_id); }
00570   }
00571 
00572   if (!L_set->empty()) {
00573     m_nb_transport = L_set->size() ;
00574     ALLOC_TABLE(m_transport_table,
00575                 C_Transport**,
00576                 sizeof(C_Transport*),
00577                 m_nb_transport);
00578     L_i = 0 ;
00579     for(L_it=L_set->begin(); L_it != L_set->end() ; L_it++) {
00580       m_transport_table[L_i] 
00581         = P_transport_ctrl->get_transport(*L_it);
00582       L_i++;
00583     }
00584     L_set->erase(L_set->begin(), L_set->end());
00585   }
00586   DELETE_VAR(L_set);
00587 }
00588 
00589 C_Transport** C_ChannelControl::get_transport_table (int *P_size) {
00590   *P_size = m_nb_transport ;
00591   return (m_transport_table);
00592 }
00593 
00594 C_ProtocolFrame* C_ChannelControl::get_channel_protocol (int P_id) {
00595   C_ProtocolFrame *L_ret = NULL ;
00596   if (P_id < m_channel_table_size) {
00597     L_ret = m_channel_table[P_id]->m_protocol ;
00598   }
00599   return (L_ret) ;
00600 }
00601 
00602 void C_ChannelControl::close_local_channel (int P_id, int *P_table) {
00603 
00604   int            L_id ;
00605 
00606   if (m_channel_table[P_id]->m_type == E_CHANNEL_LOCAL) {
00607 
00608     L_id = P_table[P_id] ;
00609     if (L_id != -1) {
00610       (m_channel_table[P_id]->m_transport)->close(L_id);
00611     }
00612   }
00613 
00614 }
00615 
00616 
00617 void C_ChannelControl::reset_channel(int *P_table) {
00618 
00619   int L_i ;
00620 
00621   for (L_i=0; L_i < m_channel_table_size; L_i++) {
00622     P_table[L_i] = -1 ;
00623   }
00624   
00625 }
00626 
00627 void C_ChannelControl::opened(int P_id, int P_open_id) {
00628   if (m_channel_table[P_id]->m_open_id == P_open_id) {
00629     m_channel_table[P_id]->m_open_status 
00630       = E_CHANNEL_OPENED ;
00631   }
00632 }
00633 
00634 void C_ChannelControl::open_failed(int P_id, int P_open_id) {
00635   T_pChannelData L_data = m_channel_table[P_id] ;
00636 
00637   if (L_data) {
00638     if (L_data->m_open_id == P_open_id) {
00639       L_data->m_open_status 
00640         = E_CHANNEL_CLOSED ;
00641       (L_data->m_transport)
00642         ->close (L_data->m_open_id) ;
00643       GEN_ERROR(E_GEN_FATAL_ERROR, "Open channel failed");
00644     }
00645   }
00646 }
00647 
00648 void C_ChannelControl::closed(int P_id, int P_open_id) {
00649 
00650   T_pChannelData L_data = m_channel_table[P_id] ;
00651 
00652   if (L_data) {
00653     if (L_data->m_open_id == P_open_id) {
00654       L_data->m_open_status = E_CHANNEL_CLOSED ;
00655       (L_data->m_transport)
00656         ->close (L_data->m_open_id) ;
00657     }
00658   }
00659 }
00660 
00661 int C_ChannelControl::opened () {
00662 
00663   int            L_nb = 0 ;
00664   int            L_i       ;
00665   T_pChannelData L_data    ;
00666 
00667   for(L_i=0; L_i < m_channel_table_size; L_i++) {
00668     L_data = m_channel_table[L_i] ;
00669     if ((L_data->m_open_status == E_CHANNEL_OPENED)
00670         && (L_data->m_type == E_CHANNEL_GLOBAL)) {
00671       L_nb ++ ;
00672     }
00673   }
00674   return (L_nb);
00675 }
00676 
00677 
00678 int C_ChannelControl::set_option_global_channel (int P_id,
00679                                                  char *P_args,
00680                                                  int *P_table) {
00681   int            L_ret  = 0       ;
00682   T_pChannelData L_data           ;
00683 
00684 
00685   if (P_id < m_channel_table_size) {
00686     L_data = m_channel_table [P_id] ;
00687 
00688     // global channel
00689     L_ret = (L_data->m_transport)
00690       ->set_option(P_table[P_id],
00691                    P_args);
00692 
00693   }
00694     
00695   return (L_ret);
00696 }
00697 
00698 //  int C_ChannelControl::set_option_global_channel (int P_Channel_Id, char *P_buf) {
00699 //    int L_ret = 0 ;
00700 //    // global channel
00701 //    L_ret = (m_channel_table[P_Channel_Id]->m_transport)
00702 //      ->set_option(m_channel_table[P_Channel_Id]->m_open_id, 
00703 //                   P_buf);
00704   
00705 //    return (L_ret);
00706 //  }

Generated on Wed Mar 7 14:44:49 2007 for Seagull by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002