bool KeystoreClientImpl::oneShotOperation(KeyPurpose purpose, const std::string& key_name,
                                          const AuthorizationSet& input_parameters,
                                          const std::string& input_data,
                                          const std::string& signature_to_verify,
                                          AuthorizationSet* output_parameters,
                                          std::string* output_data) {
    uint64_t handle;
    auto result =
        beginOperation(purpose, key_name, input_parameters, output_parameters, &handle);
    if (!result.isOk()) {
        ALOGE("BeginOperation failed: %d", int32_t(result));
        return false;
    }
    AuthorizationSet empty_params;
    size_t num_input_bytes_consumed;
    AuthorizationSet ignored_params;
    result = updateOperation(handle, empty_params, input_data, &num_input_bytes_consumed,
                             &ignored_params, output_data);
    if (!result.isOk()) {
        ALOGE("UpdateOperation failed: %d", int32_t(result));
        return false;
    }
    result =
        finishOperation(handle, empty_params, signature_to_verify, &ignored_params, output_data);
    if (!result.isOk()) {
        ALOGE("FinishOperation failed: %d", int32_t(result));
        return false;
    }
    return true;
}
Esempio n. 2
0
void WalkHotSpot::innerUpdate (float dt) {
	if (ScummGame::getInstance().getStatus() != ScummStatusPlay)
		return;
	
	// get player position

	auto node = App::getCurrentscene()->getChild(0);
	glm::vec2 pos (node->getPosition());
	IsInside test;
	glm::mat4 wt = getWorldTransform();
	bool insideNow =test.Run (m_shape.get(), wt, pos);
	if (m_isIn != insideNow) {
		if (insideNow) {
			auto s = m_master->Play ("walkin");
			if (s.isOk())
				s.Run (nullptr);
		}
		else {
			auto s = m_master->Play ("walkout");
			if (s.isOk())
				s.Run (nullptr);

		}
	}
	m_isIn = insideNow;
}
Esempio n. 3
0
XmlParseNode XmlParseNode::getChild(const std::string &nodeName) const
{
	if (!isOk())
		return XmlParseNode(m_doc, nullptr);
	const TiXmlElement * temp_curNode = m_curNode->FirstChildElement(nodeName);
	return XmlParseNode(m_doc, temp_curNode);
}
Esempio n. 4
0
XmlParseNode XmlParseNode::operator ++()
{
	if (!isOk())
		return XmlParseNode(m_doc, nullptr);
	m_curNode = m_curNode->NextSiblingElement(m_curNode->Value());
	return *this;
}
Esempio n. 5
0
vector<shared_ptr<SphereClumpGeom>> SphereClumpGeom::fromSpherePack(const shared_ptr<SpherePack>& sp, int div){
	std::map<int,std::list<int>> cIx; // map clump to all its spheres
	size_t N=sp->pack.size();
	int noClump=-1;
	for(size_t i=0; i<N; i++){
		if(sp->pack[i].clumpId<0) cIx[noClump--].push_back(i); // standalone spheres, get negative "ids"
		else cIx[sp->pack[i].clumpId].push_back(i);
	}
	vector<shared_ptr<SphereClumpGeom>> ret;
	ret.reserve(cIx.size());
	// store iterators in flat array so that the loop can be parallelized
	vector<std::map<int,std::list<int>>::iterator> cIxIter; cIxIter.reserve(cIx.size());
	for(std::map<int,std::list<int>>::iterator I=cIx.begin(); I!=cIx.end(); ++I) cIxIter.push_back(I);
	#ifdef WOO_OPENMP
		#pragma omp parallel for schedule(guided)
	#endif
	for(size_t i=0; i<cIxIter.size(); i++){
		const auto& ci(*cIxIter[i]);
		auto cg=make_shared<SphereClumpGeom>();
		cg->div=div;
		cg->centers.clear(); cg->centers.reserve(ci.second.size());
		cg->radii.clear();   cg->radii.reserve(ci.second.size());
		for(const int& i: ci.second){
			cg->centers.push_back(sp->pack[i].c);
			cg->radii.push_back(sp->pack[i].r);
		}
		assert(cg->centers.size()==ci.second.size()); assert(cg->radii.size()==ci.second.size());
		cg->recompute(div);
		assert(cg->isOk());
		ret.push_back(cg);
	}
	return ret;
}
//--------------------------------------------------------------------
//
//--------------------------------------------------------------------
void DSFilterSourceStreamAudio::done()
{
    if (isOk())
    {
        mInit = false;
    }
}
Esempio n. 7
0
Result<bool, nsresult> FrameParser::VBRHeader::ParseVBRI(
    BufferReader* aReader) {
  static const uint32_t TAG = BigEndian::readUint32("VBRI");
  static const uint32_t OFFSET = 32 + FrameParser::FrameHeader::SIZE;
  static const uint32_t FRAME_COUNT_OFFSET = OFFSET + 14;
  static const uint32_t MIN_FRAME_SIZE = OFFSET + 26;

  MOZ_ASSERT(aReader);
  // ParseVBRI assumes that the ByteReader offset points to the beginning of a
  // frame, therefore as a simple check, we look for the presence of a frame
  // sync at that position.
  auto sync = aReader->PeekU16();
  if (sync.isOk()) {  // To avoid compiler complains 'set but unused'.
    MOZ_ASSERT((sync.unwrap() & 0xFFE0) == 0xFFE0);
  }

  // Seek backward to the original position before leaving this scope.
  const size_t prevReaderOffset = aReader->Offset();
  auto scopeExit = MakeScopeExit([&] { aReader->Seek(prevReaderOffset); });

  // VBRI have a fixed relative position, so let's check for it there.
  if (aReader->Remaining() > MIN_FRAME_SIZE) {
    aReader->Seek(prevReaderOffset + OFFSET);
    uint32_t tag, frames;
    MOZ_TRY_VAR(tag, aReader->ReadU32());
    if (tag == TAG) {
      aReader->Seek(prevReaderOffset + FRAME_COUNT_OFFSET);
      MOZ_TRY_VAR(frames, aReader->ReadU32());
      mNumAudioFrames = Some(frames);
      mType = VBRI;
      return true;
    }
  }
  return false;
}
void FileSystemDevice::FileState::complete_readbuf(PacketHeader *packet_)
 {
  Packet<uint8,Sys::AsyncFile::ReadBufExt,ReadExt> packet=packet_;

  auto ext=packet.getExt();
  auto ext2=packet.getDeepExt<1>();

  if( ext->isOk() )
    {
     if( ext->off==ext2->off )
       {
        if( ext->data.len==ext2->len )
          {
           ext2->setData(ext->data.ptr);
          }
        else
          {
           ext2->setError(FileError_ReadLenMismatch);
          }
       }
     else
       {
        ext2->setError(FileError_BadPosition);
       }
    }
  else
    {
     ext2->setError(MakeError(ext,FileError_ReadFault));
    }

  packet.popExt().complete();
 }
