示例#1
0
文件: wopi.cpp 项目: Klaim/falcon
void Wopi::inner_readData( SharedMem* shmem, Item& data )
{
   StringStream target;
   shmem->read( &target, true );

   if ( target.tell() == 0 )
   {
      // nothing to be deserialized.
      data.setNil();
      return;
   }

   target.seekBegin(0);
   Item::e_sercode sc = data.deserialize( &target, VMachine::getCurrent() );
   if( sc != Item::sc_ok )
   {
      throw new WopiError( ErrorParam( FALCON_ERROR_WOPI_APPDATA_DESER, __LINE__ )
            .desc( "Error during de-serialization of application data")
            .extra( String("type ").N( (int) sc ) )
            );
   }
}
示例#2
0
文件: wopi.cpp 项目: Klaim/falcon
bool Wopi::setData( Item& data, const String& appName, bool atomicUpdate )
{
   SharedMem* pAppMem = 0;

   // do we have the required appname data?
   m_mtx.lock();
   AppDataMap::const_iterator pos = m_admap.find( appName );
   if( pos == m_admap.end() )
   {
      m_mtx.unlock();
      pAppMem = inner_create_appData( appName );
   }
   else
   {

      pAppMem = pos->second;
      m_mtx.unlock();
   }

   // we can deal with the shared memory in an unlocked region, of course.
   if ( pAppMem->currentVersion() != pAppMem->lastVersion() )
   {
      // we already know we're out of sync.
      if( atomicUpdate )
         inner_readData( pAppMem, data );

      return false;
   }

   // ok, try and serialize the data.
   StringStream source;
   Item::e_sercode sc = data.serialize( &source, false );
   if( sc != Item::sc_ok )
   {
      throw new WopiError( ErrorParam( FALCON_ERROR_WOPI_APPDATA_SER, __LINE__ )
                  .desc( "Error during Serialization of application data")
                  .extra( String("type ").N( (int) sc ) )
                  );
   }

   // great, the data is serialized; try to get it out of the door.
   int32 datalen = (int32) source.tell();
   source.seekBegin(0);
   bool bSuccess = pAppMem->commit( &source, datalen, atomicUpdate );

   // did we succeed?
   if( ! bSuccess )
   {
      // No; we wasted the serialization. However, are now required to
      // deserialize the item?
      if( atomicUpdate )
      {
         // ... and, is there anything to be de-serialized?
         if( source.tell() != 0 )
         {
            source.seekBegin(0);
            Item::e_sercode sc = data.deserialize( &source, VMachine::getCurrent() );
            if( sc != Item::sc_ok )
            {
               throw new WopiError( ErrorParam( FALCON_ERROR_WOPI_APPDATA_DESER, __LINE__ )
                     .desc( "Error during de-serialization of application data")
                     .extra( String("type ").N( (int) sc ) )
                     );
            }
         }
         else
         {
            data.setNil();
         }
      }
   }

   return bSuccess;
}