예제 #1
0
ssize_t
read_pos(int fd, off_t offset, void *buffer, size_t bufferSize)
{
	Descriptor *descriptor = get_descriptor(fd);
	if (descriptor == NULL)
		RETURN_AND_SET_ERRNO(B_FILE_ERROR);

	RETURN_AND_SET_ERRNO(descriptor->ReadAt(offset, buffer, bufferSize));
}
예제 #2
0
파일: vfs.cpp 프로젝트: naveedasmat/haiku
ssize_t
write(int fd, const void *buffer, size_t bufferSize)
{
	Descriptor *descriptor = get_descriptor(fd);
	if (descriptor == NULL)
		RETURN_AND_SET_ERRNO(B_FILE_ERROR);

	RETURN_AND_SET_ERRNO(descriptor->Write(buffer, bufferSize));
}
예제 #3
0
bool DescriptorStore::add(dvbpsi_descriptor_t *p_descriptor)
{
	Descriptor *d = NULL;
	if (p_descriptor) d = DescriptorRegistry::instance().create(m_parent, p_descriptor);
	if (d) {
		m_store.insert( std::pair<uint8_t, Descriptor*>(d->getTag(), d) );
		push((Object*)d);
	}
	return (d != NULL);
}
예제 #4
0
int
dup(int fd)
{
	Descriptor *descriptor = get_descriptor(fd);
	if (descriptor == NULL)
		RETURN_AND_SET_ERRNO(B_FILE_ERROR);

	descriptor->Acquire();
	RETURN_AND_SET_ERRNO(fd);
}
예제 #5
0
파일: main.cpp 프로젝트: JohannesEbke/a4
 void populate_fields(const shared<Message>& event)
 {
     if (_desc && _refl)
         return;
     _desc = event->GetDescriptor();
     _refl = event->GetReflection();
     _field_run = _desc->FindFieldByName("run_number");
     _field_mc_channel = _desc->FindFieldByName("mc_channel_number");
     
 }