int Block::Rotate(){
    int DstNum = type*4 + (number+1)%4;                    //DstNum:变形后的方块的标识号(number)
    int k = 0,i,j;
    for( i=0; i<4; i++){
        for( j=0; j<4; j++){
            if( b[DstNum][i][j] ){
                xy[k][0] = i;
                xy[k][1] = j;
                k++;
            }
        }
    }
    if( isOk() ){
        number = DstNum;                   //type不用变
    }else{                              //若无法旋转,则恢复xy[][]
        k = 0;
        for( i=0; i<4; i++){
            for( j=0; j<4; j++){
                if( b[number][i][j] ){
                    xy[k][0] = i;
                    xy[k][1] = j;
                    k++;
                }
            }
        }
        return -1;
    }
//    DrawCube();
    return 0;
}
int Block::MoveRight(){
    x += 1;
    if( !isOk() ){
        x -= 1;
    }
    return 0;
}
int AIBlock::MoveLeft(){
    x -= 1;
    if( !isOk() ){
        x += 1;
    }
    return 0;
}
Esempio n. 12
0
int sudokuHelper(int puzzle[][9], int row, int column) 
{
	if (9 == row) { return 1; }

	if (puzzle[row][column]) 
	{
		if (column == 8) 
		{
			if (sudokuHelper(puzzle, row+1, 0)) return 1;
		} 
		else 
		{
			if (sudokuHelper(puzzle, row, column+1)) return 1;
		}
		return 0;
	}

	for (int nextNumber=1; nextNumber<10; nextNumber++) 
	{
		if(isOk(nextNumber, row, column)) 
		{
			puzzle[row][column] = nextNumber;
			if (column == 8) 
			{
				if (sudokuHelper(puzzle, row+1, 0)) return 1;
			}
			else 
			{
				if (sudokuHelper(puzzle, row, column+1)) return 1;
			}
			puzzle[row][column] = 0;
		}
	}
	return 0;
}
Esempio n. 13
0
//********************************************************************
//
//********************************************************************
//--------------------------------------------------------------------
//
//--------------------------------------------------------------------
bool GraphSourceRandom::init(const InitData& _data)
{
    bool bOK = true;

    if (!isOk())
    {
        bOK = Inherited::init();

        mStreamAudio = 0;
        mStreamVideo = 0;
        mTimeAudio = 0;
        mTimeVideo = 0;
        mData = _data;
        mMultiTask = 0;

        if ( bOK )
            bOK = createStreams();

        if ( bOK )
        {
            mMultiTask = NEW MultiTask();
            bOK = mMultiTask->init(2,this);
        }
    }
    return bOK;
}
Esempio n. 14
0
int getMinTime() {
  int low = 0;
  int high = 1000000000;
  while (low + 1 < high) {
    int mid = (low + high) / 2;
    if (isOk(mid)) {
      high = mid;
    } else {
      low = mid;
    }
  }
  if (isOk(low)) {
    return low;
  }
  return high;
}
Esempio n. 15
0
void GnssAPIClient::onStopTrackingCb(LocationError error)
{
    LOC_LOGD("%s]: (%d)", __FUNCTION__, error);
    if (error == LOCATION_ERROR_SUCCESS && mGnssCbIface != nullptr) {
        auto r = mGnssCbIface->gnssStatusCb(IGnssCallback::GnssStatusValue::SESSION_END);
        if (!r.isOk()) {
            LOC_LOGE("%s] Error from gnssStatusCb SESSION_END description=%s",
                __func__, r.description().c_str());
        }
        r = mGnssCbIface->gnssStatusCb(IGnssCallback::GnssStatusValue::ENGINE_OFF);
        if (!r.isOk()) {
            LOC_LOGE("%s] Error from gnssStatusCb ENGINE_OFF description=%s",
                __func__, r.description().c_str());
        }
    }
}
Esempio n. 16
0
//--------------------------------------------------------------------
//
//--------------------------------------------------------------------
void NWStreamReader::done()
{
    if (isOk())
    {
        mInit = false;
    }
}
Esempio n. 17
0
// Constructor
OsDatagramSocket::OsDatagramSocket(int remoteHostPortNum, const char* remoteHost,
                                   int localHostPortNum, const char* localHost)
