[ace-users] Trying to adding an ACE_TTY_IO handler to the reactor.
Kim J. Schmock
KJS at capres.com
Fri Jun 15 02:56:52 CDT 2007
ACE VERSION: 5.5.7
HOST MACHINE and OPERATING SYSTEM:
I386 Win XP
TARGET MACHINE and OPERATING SYSTEM, if different from HOST:
COMPILER NAME AND VERSION (AND PATCHLEVEL):
THE $ACE_ROOT/ace/config.h FILE [if you use a link to a platform-
specific file, simply state which one]: ace/config-win32.h"
THE $ACE_ROOT/include/makeinclude/platform_macros.GNU FILE [if you
use a link to a platform-specific file, simply state which one
(unless this isn't used in this case, e.g., with Microsoft Visual
C++)]:
CONTENTS OF $ACE_ROOT/bin/MakeProjectCreator/config/default.features
(used by MPC when you generate your own makefiles):
AREA/CLASS/EXAMPLE AFFECTED:
I used "Logger_Simple_Server" as base.
SYNOPSIS:
Trying to add a handler for ACE_TTY_IO to add with the reactor, but it
fail when I try to register the handler for the serial device.
DESCRIPTION:
This is my first trial using ACE.
My RS232 handler class
class Rs232Handler : public ACE_Event_Handler
{
public:
Rs232Handler() ;
int open( char * ) ;
private:
virtual int handle_input( ACE_HANDLE ) ;
//virtual int handle_close( ACE_HANDLE, ACE_Reactor_Mask ) ;
virtual ACE_HANDLE get_handle( void ) const ;
~Rs232Handler() ;
ACE_TTY_IO *ser_dev_ ;
ACE_DEV_Connector *con_ ;
ACE_TTY_IO::Serial_Params dev_params ;
} ;
Rs232Handler::Rs232Handler()
{
ser_dev_ = 0 ;
con_ = 0 ;
}
Rs232Handler::~Rs232Handler()
{
if( ser_dev_)
delete ser_dev_ ;
if( con_ )
delete con_ ;
}
int Rs232Handler::open( char *dev )
{
ACE_NEW_RETURN( ser_dev_, ACE_TTY_IO, 1 ) ;
ACE_NEW_RETURN( con_, ACE_DEV_Connector, 1 ) ;
if( con_->connect( (*ser_dev_), ACE_DEV_Addr(dev) ) == -1 )
return -1 ;
dev_params.baudrate = 19200 ;
dev_params.xonlim = 0 ;
dev_params.xofflim = 0 ;
dev_params.readmincharacters = 0 ;
dev_params.readtimeoutmsec = 0 ; // 0 sec
dev_params.paritymode = "EVEN" ;
dev_params.ctsenb = false ;
dev_params.rtsenb = 0 ;
dev_params.xinenb = false ;
dev_params.xoutenb = false ;
dev_params.modem = false ;
dev_params.rcvenb = true ;
dev_params.dsrenb = false ;
dev_params.dtrdisable = false ;
dev_params.databits = 8 ;
dev_params.stopbits = 1 ;
if( ser_dev_->control(ACE_TTY_IO::SETPARAMS, &dev_params) == -1 )
return -1 ;
}
int Rs232Handler::handle_input( ACE_HANDLE )
{
char readback ;
ssize_t bytes_read = ser_dev_->recv( (void*) &readback, 1 ) ;
int read_count = 0 ;
while( bytes_read == 1 )
{
ACE_DEBUG( ( LM_DEBUG, ACE_TEXT( "read: %c\n" ),readback ) ) ;
read_count++ ;
bytes_read = ser_dev_->recv( (void*) &readback, 1 ) ;
}
if( read_count > 0 )
return -1 ;
else
return 0 ;
}
ACE_HANDLE Rs232Handler::get_handle( void ) const
{
return this->ser_dev_->get_handle() ;
}
The code from ACE_TMAIN()
:
:
// do the network preparation.
if (peer_acceptor->open (addr) == -1)
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("%p\n"),
ACE_TEXT ("open net")),
-1);
else if (REACTOR::instance ()->register_handler
(peer_acceptor,
ACE_Event_Handler::ACCEPT_MASK) == -1)
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("registering net service with
ACE_Reactor\n")),
-1);
// do the PS232 preparation.
Rs232Handler *ser_handler ;
ACE_NEW_RETURN( ser_handler, Rs232Handler, 1 ) ;
if( ser_handler->open( "\\\\.\\COM1" ) == -1 )
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("%p\n"),
ACE_TEXT ("open ser")),
-1);
else if (REACTOR::instance ()->register_handler
(ser_handler,
ACE_Event_Handler::READ_MASK) == -1) //<<<<<<<<< ----- Fails
here
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("registering ser service with
ACE_Reactor\n")),
-1);
// Run forever, performing the logging service.
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("(%P|%t) starting up server logging daemon\n")));
while (!finished)
REACTOR::instance ()->handle_events ();
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("(%P|%t) shutting down server logging
daemon\n")));
return 0;
}
REPEAT BY:
SAMPLE FIX/WORKAROUND:
?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://list.isis.vanderbilt.edu/pipermail/ace-users/attachments/20070615/b080a852/attachment-0001.htm
More information about the Ace-users
mailing list