bool
SendEmailRequestPacket::setData(const char* adr, const char* fromAdr,
                                const char* subject, const char* data,
                                uint32 nbrOptionalHeaders , 
                                const char * const * const 
                                optionalHeaderTypes,
                                const char * const * const 
                                optionalHeaderValues)
{
   // Get the length of the strings
   uint32 adrLength = strlen(adr)+1;
   uint32 fromAdrLength = strlen(fromAdr)+1;
   uint32 subjectLength = strlen(subject)+1;
   uint32 dataLength = strlen(data)+1;
   uint32 optionalHeaderLengths = 0;
   
   for ( uint32 i = 0 ; i < nbrOptionalHeaders ; i++ ) {
      optionalHeaderLengths += strlen( optionalHeaderTypes[ i ] ) + 1;
      optionalHeaderLengths += strlen( optionalHeaderValues[ i ] ) + 1;
   }

   // Make sure it all fits
   if ( adrLength + fromAdrLength + subjectLength + 
       dataLength + m_addressStartPos + optionalHeaderLengths 
        >= getBufSize() )
   {
      resize( adrLength + fromAdrLength + subjectLength + 
              dataLength + m_addressStartPos + optionalHeaderLengths + 10);
   }

   if (adrLength + fromAdrLength + subjectLength + 
       dataLength + m_addressStartPos + optionalHeaderLengths 
       < getBufSize() ) 
   {
      // Write the strings
      int pos = m_addressStartPos;
      incWriteString(pos, adr);
      incWriteString(pos, fromAdr);
      incWriteString(pos, subject);
      incWriteString(pos, data);
      for ( uint32 i = 0 ; i < nbrOptionalHeaders ; i++ ) {
         incWriteString( pos, optionalHeaderTypes[ i ] );
         incWriteString( pos, optionalHeaderValues[ i ] );
      }
      setLength(pos);

      // Set the length of the strings
      setAddressLength(adrLength);
      setFromAddressLength(fromAdrLength);
      setSubjectLength(subjectLength);
      setDataLength(dataLength);
      setNbrOptionalHeaderLines( nbrOptionalHeaders );

      // Return
      return (true);
   } else {
      // Strings too long!
      return (false);
   }
}
SearchExpandItemReplyPacket::
SearchExpandItemReplyPacket(const SearchExpandItemRequestPacket* req,
                            const vector<pair<uint32, OverviewMatch*> >&
                            translated)
      : ReplyPacket( calcPacketSize(translated),
                     Packet::PACKETTYPE_SEARCHEXPANDITEMREPLY,
                     req,
                     StringTable::OK)
{
   int pos = USER_DEF_POS;
   incWriteLong(pos, req->getUserData());
   incWriteLong(pos, translated.size());
   for ( uint32 i = 0; i < translated.size(); ++i ) {
      // Update position
      setLength(pos);      
      if ( updateSize( 1024, 1024+getBufSize()) ) {
         mc2dbg8 << "[SEIP]: Resized packet to " << getBufSize()
                 << " bytes" << endl;
      }
      incWriteLong(pos, translated[i].first);
      // From now on we will have overview matches here.
      translated[i].second->save(this, pos);
   }
   setLength(pos);
}
void 
GfxFeatureMapReplyPacket::setGfxFeatureMapData(uint32 size, 
                                               DataBuffer* data,
                                               bool zipped )
{
   // Store the zipped flag.
   setZippedGfxFeatureMapData( zipped );
   
   // Get position
   int position = getGfxStartPos();

   // Check size of buffer
   int bufSize  = getBufSize();
   int required = position + size + 1024;
   if ( required > bufSize ) {
      mc2dbg8 << "GfxFeatureMapReplyPacket : Resizing to " << required 
              << endl;
      setLength(position); // Needed for resize,
      resize(required);
   }
   
   // Write the size
   incWriteLong(position, size);

   // Reset offsets
   data->reset();
   
   // Get the bytearray pointer from the DataBuffer.
   const byte* bytes = data->readNextByteArray(size);
   // Copy it into the packet.
   incWriteByteArray(position, bytes, size);
   
   mc2dbg8 << "position " << position<< endl;
   setLength(position);
}
Example #4
0
string _dpsLogPage::toString() const
{
    stringstream ss ;
    ss << "PageNumber: " << _pageNumber
       << ", StartPage: " << (INT32)_startPage
       << ", BeginLSNV" << _beginLSN.version
       << ", BeginLSNO" << _beginLSN.offset
       << ", Length: " << getLength()
       << ", Size: " << getBufSize()
       << ", IdleSize: " << getLastSize() ;
    return ss.str() ;
}
Example #5
0
T* RingBuffer<T>::writeOneBuffer()
{
  pthread_mutex_lock(&_lock);
 
  int futWritePos = (getWritePos() + 1) % getNumBufers();
  while (futWritePos == getReadPos())
    pthread_cond_wait(&_wrcond, &_lock);

  T *buf = _buffer + getWritePos()*getBufSize();

  pthread_mutex_unlock(&_lock);
  return buf;
}
Example #6
0
T* RingBuffer<T>::readOneBuffer()
{
  pthread_mutex_lock(&_lock);
 
  while (getReadPos() == getWritePos())
    pthread_cond_wait(&_rdcond, &_lock);

  T *buf = _buffer + getReadPos()*getBufSize();

  pthread_mutex_unlock(&_lock);

  return buf;
}
SubRouteRequestPacket::SubRouteRequestPacket(const DriverPref* driverPref,
                                             const SubRouteVector* origs,
                                             const OrigDestInfoList* dests,
                                             const OrigDestInfoList* allDests,
                                             bool routeToOneDest,
                                             uint32 cutOff,
                                             int levelDelta,
                                             const DisturbanceVector*
                                             disturbances,
                                             bool calcCostSums,
                                             bool dontSendSubRoutes,
                                             const DisturbanceVector*
                                             infoModuleDists )
{   
   mc2dbg4 << "SubRouteRequestPacket::SubRouteRequestPacket" << endl;
   setPriority(DEFAULT_PACKET_PRIO);
   // Calculate size of request
   // Origins and destinations
  
   // Do something about the listtype
   if ( driverPref->getVehicleRestriction() != ItemTypes::pedestrian ) {
      setListType(SubRouteListTypes::LOWER_LEVEL);
   } else {
      // Pedestrian
      setListType(SubRouteListTypes::LOWER_LEVEL_WALK); // Lower level walk
   }

   uint32 reqSize = SUBROUTE_REQUEST_HEADER_SIZE;

   // The number of subroutes
   int nbrSubRoutes = origs->getSize() +
      // Add the destinations for HIGHER_LEVEL too
    ((getListType() == SubRouteListTypes::HIGHER_LEVEL) ? dests->size() : 0);

   
   // Origin. Will probably be removed
   if ( origs != NULL &&
        getListType() == SubRouteListTypes::HIGHER_LEVEL )
      reqSize += origs->size() * ORIG_DEST_SIZE;
   // Destinations 
   if ( dests != NULL )
      reqSize += dests->size() * ORIG_DEST_SIZE;
   // Subroutes.
   for(uint32 i=0; i < origs->size() ; i++ ) {
      reqSize += SUB_ROUTE_SIZE +
         SUB_ROUTE_CONNECTION_SIZE * 1;
   }

   // Compensate for disturbances
   // Length
   reqSize += 4;
   if ( disturbances != NULL ) {
      reqSize += DISTURBANCE_SIZE*disturbances->size();
   }
   reqSize += 4;
   if ( infoModuleDists != NULL ) {
      reqSize += 8 * infoModuleDists->size();
   }

   if ( reqSize > getBufSize() ) {
      mc2dbg2 << "SubRouteRequestPacket - buffer too small reallocing"
              << endl;
      byte* temp = MAKE_UINT32_ALIGNED_BYTE_BUFFER( reqSize * 2);
      memcpy(temp, this->buffer, SUBROUTE_REQUEST_HEADER_SIZE);      
      delete [] this->buffer;
      this->buffer = temp;
      this->bufSize = reqSize * 2;
   }

   // First request? Won't exactly work all the time...
   bool original = origs->front()->getPrevSubRouteID() == MAX_UINT32;

   if ( levelDelta == 1 ) {
      // Higher level routing - do some tricks
      setMapID( FIRST_OVERVIEWMAP_ID  );
      setListType(SubRouteListTypes::HIGHER_LEVEL);
   }

   //setOriginIP(leaderIP);
   //setOriginPort(leaderPort);
   setSubType(Packet::PACKETTYPE_SUBROUTEREQUEST);
   // Get mapid from one of the origins
   setMapID(origs->front()->getNextMapID() );
   // Setting the extra vehicle to avoid toll roads.
   uint32 extraVehicle = 0;
   if ( driverPref->avoidTollRoads() ) {
      extraVehicle |= ItemTypes::avoidTollRoad;
   }
   if ( driverPref->avoidHighways() ) {
      extraVehicle |= ItemTypes::avoidHighway;
   }
   setVehicleRestrictions( driverPref->getVehicleRestriction() |
                           extraVehicle );
                                                  
   setRoutingCosts(driverPref->getRoutingCosts());
   setUseTurnCost(driverPref->useUturn());
   setTime(driverPref->getTime());
   setMinWaitTime(driverPref->getMinWaitTime());

   // Some flags.
   setRouteToAll(! routeToOneDest );
   setDontSendSubRoutes( dontSendSubRoutes );
   setCalcCostSums( calcCostSums );
      
   setRouteID(0);  // Don't know what it should be. Seems to be the same
                   // as the request id, but for the RouteReader.
   setCutOff(cutOff);
   
   setIsOriginalRequest(original);
   
   // Add the origins that belongs to this mapID and only the first time.
   setNbrOrigins(0);
   int pos = SUBROUTE_REQUEST_HEADER_SIZE;

   if ( original ) {
      for(uint32 i=0; i < origs->getSize(); i++) {
         const SubRoute* curSubRoute = origs->getSubRouteAt(i);
         // Destinations are origins in next route.
         const OrigDestInfo* orig = curSubRoute->getDestInfo();
         addOrigin(*orig, pos);
//           addOrigin(curSubRoute->getNextMapID(),
//                     curSubRoute->getDestNodeID(),
//                     curSubRoute->getDestOffset(),
//                     MAX_UINT32,
//                     MAX_UINT32,
//                     pos);
      }
   }
   
   // Add all destinations ( not allDests, they aren't used yet)
   setNbrDestinations(0);
   OrigDestInfoList::const_iterator it;
   it = dests->begin();
   while ( it != dests->end() ) {
      addDestination(*it, pos);
      it++;
   }

   setNbrSubRoutes( nbrSubRoutes );
   for (uint32 i = 0; i < origs->getSize(); i++) {
      SubRoute* subRoute = (*origs)[i];
      if (subRoute != NULL) {
         addSubRoute(subRoute, pos);
      }
   }

   if ( getListType() == SubRouteListTypes::HIGHER_LEVEL ) {
      OrigDestInfoList::const_iterator it(dests->begin());
      for(uint32 i=0; i < dests->size() ; ++i ) {
         SubRoute subRoute(*it, *it);
         ++it;
         // Add backward subroute for each destination.
         // The routemodule uses them as destinations later.
         addSubRoute(&subRoute, pos, false);
      }
   }
   
   addDisturbances(pos, disturbances);
   // Add info module disturbances using the more compact format.
   addInfoModDisturbances( pos, infoModuleDists );
   setLength(pos);
   
   if ( true || pos > (int)reqSize || (reqSize - pos) > 65536 ) {
      mc2dbg2 << "SubRouteRequestPacket - calcSize = " << reqSize 
           << "real size = " << pos << endl;
   }
} // Constructor
	// Implementation of inherited interfaces
	void* ANativeWindowDisplayAdapter::allocateBuffer(int width, int height,
			const char* format, int &bytes, int numBufs) {
		LOG_FUNCTION_NAME;
		status_t err;
		int i = -1;
		const int lnumBufs = numBufs;
		mBufferHandleMap = new buffer_handle_t*[lnumBufs];
		mGrallocHandleMap = new IMG_native_handle_t*[lnumBufs];
		int undequeued = 0;
		GraphicBufferMapper &mapper = GraphicBufferMapper::get();
		Rect bounds;

		if (NULL == mANativeWindow) {
			return NULL;
		}

		// Set gralloc usage bits for window.
		err = mANativeWindow->set_usage(mANativeWindow, CAMHAL_GRALLOC_USAGE);
		if (err != 0) {
			LOGE("native_window_set_usage failed: %s (%d)", strerror(-err), -err);

			if (ENODEV == err) {
				LOGE("Preview surface abandoned!");
				mANativeWindow = NULL;
			}

			return NULL;
		}

		LOGE("Number of buffers set to ANativeWindow %d", numBufs);
		///Set the number of buffers needed for camera preview
		err = mANativeWindow->set_buffer_count(mANativeWindow, numBufs);
		if (err != 0) {
			LOGE("native_window_set_buffer_count failed: %s (%d)", strerror(-err),
					-err);

			if (ENODEV == err) {
				LOGE("Preview surface abandoned!");
				mANativeWindow = NULL;
			}

			return NULL;
		}
		LOGE("Configuring %d buffers for ANativeWindow", numBufs);
		mBufferCount = numBufs;

		// Set window geometry
		err = mANativeWindow->set_buffers_geometry(mANativeWindow,
				width,
				height,
				ANDROID_HAL_PIXEL_FORMAT_YCbCr_422_I
				); //current camera is YUYV,which same as YUY2

		if (err != 0) {
			LOGE("native_window_set_buffers_geometry failed: %s (%d)",
					strerror(-err), -err);

			if (ENODEV == err) {
				LOGE("Preview surface abandoned!");
				mANativeWindow = NULL;
			}

			return NULL;
		}

		///We just return the buffers from ANativeWindow, if the width and height are same, else (vstab, vnf case)
		///re-allocate buffers using ANativeWindow and then get them
		///@todo - Re-allocate buffers for vnf and vstab using the width, height, format, numBufs etc
		if (mBufferHandleMap == NULL) {
			LOGE("Couldn't create array for ANativeWindow buffers");
			LOG_FUNCTION_NAME_EXIT;
			return NULL;
		}

		//mANativeWindow->get_min_undequeued_buffer_count(mANativeWindow,
		//		&undequeued);

		bytes = getBufSize(format, width, height);

		// lock the initial queueable buffers
		bounds.left = 0;
		bounds.top = 0;
		bounds.right = width;
		bounds.bottom = height;

		for (i = 0; i < mBufferCount; i++) {
			IMG_native_handle_t** hndl2hndl;
			int stride;
			err = mANativeWindow->dequeue_buffer(mANativeWindow,
					(buffer_handle_t**) &hndl2hndl, &stride);

			if (err != 0) {
				LOGE("dequeueBuffer failed: %s (%d)", strerror(-err), -err);

				if (ENODEV == err) {
					LOGE("Preview surface abandoned!");
					mANativeWindow = NULL;
				}

				goto fail;
			}

			mBufferHandleMap[i] = (buffer_handle_t*) hndl2hndl;
		}


		LOGE("mBufferCount %d, undequeued %d\n", mBufferCount, undequeued);

		for (i = 0; i < mBufferCount - undequeued; i++) {
			IMG_native_handle_t* handle;			
			void * y_uv = NULL;


			mapper.lock((buffer_handle_t) *mBufferHandleMap[i], CAMHAL_GRALLOC_USAGE, bounds, &y_uv);
			handle = (IMG_native_handle_t*)y_uv;

			LOGE("xxxxxxxx graphic index %d, address %x", i, handle);
			mANativeWindow->lock_buffer(mANativeWindow, mBufferHandleMap[i]);
			mGrallocHandleMap[i] = handle;
			mFramesWithCameraAdapterMap.add((int) mGrallocHandleMap[i], i);
			mapper.unlock((buffer_handle_t) *mBufferHandleMap[i]);
		}

		// return the rest of the buffers back to ANativeWindow
		for (i = (mBufferCount - undequeued); i >= 0 && i < mBufferCount; i++) {
			err = mANativeWindow->cancel_buffer(mANativeWindow,
					mBufferHandleMap[i]);
			if (err != 0) {
				LOGE("cancel_buffer failed: %s (%d)", strerror(-err), -err);

				if (ENODEV == err) {
					LOGE("Preview surface abandoned!");
					mANativeWindow = NULL;
				}

				goto fail;
			}
			mFramesWithCameraAdapterMap.removeItem((int) mGrallocHandleMap[i]);
			void *y_uv[2];
			mapper.lock((buffer_handle_t) mBufferHandleMap[i],
					CAMHAL_GRALLOC_USAGE, bounds, y_uv);
			mapper.unlock((buffer_handle_t) mBufferHandleMap[i]);
		}

		mFirstInit = true;
		mPixelFormat = getPixFormatConstant(format);
		mFrameWidth = width;
		mFrameHeight = height;

		return mGrallocHandleMap;

fail:
		// need to cancel buffers if any were dequeued
		for (int start = 0; start < i && i > 0; start++) {
			int err = mANativeWindow->cancel_buffer(mANativeWindow,
					mBufferHandleMap[start]);
			if (err != 0) {
				LOGE("cancelBuffer failed w/ error 0x%08x", err);
				break;
			}
			mFramesWithCameraAdapterMap.removeItem((int) mGrallocHandleMap[start]);
		}

		freeBuffer(mGrallocHandleMap);

		LOGE("Error occurred, performing cleanup");

		if (NULL != mErrorNotifier.get()) {
			mErrorNotifier->errorNotify(-ENOMEM);
		}

		LOG_FUNCTION_NAME_EXIT;
		return NULL;

	}