: mNumTotalWriteErrors(0)
, mNumRecentWriteErrors(0)
, mSimulatedConnect(FALSE)     // Simulated connection is off until
                               // activated in doConnect.
{
    int error = ctorCommonCode();
    if (error != 0)
    {
        OsSysLog::add(FAC_KERNEL, PRI_DEBUG,
                      "OsDatagramSocket::OsDatagramSocket( %s:%d %s:%d) failed w/ errno %d)",
                      remoteHost, remoteHostPortNum, localHost ? localHost : "NULL", 
                      localHostPortNum, error);
        goto EXIT;
    }

    // Bind to the socket
    bind(localHostPortNum, localHost);
    if (!isOk())
    {
        goto EXIT;
    }

    // Kick off connection
    doConnect(remoteHostPortNum, remoteHost, mSimulatedConnect);

EXIT:
    return;
}
Esempio n. 18
0
/**
   \brief Completes writing the stream, closes it, release resources.
**/
bool QVideoEncoder::close()
{
   if(!isOk())
      return false;

   av_write_trailer(pFormatCtx);

   // close_video

   avcodec_close(pVideoStream->codec);
   freeFrame();
   freeOutputBuf();


   /* free the streams */

   for(unsigned i = 0; i < pFormatCtx->nb_streams; i++)
   {
      av_freep(&pFormatCtx->streams[i]->codec);
      av_freep(&pFormatCtx->streams[i]);
   }

   // Close file
   avio_close(pFormatCtx->pb);

   // Free the stream
   av_free(pFormatCtx);

   initVars();
   return true;
}
Esempio n. 19
0
    BSONObj SyncClusterConnection::findOne(const string &ns, Query query, const BSONObj *fieldsToReturn, int queryOptions) {
        
        if ( ns.find( ".$cmd" ) != string::npos ){
            string cmdName = query.obj.firstElement().fieldName();

            int lockType = _lockType( cmdName );

            if ( lockType > 0 ){ // write $cmd
                string errmsg;
                if ( ! prepare( errmsg ) )
                    throw UserException( 13104 , (string)"SyncClusterConnection::insert prepare failed: " + errmsg );
                
                vector<BSONObj> all;
                for ( size_t i=0; i<_conns.size(); i++ ){
                    all.push_back( _conns[i]->findOne( ns , query , 0 , queryOptions ).getOwned() );
                }
                
                _checkLast();
                
                for ( size_t i=0; i<all.size(); i++ ){
                    BSONObj temp = all[i];
                    if ( isOk( temp ) )
                        continue;
                    stringstream ss;
                    ss << "write $cmd failed on a shard: " << temp.jsonString();
                    ss << " " << _conns[i]->toString();
                    throw UserException( 13105 , ss.str() );
                }
                
                return all[0];
            }
        }

        return DBClientBase::findOne( ns , query , fieldsToReturn , queryOptions );
    }
