本文整理汇总了C++中msg_ptr::is方法的典型用法代码示例。如果您正苦于以下问题:C++ msg_ptr::is方法的具体用法?C++ msg_ptr::is怎么用?C++ msg_ptr::is使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类msg_ptr
的用法示例。
在下文中一共展示了msg_ptr::is方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
void
ControlConnection::handleMsg( msg_ptr msg )
{
if ( msg->is( Msg::PING ) )
{
// qDebug() << "Received Connection PING, nice." << m_pingtimer_mark.elapsed();
m_pingtimer_mark.restart();
return;
}
// if small and not compresed, print it out for debug
if ( msg->length() < 1024 && !msg->is( Msg::COMPRESSED ) )
{
qDebug() << id() << "got msg:" << QString::fromLatin1( msg->payload() );
}
// All control connection msgs are JSON
if ( !msg->is( Msg::JSON ) )
{
Q_ASSERT( msg->is( Msg::JSON ) );
markAsFailed();
return;
}
QVariantMap m = msg->json().toMap();
if ( !m.isEmpty() )
{
if ( m.value( "conntype" ).toString() == "request-offer" )
{
QString theirkey = m["key"].toString();
QString ourkey = m["offer"].toString();
QString theirdbid = m["controlid"].toString();
servent()->reverseOfferRequest( this, theirdbid, ourkey, theirkey );
}
else if ( m.value( "method" ).toString() == "dbsync-offer" )
{
m_dbconnkey = m.value( "key" ).toString() ;
setupDbSyncConnection();
}
else if ( m.value( "method" ) == "protovercheckfail" )
{
qDebug() << "*** Remote peer protocol version mismatch, connection closed";
shutdown( true );
return;
}
else
{
tDebug() << id() << "Unhandled msg:" << QString::fromLatin1( msg->payload() );
}
return;
}
tDebug() << id() << "Invalid msg:" << QString::fromLatin1( msg->payload() );
}
示例2: changeState
void
DBSyncConnection::handleMsg( msg_ptr msg )
{
Q_ASSERT( !msg->is( Msg::COMPRESSED ) );
if ( m_state == FETCHING )
changeState( PARSING );
// "everything is synced" indicated by non-json msg containing "ok":
if ( !msg->is( Msg::JSON ) &&
msg->is( Msg::DBOP ) &&
msg->payload() == "ok" )
{
changeState( SYNCED );
// calc the collection stats, to updates the "X tracks" in the sidebar etc
// this is done automatically if you run a dbcmd to add files.
DatabaseCommand_CollectionStats* cmd = new DatabaseCommand_CollectionStats( m_source );
connect( cmd, SIGNAL( done( const QVariantMap & ) ),
m_source.data(), SLOT( setStats( const QVariantMap& ) ), Qt::QueuedConnection );
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>(cmd) );
return;
}
示例3: qDebug
/// This method is run by QtConcurrent:
msg_ptr
MsgProcessor::process( msg_ptr msg, quint32 mode, quint32 threshold )
{
// uncompress if needed
if( (mode & UNCOMPRESS_ALL) && msg->is( Msg::COMPRESSED ) )
{
qDebug() << "MsgProcessor::UNCOMPRESSING";
msg->m_payload = qUncompress( msg->payload() );
msg->m_length = msg->m_payload.length();
msg->m_flags ^= Msg::COMPRESSED;
}
// parse json payload into qvariant if needed
if( (mode & PARSE_JSON) &&
msg->is( Msg::JSON ) &&
msg->m_json_parsed == false )
{
qDebug() << "MsgProcessor::PARSING JSON";
bool ok;
QJson::Parser parser;
msg->m_json = parser.parse( msg->payload(), &ok );
msg->m_json_parsed = true;
}
// compress if needed
if( (mode & COMPRESS_IF_LARGE) &&
!msg->is( Msg::COMPRESSED )
&& msg->length() > threshold )
{
qDebug() << "MsgProcessor::COMPRESSING";
msg->m_payload = qCompress( msg->payload(), 9 );
msg->m_length = msg->m_payload.length();
msg->m_flags |= Msg::COMPRESSED;
}
return msg;
}
示例4: if
void
StreamConnection::handleMsg( msg_ptr msg )
{
Q_ASSERT( msg->is( Msg::RAW ) );
if ( msg->payload().startsWith( "block" ) )
{
int block = QString( msg->payload() ).mid( 5 ).toInt();
m_readdev->seek( block * BufferIODevice::blockSize() );
qDebug() << "Seeked to block:" << block;
QByteArray sm;
sm.append( QString( "doneblock%1" ).arg( block ) );
sendMsg( Msg::factory( sm, Msg::RAW | Msg::FRAGMENT ) );
QTimer::singleShot( 0, this, SLOT( sendSome() ) );
}
else if ( msg->payload().startsWith( "doneblock" ) )
{
int block = QString( msg->payload() ).mid( 9 ).toInt();
( (BufferIODevice*)m_iodev.data() )->seeked( block );
m_curBlock = block;
qDebug() << "Next block is now:" << block;
}
else if ( msg->payload().startsWith( "data" ) )
{
m_badded += msg->payload().length() - 4;
( (BufferIODevice*)m_iodev.data() )->addData( m_curBlock++, msg->payload().mid( 4 ) );
}
//qDebug() << Q_FUNC_INFO << "flags" << (int) msg->flags()
// << "payload len" << msg->payload().length()
// << "written to device so far: " << m_badded;
if ( m_iodev && ( (BufferIODevice*)m_iodev.data() )->nextEmptyBlock() < 0 )
{
m_allok = true;
// tell our iodev there is no more data to read, no args meaning a success:
( (BufferIODevice*)m_iodev.data() )->inputComplete();
shutdown();
}
}