예제 #6
0
double EuclidianMetric::getDistance(Descriptor &desc1, Descriptor &desc2)
{
    if (desc1.size() != desc2.size())
        throw std::logic_error("Error: out of bounds!");

    double distance = 0;
    for (int i = 0; i < desc1.size(); i++)
        distance += sqr(desc1[i] - desc2[i]);

    return std::sqrt(distance);
}
예제 #7
0
void DesignerGUIUtils::setupSamplesDocument(const Descriptor& d, const QIcon& ico, QTextDocument* doc) {
    bool hasIcon = (ico.availableSizes().size() > 0);
    QString text =
            QString(hasIcon ?
                        "<html>"
                        "<table align='center' border='0' cellpadding='3' cellspacing='3'>"
                        "<tr><td colspan='2'><h1 align='center'>%1</h1></td></tr>"
                        "<tr>"
                            "<td valign='middle' width='20%'><img src=\"%2\"/></td>"
                            "<td valign='bottom'><br>%3</td></tr>"
                        "<tr><td colspan='2' valign='top'>%4<br></td></tr>"
                        "<tr><td colspan='2' bgcolor='gainsboro' align='center'><font color='maroon' size='+2' face='Courier'><b>%5</b></font></td></tr>"
                        "</table>"
                        "</html>"
                      :
                        "<html>"
                        "<table align='center' border='0' cellpadding='3' cellspacing='3'>"
                        "<tr><td><h1 align='center'>%1</h1></td></tr>"
                        "<tr>%2"
                            "<td valign='bottom'><br>%3</td></tr>"
                        "<tr><td valign='top' halign='right'>%4<br></td></tr>"
                        "<tr><td bgcolor='gainsboro' align='center'><font color='maroon' size='+2' face='Courier'><b>%5</b></font></td></tr>"
                        "</table>"
                        "</html>"
                        );
    QString img("img://img");

    if (hasIcon) {
        doc->addResource(QTextDocument::ImageResource, QUrl(img), ico.pixmap(200));
    }
#if (QT_VERSION < 0x050000) //Qt 5
    QString body = Qt::escape(d.getDocumentation()).replace("\n", "<br>");
#else
    QString body = d.getDocumentation().toHtmlEscaped().replace("\n", "<br>");
#endif
    int brk = body.indexOf("<br><br>");
    int shift = 8;
    if (brk <= 0) {
        brk = body.indexOf("<br>");
        shift = 4;
    }
    QString body2;
    if (brk > 0) {
        body2 = body.mid(brk + shift);
        body = body.left(brk);
    }
    text = text.arg(d.getDisplayName()).arg(hasIcon ? img : "").arg(body).arg(body2)
        .arg(QObject::tr("Double click to load the sample"));
    doc->setHtml(text);
    QFont f;
    //f.setFamily("Times New Roman");
    f.setPointSizeF(12);
    doc->setDefaultFont(f);
}
예제 #8
0
Descriptor ColorStructure::extract_(MyImage *image,
				   bool makeVisRep,
				   Magick::Image *repr){
  cv::Mat &img = *image->getOpenCVMat();
  Frame* frame = new Frame(img);
  XM::ColorStructureDescriptor *ehd = Mpeg7Feature::getColorStructureD(frame, 64);
  Descriptor desc;
  for(size_t i = 0; i < ehd->GetSize(); ++i)
    desc.push_back((float) ehd->GetElement(i));
  return desc;
}
void IOManager::pollBody() {
  while (!stopped()) {
    int res = poller_->poll();
    if (res == -1) {
      if (errno != EINTR) {
        perror("Error in epoll_wait ");
        exit(1);
      }
    }

    // Issue the alarm callbacks that are due. We'll clean up the
    // queue shortly.
    m_timer_queue_.lock();
    TicksClock::Ticks now = TicksClock::getTicks();
    TimerQueue::iterator to_execute = timer_queue_.begin();
    while (to_execute != timer_queue_.end()) {
      if (to_execute->first > now) {
        break;
      }
      worker_pool_->addTask(to_execute->second);
      timer_queue_.erase(to_execute++);
    }
    m_timer_queue_.unlock();

    int e;
    Descriptor* desc;
    for (int i = 0; i < res; i++) {
      poller_->getEvents(i, &e, &desc);
      if (e & (DescriptorPoller::DP_ERROR | DescriptorPoller::DP_READ_READY)) {
        desc->readIfWaiting();
      }
      if (e & (DescriptorPoller::DP_ERROR | DescriptorPoller::DP_WRITE_READY)) {
        desc->writeIfWaiting();
      }
    }

    Descriptor* to_delete = NULL;
    m_deleted_desc_.lock();
    to_delete = deleted_desc_;
    deleted_desc_ = NULL;
    m_deleted_desc_.unlock();
    while (to_delete) {
      Descriptor* hold = to_delete;
      to_delete = to_delete->next_;
      delete hold;
    }
  }

  m_stop_.lock();
  polling_ = false;
  cv_polling_.signal();
  m_stop_.unlock();
}
예제 #10
0
bool InferredType::set(const ConcurrentJSLocker& locker, VM& vm, Descriptor newDescriptor)
{
    // We will trigger write barriers while holding our lock. Currently, write barriers don't GC, but that
    // could change. If it does, we don't want to deadlock. Note that we could have used
    // GCSafeConcurrentJSLocker in the caller, but the caller is on a fast path so maybe that wouldn't be
    // a good idea.
    DeferGCForAWhile deferGC(vm.heap);
    
    // Be defensive: if we're not really changing the type, then we don't have to do anything.
    if (descriptor(locker) == newDescriptor)
        return false;

    bool shouldFireWatchpointSet = false;
    
    // The new descriptor must be more general than the previous one.
    ASSERT(newDescriptor.subsumes(descriptor(locker)));

    // If the new descriptors have different structures, then it can only be because one is null.
    if (descriptor(locker).structure() != newDescriptor.structure())
        ASSERT(!descriptor(locker).structure() || !newDescriptor.structure());

    // We are changing the type, so make sure that if anyone was watching, they find out about it now. If
    // anyone is watching, we make sure to go to Top so that we don't do this sort of thing again.
    if (m_watchpointSet.state() != ClearWatchpoint) {
        // We cannot have been invalidated, since if we were, then we'd already be at Top.
        ASSERT(m_watchpointSet.state() != IsInvalidated);

        // We're about to do expensive things because some compiler thread decided to watch this type and
        // then the type changed. Assume that this property is crazy, and don't ever do any more things for
        // it.
        newDescriptor = Top;

        shouldFireWatchpointSet = true;
    }

    // Remove the old InferredStructure object if we no longer need it.
    if (!newDescriptor.structure())
        m_structure = nullptr;

    // Add a new InferredStructure object if we need one now.
    if (newDescriptor.structure()) {
        if (m_structure) {
            // We should agree on the structures if we get here.
            ASSERT(newDescriptor.structure() == m_structure->structure());
        } else {
            m_structure = adoptRef(new InferredStructure(vm, this, newDescriptor.structure()));
            newDescriptor.structure()->addTransitionWatchpoint(&m_structure->m_watchpoint);
        }
    }

    // Finally, set the descriptor kind.
    m_kind = newDescriptor.kind();

    // Assert that we did things.
    ASSERT(descriptor(locker) == newDescriptor);

    return shouldFireWatchpointSet;
}
예제 #11
0
void SkGradientShaderBase::flatten(SkWriteBuffer& buffer) const {
    Descriptor desc;
    desc.fColors = fOrigColors;
    desc.fPos = fOrigPos;
    desc.fCount = fColorCount;
    desc.fTileMode = fTileMode;
    desc.fGradFlags = fGradFlags;

    const SkMatrix& m = this->getLocalMatrix();
    desc.fLocalMatrix = m.isIdentity() ? nullptr : &m;
    desc.flatten(buffer);
}
예제 #12
0
Descriptor ScalableColor::extract_(MyImage *image,
				   bool makeVisRep,
				   Magick::Image *repr){
  cv::Mat &img = *image->getOpenCVMat();
  Frame* frame = new Frame(img);
  const size_t dsize = 256;
  XM::ScalableColorDescriptor *scd = Mpeg7Feature::getScalableColorD(frame, true, dsize);
  Descriptor desc;
  for(size_t i = 0; i < dsize; ++i)
    desc.push_back((float) scd->GetCoefficient(i));
  return desc;
}
예제 #13
0
Descriptor EdgeHistogram::extract_(MyImage *image,
				   bool makeVisRep,
				   Magick::Image *repr){
  cv::Mat &img = *image->getOpenCVMat();
  Frame* frame = new Frame(img);
  XM::EdgeHistogramDescriptor *ehd_ = Mpeg7Feature::getEdgeHistogramD(frame);
  XM::EHD *ehd = ehd_->GetEdgeHistogram();
  Descriptor desc;
  for(int i = 0; i < 80; ++i)
    desc.push_back((float) ehd->Local_Edge[i]);
  return desc;
}
double PatchMatchDescriptor::distanceDescriptor(const Descriptor& desSource, const Descriptor& desTarget, int sx, int sy, int tx, int ty) {
	double dist = 0.0;
	TextureDescriptor textSource( desSource.at(sy, sx));
	TextureDescriptor textTarget( desTarget.at(ty, tx));

	dist = textSource.distance(textTarget);

	if(dist <= 1e-10)
		dist = 0.0;

	return dist;
}
예제 #15
0
void MessageReader::onDescriptor(const Descriptor& descriptor, const char* position)
{
    if (bare.data) {
        if (descriptor.match(FOOTER_SYMBOL, FOOTER_CODE)) {
            bare.size = position - bare.data;
        }
    } else {
        if (descriptor.match(PROPERTIES_SYMBOL, PROPERTIES_CODE) || descriptor.match(APPLICATION_PROPERTIES_SYMBOL, APPLICATION_PROPERTIES_CODE)
            || descriptor.match(AMQP_SEQUENCE_SYMBOL, AMQP_SEQUENCE_CODE) || descriptor.match(AMQP_VALUE_SYMBOL, AMQP_VALUE_CODE) || descriptor.match(DATA_SYMBOL, DATA_CODE)) {
            bare.data = position;
        }
    }
}
예제 #16
0
off_t
lseek(int fd, off_t offset, int whence)
{
	Descriptor* descriptor = get_descriptor(fd);
	if (descriptor == NULL)
		RETURN_AND_SET_ERRNO(B_FILE_ERROR);

	status_t error = descriptor->Seek(offset, whence);
	if (error != B_OK)
		RETURN_AND_SET_ERRNO(B_FILE_ERROR);

	return descriptor->Offset();
}
예제 #17
0
void TrueClusterHistogram::min(const patch &descriptor,
				  Descriptor &histogram,
				  bool first){
	Descriptor::iterator h = histogram.begin();
	patch_collection::iterator c = centers.begin();
	while(h != histogram.end() && c != centers.end()){
	  float dist = descriptor.distance(*c);
	  if(first || dist < *h)
	    *h = dist;
	  h++;
	  c++;
	}
}
예제 #18
0
TEST(Descriptor, TryReadReturnsTrueIfDirectoryContainsDescriptor) {
    Descriptor descriptor;
    descriptor.num_partitions = 1;
    descriptor.map_type = Descriptor::TYPE_MAP;
    descriptor.writeToDirectory(TMPDIR);

    Descriptor read_descriptor;
    ASSERT_TRUE(Descriptor::tryReadFromDirectory(TMPDIR, &read_descriptor));
    ASSERT_EQ(descriptor.map_type, read_descriptor.map_type);
    ASSERT_EQ(descriptor.num_partitions, read_descriptor.num_partitions);
    ASSERT_EQ(descriptor.major_version, read_descriptor.major_version);
    ASSERT_EQ(descriptor.minor_version, read_descriptor.minor_version);
}
예제 #19
0
double Metric::ManhattanMetric(const Descriptor &_desc1, const Descriptor &_desc2)
{
	vector<double> d1 = _desc1.getDescriptorVector();
	vector<double> d2 = _desc2.getDescriptorVector();

	double result = 0;
	size_t length = d1.size();
	for (size_t i = 0; i < length; i++)
	{
		result += fabs(d1[i] - d2[i]);
	}

	return result;
}
예제 #20
0
void SteadyStateAlgo::describe(QString type)
{
	Descriptor d = addTypeDescription(type, "steadyState Algorithm");
	d.describeInt("popSize").limits(1, INT_MAX).def(1).help("Number of the individuals belonging to the population");
	d.describeInt("numGenerations").limits(1, INT_MAX).def(1000).help("Number of the generations of the evolutionary process");
	d.describeReal("mutRate").def(0.1).help("Mutation rate");
	d.describeReal("mutDecay").def(0.01).help("Mutation rate decay");
	d.describeReal("initMutRate").def(0.5).help("Initial mutation rate");
	d.describeObject("gaEvaluator").type("RobotExperiment").props(IsMandatory).help("Object that calculate the fitness");
	d.describeObject("genotypeTester").type("SingleGenotypeIntToEvonet").props(IsMandatory).help("Object that sets the genotype to be tested");
	d.describeSubgroup("Genotype").type("GenotypeInt").props(IsMandatory).help("Object containing the individual under evolution");
}
예제 #21
0
bool InferredType::canWatch(const ConcurrentJSLocker& locker, const Descriptor& expected)
{
    if (expected.kind() == Top)
        return false;
    
    return descriptor(locker) == expected;
}
예제 #22
0
double Metric::EuclideanMetric(const Descriptor &_desc1, const Descriptor &_desc2)
{
	vector<double> d1 = _desc1.getDescriptorVector();
	vector<double> d2 = _desc2.getDescriptorVector();

	double result = 0;
	size_t length = d1.size();
	for (size_t i = 0; i < length; i++)
	{
		double a = d1[i];
		double b = d2[i];
		result += ((a - b) * (a - b));
	}

	return sqrt(result);
}
예제 #23
0
double Metric::MaxMetric(const Descriptor &_desc1, const Descriptor &_desc2)
{
	vector<double> d1 = _desc1.getDescriptorVector();
	vector<double> d2 = _desc2.getDescriptorVector();

	double result = 0;
	size_t length = d1.size();
	for (size_t i = 0; i < length; i++)
	{
		double delta = fabs(d1[i] - d2[i]);
		if (result < delta)
			result = delta;
	}

	return result;
}
// Queries the kd tree for the nearest neighbor of 'query'.
bool FlannDescriptorKDTree::NearestNeighbor(Descriptor& query, int& nn_index,
                                            double& nn_distance) {
  if (index_ == nullptr) {
    VLOG(1) << "Index has not been built. Descriptors must be added before "
               "querying the kd tree";
    return false;
  }

  // Convert the input descriptor to the FLANN format. We can use Eigen's memory
  // here, since we will have our answer before leaving function scope.
  flann::Matrix<double> flann_query(query.data(), 1, index_->veclen());

  // Search the kd tree for the nearest neighbor to the query.
  std::vector< std::vector<int> > query_match_indices;
  std::vector< std::vector<double> > query_distances;

  const int kOneNearestNeighbor = 1;
  int num_neighbors_found = index_->knnSearch(
      flann_query, query_match_indices, query_distances, kOneNearestNeighbor,
      flann::SearchParams(flann::FLANN_CHECKS_UNLIMITED) /* no approx */);

  // If we found a nearest neighbor, assign output.
  if (num_neighbors_found > 0) {
    nn_index = query_match_indices[0][0];
    nn_distance = query_distances[0][0];
  }

  return num_neighbors_found > 0;
}
예제 #25
0
Descriptor HomogeneousTexture::extract_(MyImage *image,
					bool makeVisrep,
					Magick::Image *repr){
  cv::Mat non_gray = *image->getOpenCVMat();
  cv::Mat img = Mat( non_gray.rows, non_gray.cols, CV_8UC1);
  cvtColor(non_gray, img, CV_BGR2GRAY);
  Frame *frame = new Frame(img.rows, img.cols, false, true, false);
  frame->setGray(img);
  XM::HomogeneousTextureDescriptor *xmdesc = 
    Mpeg7Feature::getHomogeneousTextureD(frame, true);
  Descriptor desc;
  for(int i = 0; i < 62; ++i)
    desc.push_back((float) xmdesc->feature[i]);
  delete xmdesc;
  return desc;
}
예제 #26
0
        static void verify_or_upgrade_db_descriptor(DB *db, const Descriptor &descriptor,
                                                    const bool hot_index) {
            const DBT *desc = &db->cmp_descriptor->dbt;
            verify(desc->data != NULL && desc->size >= 4);

            if (desc->size == 4) {
                // existing descriptor is from before descriptors were even versioned.
                // it's only an ordering. make sure it matches, then upgrade.
                const Ordering &ordering(*reinterpret_cast<const Ordering *>(desc->data));
                const Ordering &expected(descriptor.ordering());
                verify(memcmp(&ordering, &expected, 4) == 0);
                set_db_descriptor(db, descriptor, hot_index);
            } else {
                const Descriptor existing(reinterpret_cast<const char *>(desc->data), desc->size);
                if (existing.version() < descriptor.version()) {
                    // existing descriptor is out-dated. upgrade to the current version.
                    set_db_descriptor(db, descriptor, hot_index);
                } else if (existing.version() > descriptor.version()) {
                    problem() << "Detected a \"dictionary descriptor\" version that is too new: "
                              << existing.version() << ". The highest known version is " << descriptor.version()
                              << "This data may have already been upgraded by a newer version of "
                              << "TokuMX and is now no longer usable by this version."
                              << endl << endl
                              << "The assertion failure you are about to see is intentional."
                              << endl;
                    verify(false);
                } else {
                    // same version, ensure the contents of the descriptor are correct
                    verify(existing == descriptor);
                }
            }
        }