Esempio n. 20
0
int udp_connection::read( char *data, int len, char *remote_addr, int remote_len, int flags )
{
  if (!isOk()) return( -1 );
  if (len<=0 || !data) return( 0 );

  int result, rflag;
  socklen_t slen;

  rflag=PROTOCOL_NONE;
  if (flags&PROTOCOL_PEEK) rflag|=MSG_PEEK;
#if defined(__WIN32__)
  data[0]=0;
#endif
  slen=sizeof( addr );
  result=::recvfrom( sock, data, len, rflag, (struct sockaddr *)&addr, &slen );
#if defined(__WIN32__)
  if (flags&PROTOCOL_PEEK)
    { // Windows can not do peek properly
      if (data[0]!=0)
        result=len;
    }
#endif
  if (result>0) readd+=result;
  if (remote_addr && remote_len>0)
    {
#if defined(__WIN32__) || defined(_MSC_VER)
      strncpy( remote_addr, inet_ntoa( addr.sin_addr ), remote_len );
#else
      inet_ntop( AF_INET, &(addr.sin_addr), remote_addr, remote_len );
#endif
    }
  return( result );
}
Esempio n. 21
0
Error Mapper::lock(buffer_handle_t bufferHandle, uint64_t usage,
        const IMapper::Rect& accessRegion,
        int acquireFence, void** outData) const
{
    auto buffer = const_cast<native_handle_t*>(bufferHandle);

    // put acquireFence in a hidl_handle
    hardware::hidl_handle acquireFenceHandle;
    NATIVE_HANDLE_DECLARE_STORAGE(acquireFenceStorage, 1, 0);
    if (acquireFence >= 0) {
        auto h = native_handle_init(acquireFenceStorage, 1, 0);
        h->data[0] = acquireFence;
        acquireFenceHandle = h;
    }

    Error error;
    auto ret = mMapper->lock(buffer, usage, accessRegion, acquireFenceHandle,
            [&](const auto& tmpError, const auto& tmpData)
            {
                error = tmpError;
                if (error != Error::NONE) {
                    return;
                }

                *outData = tmpData;
            });

    // we own acquireFence even on errors
    if (acquireFence >= 0) {
        close(acquireFence);
    }

    return (ret.isOk()) ? error : kTransactionError;
}
Esempio n. 22
0
		bool TcpSession::writeMessage( const Message& msg )
		{
			if (!isOk())
			{
				return false;
			}

			boost::mutex::scoped_lock lock(_writeMutex);

			if (!checkWriteBuffer(msg))
			{
				try
				{
					postWriteNull();
				}
				catch (std::exception& e)
				{
					LOGE("Try to write error ==> [ %s ]", e.what());
				}
				return false;
			}
			if ( _writeBuffer )
			{
				writeNolock((const char*)&msg, MessageHeaderLength);			
				writeNolock(msg._msgData, msg.messageDataLen());

				return true;
			}

			LOGE("Write buffer is null");

			return false;
		}
