示例#1
0
void Symbol::addPair(const string& key, const string& value)
{
  if (existPair(key)) {
    warning("Pair key '" + key + "' re-defined. new: '" + value + "' old: '" + lookupPair(key) + "'");
  }
  m_pairs.add(key, value);
}
示例#2
0
// Relative to rKey, return the key and value associated with
// next (lexicographically ordered) key/value pair stored in the
// database.  If rKey is the empty string, key and value associated
// with the first entry in the database will be returned.
// Returns
//   OS_SUCCESS if there is a "next" entry
//   OS_NOT_FOUND if rKey is not found in the database and is not the
//      empty string
//   OS_NO_MORE_DATA if there is no "next" entry
OsStatus OsConfigDb::getNext(const UtlString& rKey,
                             UtlString& rNextKey,
                             UtlString& rNextValue) const
{
   OsReadLock  lock(mRWMutex);
   UtlBoolean  foundMatch;
   size_t      nextIdx = 0;
   DbEntry     lookupPair(rKey);
   DbEntry*    pEntry;

   foundMatch = FALSE;
   if (rKey.compareTo("") == 0)
   {
      foundMatch = TRUE;         // if the key is the empty string, then
      nextIdx = 0;               // return the first entry in the database
   }
   else
   {
      size_t idx = mDb.index(&lookupPair);
      if (idx != UTL_NOT_FOUND)
      {
         foundMatch = TRUE;
         nextIdx = idx + 1;
      }
   }

   if (foundMatch && (((int)nextIdx) < numEntries()))
   {
      pEntry     = (DbEntry *)mDb.at(nextIdx);
      rNextKey   = pEntry->key;
      rNextValue = pEntry->value;

      return OS_SUCCESS;
   }

   rNextKey   = "";
   rNextValue = "";

   if (!foundMatch)
      return OS_NOT_FOUND;
   else
      return OS_NO_MORE_DATA;
}
示例#3
0
// Sets rValue to the value in the database associated with rKey.
// If rKey is found in the database, returns OS_SUCCESS.  Otherwise,
// returns OS_NOT_FOUND and sets rValue to the empty string.
OsStatus OsConfigDb::get(const UtlString& rKey, UtlString& rValue) const
{
   OsReadLock lock(mRWMutex);
   DbEntry   lookupPair(rKey);
   DbEntry*  pEntry;
   size_t i = mDb.index(&lookupPair);
   if (i == UTL_NOT_FOUND)
   {
      rValue = "";     // entry not found
      return OS_NOT_FOUND;
   }
   else
   {
      pEntry = (DbEntry *)mDb.at(i);
      rValue = pEntry->value;
   }

   return OS_SUCCESS;
}
示例#4
0
// Remove the key/value pair associated with rKey.
// Return OS_SUCCESS if the key was found in the database, return
// OS_NOT_FOUND otherwise.
OsStatus OsConfigDb::remove(const UtlString& rKey)
{
   OsWriteLock lock(mRWMutex);
   DbEntry    lookupPair(rKey);
   DbEntry*   pEntryToRemove;
   size_t i = mDb.index(&lookupPair);
   if (i == UTL_NOT_FOUND)
   {
      return OS_NOT_FOUND;
   }
   else
   {
      pEntryToRemove = (DbEntry *)mDb.at(i);
      mDb.removeAt(i);
      delete pEntryToRemove;

      return OS_SUCCESS;
   }
}
示例#5
0
CallObject* Listener::removeEntry(UtlString& rKey)
{
   OsWriteLock lock(mRWMutex);
   ActiveCall  lookupPair(rKey);
   ActiveCall* pEntryToRemove;
   unsigned int i = mCalls.index(&lookupPair);
   if (i == UTL_NOT_FOUND)
   {
      return NULL;
   }
   else
   {
      pEntryToRemove = (ActiveCall *)mCalls.at(i);
      CallObject* pObject = pEntryToRemove->getCallObject();
      mCalls.removeAt(i);
      delete pEntryToRemove;

      OsSysLog::add(FAC_MEDIASERVER_VXI, PRI_DEBUG, "Listener::remove - removed CallObject %p\n", pObject);

      return pObject;
   }
}
示例#6
0
// store translations into transMap
void storeTrans(ImgFetcher &fetcher, const Point2f &absHint, PairToTransData &transMap, const MaxDists &dists) {
	vector<GridPtOff> imOffs;
	if (fetcher.row_major) {
		imOffs.push_back(makeOff(-1, 0));
		imOffs.push_back(makeOff(-1, -1));
		imOffs.push_back(makeOff(0, -1));
		imOffs.push_back(makeOff(1, -1));
	} else {
		imOffs.push_back(makeOff(0, -1));
		imOffs.push_back(makeOff(-1, -1));
		imOffs.push_back(makeOff(-1, 0));
		imOffs.push_back(makeOff(-1, 1));
	}

	map<PtPair, shared_future<TransData>> pairToTransFut;
	map<GridPt, shared_future<FFTHolder>> ptToFFTFut;

	unsigned loaded = 0;
	GridPt fixPt = {{0, 0}};
	GridPt waitPt = {{0, 0}};
	Mat cur;

	fetcher.getMat(fixPt, cur);
	Size imSz = cur.size();
	unsigned fftLen = getFFTLen(imSz);

	map<GridPtOff, Mat> hintToMask;
	storeHintToMask(hintToMask, imSz, absHint, dists);

	float *tmp = (float *)fftwf_malloc_thr(sizeof(float) * fftLen);
	fftwf_plan r2cPlan = fftwf_plan_dft_r2c_2d(imSz.height, imSz.width, tmp, (fftwf_complex *)tmp, FFTW_MEASURE);
	fftwf_plan c2rPlan = fftwf_plan_dft_c2r_2d(imSz.height, imSz.width, (fftwf_complex *)tmp, tmp, FFTW_MEASURE);
	fftwf_free_thr(tmp);

	bool readDone = false;
	while (true) {
		//a dirty kind of event loop
		if (loaded > fetcher.cap || readDone) {
			//			printf("start free waitPt %d %d\n", waitPt[0], waitPt[1]);
			// free oldest image, at waitPt
			for (auto &off: imOffs) {
				// *subtract* offset to avoid duplicating pairs
				GridPt nbrPt = {{waitPt[0] - off[0], waitPt[1] - off[1]}};
				if (ptInGrid(nbrPt, fetcher)) {
					PtPair pair = {{waitPt, nbrPt}};
					shared_future<TransData> transFut;
					if (!lookupPair(pairToTransFut, pair, transFut)) {
						printf("err: future of pair %d %d to %d %d not found\n", pair[0][0], pair[0][1], pair[1][0], pair[1][1]);
						exit(1);
					}
					transMap.emplace(pair, transFut.get());
					pairToTransFut.erase(pair);
				}
			}
			fftwf_free_thr(ptToFFTFut[waitPt].get().fft);
			ptToFFTFut.erase(waitPt);

			if (!nextCoor(waitPt, fetcher)) {
				break;
			}
			loaded--;
		}

		if (!readDone) {
			//printf("emplace fft at %d %d\n", fixPt[0], fixPt[1]);
			fetcher.getMat(fixPt, cur);

			// fft only supports 32-bit float with even width, for now
			assert(cur.type() == CV_32FC1 && (int)cur.step[0] == cur.size().width * 4 && cur.step[1] == 4 && cur.size().width % 2 == 0);
			assert(cur.isContinuous());

			ptToFFTFut.emplace(fixPt, async(launch::async,
				[&r2cPlan, &absHint](Mat im) {
					return FFTHolder(im, absHint, r2cPlan);
			},
				cur
				));

			for (auto &off: imOffs) {
				GridPt nbrPt = {{fixPt[0] + off[0], fixPt[1] + off[1]}};
				if (ptInGrid(nbrPt, fetcher)) {
					PtPair pair = {{fixPt, nbrPt}};
					//					printf("emplace pair transfut %d %d, %d %d\n", pair[0][0], pair[0][1], pair[1][0], pair[1][1]);

					// needed since VS2012 async() can't take functions with too many arguments :(
					shared_future<FFTHolder> &a = ptToFFTFut[fixPt];
					shared_future<FFTHolder> &b = ptToFFTFut[nbrPt];
					pairToTransFut.emplace(pair, async(launch::async, [=] {
						return phaseCorrThr(a, b, c2rPlan, pair, absHint, hintToMask, imSz);
					}));
				}
			}

			loaded++;
			if (!nextCoor(fixPt, fetcher)) {
				readDone = true;
			}
		}
	}

	fftwf_destroy_plan(r2cPlan);
	fftwf_destroy_plan(c2rPlan);
}