예제 #27
0
PropertyType ObjectSchema::from_core_type(Descriptor const& table, size_t col)
{
    auto optional = table.is_nullable(col) ? PropertyType::Nullable : PropertyType::Required;
    switch (table.get_column_type(col)) {
        case type_Int:       return PropertyType::Int | optional;
        case type_Float:     return PropertyType::Float | optional;
        case type_Double:    return PropertyType::Double | optional;
        case type_Bool:      return PropertyType::Bool | optional;
        case type_String:    return PropertyType::String | optional;
        case type_Binary:    return PropertyType::Data | optional;
        case type_Timestamp: return PropertyType::Date | optional;
        case type_Mixed:     return PropertyType::Any | optional;
        case type_Link:      return PropertyType::Object | PropertyType::Nullable;
        case type_LinkList:  return PropertyType::Object | PropertyType::Array;
        case type_Table:     return from_core_type(*table.get_subdescriptor(col), 0) | PropertyType::Array;
        default: REALM_UNREACHABLE();
    }
}
예제 #28
0
 // set a descriptor for the given dictionary.
 static void set_db_descriptor(DB *db, const Descriptor &descriptor,
                               const bool hot_index) {
     const int flags = DB_UPDATE_CMP_DESCRIPTOR | (hot_index ? DB_IS_HOT_INDEX : 0);
     DBT desc = descriptor.dbt();
     const int r = db->change_descriptor(db, cc().txn().db_txn(), &desc, flags);
     if (r != 0) {
         handle_ydb_error_fatal(r);
     }
 }
예제 #29
0
double Descriptor::getDistance(const Descriptor &descriptor) const
{
    double result = 0;
    for(int i = 0; i < histogramsCount; i++){
        for(int j = 0; j < binCount; j++){
            result += pow((descriptor.getHistValue(i,j) - getHistValue(i,j)),2);
        }
    }
    return sqrt(result);
}
예제 #30
0
  QByteArray BulkRound::GenerateXorMessage(int idx)
  {
    if(_my_idx == idx) {
      return _my_xor_message;
    }

    Descriptor descriptor = _descriptors[idx];
    QByteArray seed = GetDhKey().GetSharedSecret(descriptor.PublicDh());

    QByteArray msg(descriptor.Length(), 0);
    CryptoRandom(seed).GenerateBlock(msg);
    QByteArray hash = Hash().ComputeHash(msg);

    if(descriptor.XorMessageHashes()[GetGroup().GetIndex(GetLocalId())] != hash) {
      qWarning() << "Invalid hash";
    }

    return msg;
  }