Skip to content

Commit

Permalink
cin test
Browse files Browse the repository at this point in the history
  • Loading branch information
maloel committed Jan 2, 2025
1 parent a6f90a6 commit 7e00676
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion tools/dds/dds-adapter/rs-dds-adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,36 @@ static json load_settings( json const & local_settings )
}


static char const * delim( bool & first )
{
if( ! first )
return " ";
first = false;
return "";
};


struct stream_bits
{
std::istream & is;
stream_bits( std::istream & _ ) : is( _ ) {}
};

std::ostream & operator<<( std::ostream & os, stream_bits const & sb )
{
bool first = true;
if( sb.is.bad() )
os << delim( first ) << "BAD";
if( sb.is.good() )
os << delim( first ) << "good";
if( sb.is.fail() )
os << delim( first ) << "FAIL";
if( sb.is.eof() )
os << delim( first ) << "EOF";
return os;
};


int main( int argc, char * argv[] )
try
{
Expand Down Expand Up @@ -195,7 +225,16 @@ try
device_handlers_list.erase( dev );
} );

std::cin.ignore(std::numeric_limits<std::streamsize>::max(), 0);// Pend until CTRL + C is pressed

std::cout << "CIN was " << stream_bits( std::cin ) << std::endl;
std::cin.clear(); // unset good/bad/fail/eof bits
std::cin.ignore( std::numeric_limits< std::streamsize >::max(), 0 ); // Pend until CTRL + C is pressed
std::cout << "CIN is " << stream_bits( std::cin ) << std::endl;
if( ! std::cin.good() )
{
std::cout << "Sleeping for 2 minutes" << std::endl;
std::this_thread::sleep_for( std::chrono::seconds( 120 ) );
}

std::cout << "Shutting down rs-dds-adapter..." << std::endl;

Expand Down

0 comments on commit 7e00676

Please sign in to comment.