Esempio n. 23
0
Error Allocator::allocate(BufferDescriptor descriptor, uint32_t count,
        uint32_t* outStride, buffer_handle_t* outBufferHandles) const
{
    Error error;
    auto ret = mAllocator->allocate(descriptor, count,
            [&](const auto& tmpError, const auto& tmpStride,
                const auto& tmpBuffers) {
                error = tmpError;
                if (tmpError != Error::NONE) {
                    return;
                }

                // import buffers
                for (uint32_t i = 0; i < count; i++) {
                    error = mMapper.importBuffer(tmpBuffers[i],
                            &outBufferHandles[i]);
                    if (error != Error::NONE) {
                        for (uint32_t j = 0; j < i; j++) {
                            mMapper.freeBuffer(outBufferHandles[j]);
                            outBufferHandles[j] = nullptr;
                        }
                        return;
                    }
                }

                *outStride = tmpStride;
            });

    // make sure the kernel driver sees BC_FREE_BUFFER and closes the fds now
    hardware::IPCThreadState::self()->flushCommands();

    return (ret.isOk()) ? error : kTransactionError;
}
Esempio n. 24
0
//--------------------------------------------------------------------
//
//--------------------------------------------------------------------
void GroupBox::done()
{
    if (isOk())
    {

        Inherited::done();
    }
}
Esempio n. 25
0
 bool searchMatrix(vector<vector<int>>& matrix, int target) {
     if (matrix.size() == 0) return false;
     for (int i = 0; i < matrix.size(); ++i) {
         bool is = isOk(matrix[i], target);
         if (is) return true;
     }
     return false;
 }
Esempio n. 26
0
//--------------------------------------------------------------------
//
//--------------------------------------------------------------------
void Button::done()
{
    if (isOk())
    {

        Inherited::done();
    }
}
Esempio n. 27
0
//--------------------------------------------------------------------
//
//--------------------------------------------------------------------
void JuceComboBox::done()
{
    if (isOk())
    {

        Inherited::done();
    }
}
 bool SyncClusterConnection::_commandOnActive(const string &dbname, const BSONObj& cmd, BSONObj &info, int options ) {
     auto_ptr<DBClientCursor> cursor = _queryOnActive(dbname + ".$cmd", cmd, 1, 0, 0, options, 0);
     if ( cursor->more() )
         info = cursor->next().copy();
     else
         info = BSONObj();
     return isOk( info );
 }
Esempio n. 29
0
//--------------------------------------------------------------------
//
//--------------------------------------------------------------------
void JuceForm::done()
{
    if (isOk())
    {

        Inherited::done();
    }
}
Esempio n. 30
0
void JSON::save(const wxFileName& fn) const
{
    if(!isOk()) {
        FileUtils::WriteFileContent(fn, "[]");
    } else {
        FileUtils::WriteFileContent(fn, toElement().format(), wxConvUTF8);
    }
}