メインページ   モジュール   名前空間一覧   クラス階層   アルファベット順一覧   構成   ファイル一覧   構成メンバ   ファイルメンバ   関連ページ    

TOutputObjectSocket.cc

解説を見る。
00001 // =====================================================================
00002 //  $Id: TOutputObjectSocket.cc,v 1.5 2004/03/07 10:30:32 goiwai Exp $
00003 //  $Name: CLDAQ-1-14-03 $
00004 //  $Log: TOutputObjectSocket.cc,v $
00005 //  Revision 1.5  2004/03/07 10:30:32  goiwai
00006 //  ROOTに組みこむためのおまじないマクロを埋めこみました。
00007 //  全てにおいて完全に動作するわけではありません。
00008 //
00009 //  Revision 1.4  2003/12/06 10:56:19  goiwai
00010 //  フィルタ関連の修整と Read(),Write()の戻り値の修整です.
00011 //  Read()もWrite()も処理したレコードサイズを返します.
00012 //  フィルタがある場合も同様です.
00013 //  それぞれのストリームのDataSizeの扱いですが,これは扱ったレコードサイズ
00014 //  でなく扱ったファイルやソケットなどのサイズになります.レコードサイズと
00015 //  一致するとは限りません.
00016 //
00017 //  Revision 1.3  2003/10/06 17:02:42  goiwai
00018 //  *** empty log message ***
00019 //
00020 //  Revision 1.2  2003/07/30 16:19:31  goiwai
00021 //  ファイルにコミットログをつけることにしました.
00022 //
00023 // =====================================================================
00024 #include "TOutputObjectSocket.hh"
00025 #include "TStreamableObject.hh"
00026 #include "TOutputObjectFilter.hh"
00027 
00028 TOutputObjectSocket::TOutputObjectSocket( const Tstring& hostname, Tint port )
00029   : TObjectSocket( port ), TOutputObjectStream( tSocketStream ), 
00030     theServerName( hostname ), theHostInformation( 0 )
00031 {
00032   initialize();
00033 }
00034 
00035 TOutputObjectSocket::TOutputObjectSocket( Tint port )
00036   : TObjectSocket( port ), TOutputObjectStream( tSocketStream ), 
00037     theServerName( "localhost" ), theHostInformation( 0 )
00038 {
00039   initialize();
00040 }
00041 
00042 TOutputObjectSocket::TOutputObjectSocket( TOutputObjectFilter* filter, const Tstring& hostname, Tint port )
00043   : TObjectSocket( port ), TOutputObjectStream( filter, tSocketStream ), 
00044     theServerName( hostname ), theHostInformation( 0 )
00045 {
00046   initialize();
00047 }
00048 
00049 TOutputObjectSocket::TOutputObjectSocket( TOutputObjectFilter* filter, Tint port )
00050   : TObjectSocket( port ), TOutputObjectStream( filter, tSocketStream ), 
00051     theServerName( "localhost" ), theHostInformation( 0 )
00052 {
00053   initialize();
00054 }
00055 
00056 TOutputObjectSocket::~TOutputObjectSocket()
00057 {
00058   CloseServer();
00059 }
00060 
00061 Tvoid TOutputObjectSocket::initialize()
00062 {
00063   theHostInformation = gethostbyname( theServerName.c_str() );
00064   if ( theHostInformation == 0 ) {
00065     perror( "TOutputObjectSocket::initialize" );
00066     exit( -errno );
00067   }
00068   theAddress.sin_family = PF_INET;
00069   theAddress.sin_port = htons( (TUshort)thePortNumber );
00070   theAddress.sin_addr.s_addr =
00071     *( (unsigned long *)( *( theHostInformation -> h_addr_list ) ) );
00072 
00073   OpenServer();
00074   Tsocklen_t len = (Tsocklen_t)( Tsizeof( theAddress ) );
00075 
00076   if ( connect( theServerDescriptor, (struct sockaddr *)&theAddress, len ) == -1 )
00077     perror( "TOutputObjectSocket::initialize" );
00078 
00079 
00080   return;
00081 }
00082 
00083 Tint TOutputObjectSocket::Write( TStreamableObject& object )
00084 {
00085   if ( HasFilter() ) {
00086     return theObjectFilter -> Filtering( object, this );
00087   }
00088 
00089   theLastDataSize = theDataSize;
00090   theDataSize = 0;
00091   theDataSize = object.Record( this );
00092   theTotalDataSize += theDataSize;
00093 
00094   return theDataSize;
00095 }
00096 
00097 #ifdef __CLDAQ_ROOT_DLL
00098     ClassImp(TOutputObjectSocket)
00099 #endif


CLDAQ - a Class Library for DataAcQuisition (Version 1.14.3)
Go IWAI -- goiwai at users.sourceforge.jp