Ejemplo n.º 1
0
/**
 * Set a breakpoint if this is the first one at this location.
 */
static jvmtiError
setBreakpoint(HandlerNode *node)
{
    jvmtiError error = JVMTI_ERROR_NONE;
    Filter *filter;

    filter = findFilter(node, JDWP_REQUEST_MODIFIER(LocationOnly));
    if (filter == NULL) {
        /* bp event with no location filter */
        error = AGENT_ERROR_INTERNAL;
    } else {
        LocationFilter *lf = &(filter->u.LocationOnly);

        /* if this is the first handler for this
         * location, set bp at JVMTI level
         */
        if (!eventHandlerRestricted_iterator(
                EI_BREAKPOINT, matchBreakpoint, lf)) {
            LOG_LOC(("SetBreakpoint at location: method=%p,location=%d",
                        lf->method, (int)lf->location));
            error = JVMTI_FUNC_PTR(gdata->jvmti,SetBreakpoint)
                        (gdata->jvmti, lf->method, lf->location);
        }
    }
    return error;
}
Ejemplo n.º 2
0
bool
PaceFilter::setup()
{
  if (findFilter("queue", true) == nullptr
      && std::dynamic_pointer_cast<LinkConnect>(conn.lock()) != nullptr)
    ERRORPRINTF(t, E_NOTICE, "The 'pace' filter without a queue acts globally.");
  if (!Filter::setup())
    return false;
  delay = cfg->value("delay",15)/1000.;
  if (delay <= 0)
    {
      ERRORPRINTF(t, E_ERROR, "The delay must be >0");
      return false;
    }
  byte_delay = cfg->value("delay-per-byte",1)/1000.;
  if (byte_delay < 0)
    {
      ERRORPRINTF(t, E_ERROR, "The delay must be >0");
      return false;
    }
  factor_in = cfg->value("incoming",0.75);
  if (factor_in < 0)
    {
      ERRORPRINTF(t, E_ERROR, "The factor for incoming packets must be >=0");
      return false;
    }
  return true;
}
Ejemplo n.º 3
0
/**
 * Clear a watchpoint if this is the last one on this field.
 */
static jvmtiError
clearWatchpoint(HandlerNode *node)
{
    jvmtiError error = JVMTI_ERROR_NONE;
    Filter *filter;

    filter = findFilter(node, JDWP_REQUEST_MODIFIER(FieldOnly));
    if (filter == NULL) {
        /* event with no field filter */
        error = AGENT_ERROR_INTERNAL;
    } else {
        FieldFilter *ff = &(filter->u.FieldOnly);

        /* if this is the last handler for this
         * field, clear wp at JVMTI level
         */
        if (!eventHandlerRestricted_iterator(
                NODE_EI(node), matchWatchpoint, ff)) {
            error = (NODE_EI(node) == EI_FIELD_ACCESS) ?
                JVMTI_FUNC_PTR(gdata->jvmti,ClearFieldAccessWatch)
                        (gdata->jvmti, ff->clazz, ff->field) :
                JVMTI_FUNC_PTR(gdata->jvmti,ClearFieldModificationWatch)
                                (gdata->jvmti, ff->clazz, ff->field);
        }
    }
    return error;
}
Ejemplo n.º 4
0
/**
 * Clear a watchpoint if this is the last one on this field.
 */
static jint
clearWatchpoint(HandlerNode *node)
{
    jint error = JVMDI_ERROR_NONE;
    Filter *filter;

    filter = findFilter(node, JDWP_REQUEST_MODIFIER(FieldOnly));
    if (filter == NULL) {
        /* event with no field filter */
        error = JVMDI_ERROR_INTERNAL; 
    } else {
        FieldFilter *ff = &(filter->u.FieldOnly);

        /* if this is the last handler for this 
         * field, clear wp at jvmdi level 
         */
        if (!eventHandlerRestricted_iterator(
                KIND(node), matchWatchpoint, ff)) {
            error = (KIND(node) == JVMDI_EVENT_FIELD_ACCESS) ?
                jvmdi->ClearFieldAccessWatch(ff->clazz, 
                                             ff->field) :
                jvmdi->ClearFieldModificationWatch(ff->clazz,
                                                   ff->field);
        }
    }
    return error;
}
Ejemplo n.º 5
0
void 
filteredDataServer::cancelSubRequest (fdsSubscriber sub, metricHandle met, focus foc)
{
  // find the pending enable request for this met/focus pair
  filter *subfilter = findFilter(met, foc);
  assert (subfilter);

  if (subfilter->numConsumers == 1) {
    // this was the only pending request; change status
    subfilter->status = filter::Inactive;
  }
  subfilter->rmConsumer(sub);
}
Ejemplo n.º 6
0
bool SvgParser::parseFilter(const KoXmlElement &e, const KoXmlElement &referencedBy)
{
    SvgFilterHelper filter;

    // Use the filter that is referencing, or if there isn't one, the original filter
    KoXmlElement b;
    if (!referencedBy.isNull())
        b = referencedBy;
    else
        b = e;

    // check if we are referencing another filter
    if (e.hasAttribute("xlink:href")) {
        QString href = e.attribute("xlink:href").mid(1);
        if (! href.isEmpty()) {
            // copy the referenced filter if found
            SvgFilterHelper *refFilter = findFilter(href);
            if (refFilter)
                filter = *refFilter;
        }
    } else {
        filter.setContent(b);
    }

    if (b.attribute("filterUnits") == "userSpaceOnUse")
        filter.setFilterUnits(SvgFilterHelper::UserSpaceOnUse);
    if (b.attribute("primitiveUnits") == "objectBoundingBox")
        filter.setPrimitiveUnits(SvgFilterHelper::ObjectBoundingBox);

    // parse filter region rectangle
    if (filter.filterUnits() == SvgFilterHelper::UserSpaceOnUse) {
        filter.setPosition(QPointF(parseUnitX(b.attribute("x")),
                                   parseUnitY(b.attribute("y"))));
        filter.setSize(QSizeF(parseUnitX(b.attribute("width")),
                              parseUnitY(b.attribute("height"))));
    } else {
        // x, y, width, height are in percentages of the object referencing the filter
        // so we just parse the percentages
        filter.setPosition(QPointF(SvgUtil::fromPercentage(b.attribute("x", "-0.1")),
                                   SvgUtil::fromPercentage(b.attribute("y", "-0.1"))));
        filter.setSize(QSizeF(SvgUtil::fromPercentage(b.attribute("width", "1.2")),
                              SvgUtil::fromPercentage(b.attribute("height", "1.2"))));
    }

    m_filters.insert(b.attribute("id"), filter);

    return true;
}
Ejemplo n.º 7
0
// this assumes 'filterPath' is a file path, so it ignores the final component
pugi::xml_node VcProj::Filters::createAndFindFiltersPath( std::string filterPath )
{
	QStringList items = QString::fromUtf8( filterPath.c_str() ).split( '/' );
	QString curPath;
	pugi::xml_node result;
	for( QStringList::Iterator itemIt = items.begin(); (items.length() > 1) && (itemIt != (items.end()-1)); ++itemIt ) {
		curPath += *itemIt;
		result = findFilter( curPath.toStdString() );
		if( ! result ) {
			result = addFilter( curPath.toStdString(), "" );
		}
		curPath += '\\';
	}

	return result;
}
Ejemplo n.º 8
0
bool
QueueFilter::setup()
{
  if(std::dynamic_pointer_cast<LinkConnect>(conn.lock()) == nullptr)
    {
      ERRORPRINTF(t, E_ERROR, "You can't use the 'queue' filter globally");
      return false;
    }
  if (findFilter("queue", true) != nullptr)
    {
      ERRORPRINTF(t, E_WARNING, "Two queue filters on a link does not make sense");
      return false;
    }
  if (!Filter::setup())
    return false;
  // XXX options?
  return true;
}
Ejemplo n.º 9
0
bool
TPUARTwrap::setup()
{
  ackallgroup = cfg->value("ack-group",false);
  ackallindividual = cfg->value("ack-individual",false);
  monitor = cfg->value("monitor",false);

  if (cfg->value("device","").length() > 0)
    {
      if (cfg->value("ip-address","").length() > 0 ||
          cfg->value("port",-1) != -1)
        {
          ERRORPRINTF (t, E_ERROR, "Don't specify both device and IP options!");
          return false;
        }
      iface = create_serial(this, cfg);
    }
  else
    {
      if (cfg->value("baudrate",-1) != -1)
        {
          ERRORPRINTF (t, E_ERROR, "Don't specify both device and IP options!");
          return false;
        }
      iface = new LLtcp(this, cfg);
    }

  if (t->ShowPrint(0))
    iface = new LLlog (this,cfg, iface);

  FilterPtr single = findFilter("single");
  if (single != nullptr)
    {
      std::shared_ptr<NatL2Filter> f = std::dynamic_pointer_cast<NatL2Filter>(single);
      if (f)
        my_addr = f->addr;
    }
  
  if (!LowLevelFilter::setup())
    return false;

  return true;
}
Ejemplo n.º 10
0
// 
// all filters live until end of Search, although no subscribers may remain
// if subscriber count goes to 0, disable raw data
//
void 
filteredDataServer::endSubscription(fdsSubscriber sub, metricHandle met, focus foc)
{
  filter *curr = findFilter (met, foc);
  if (!curr) 
    // invalid request 
    return;
  int subsLeft = curr->rmConsumer(sub);
  if (subsLeft == 0) {
    // we just removed the only subscriber
    inActivateFilter(curr);
  }
#ifdef PCDEBUG
  if (performanceConsultant::printDataCollection) {
    cout << "FDS: subscription ended: " << curr->getMI() << "numLeft=" << subsLeft 
         << endl; 
  }
#endif
}
Ejemplo n.º 11
0
//
// addFilter
//
// Add a filter to the list
//
bool 
Filter::addFilter(const QString& filterPattern)
{
  FilterItem* re;

  // no duplicates allowed
  if (findFilter(filterPattern))
    return false;

  re = new FilterItem(filterPattern, m_caseSensitive);

  // append it to the end of the list
  m_filterItems.append(re);

#ifdef DEBUG_FILTER
  seqDebug("Added Filter '%s'", (const char*)filterPattern);
#endif

 return re->valid(); 
} // end addFilter
Ejemplo n.º 12
0
//
// addFilter
//
// Add a filter to the list
//
bool 
Filter::addFilter(const QString& filterPattern)
{
  FilterItem* re;

  // no duplicates allowed
  if (findFilter(filterPattern))
    return false;

  re = new FilterItem(filterPattern, m_cFlags);

  // append it to the end of the list
  m_filterItems.append(re);

#ifdef DEBUG_FILTER
printf("Added Filter '%s'\n", filterPattern);
#endif

 return re->valid(); 
} // end addFilter
Ejemplo n.º 13
0
void TargetTracker::tracking(std::vector<TargetState> states)
{
    std::vector<TargetState>::const_iterator iter;
    TargetState tState;
    KalmanFilter *filter;
    SingleTarget *target;
    qDebug() << "测量值:";

    for (iter = states.begin(); iter != states.end(); ++iter)
    {
        tState = *iter;
        tState.state.print();

        filter = findFilter(tState.groupId, tState.targetId);
        target = findTarget(tState.groupId, tState.targetId);
        if (target == NULL) continue;
        if (filter == NULL) continue;
        if (target->getStateCount() == 0) {
            // 第一次获取目标的状态,直接保存,不做任何计算。
            target->addState(tState.state);
            filter->setState(tState.state.getData());
            continue;
        }
        //计算一步预测值
        Matrix matrix = filter->estimate();
        // 根据测量值更新预测数据
        filter->updateByMeasure(tState.state.getData());
        State s;
        s.setData(matrix);
        s.setTime(tState.time);
        target->addState(s);
    }

    //项目验收后去掉
    initMessage();

    printTargetGroups();
}
Ejemplo n.º 14
0
/**
 * Clear a breakpoint if this is the last one at this location.
 */
static jint
clearBreakpoint(HandlerNode *node)
{
    jint error = JVMDI_ERROR_NONE;
    Filter *filter;

    filter = findFilter(node, JDWP_REQUEST_MODIFIER(LocationOnly));
    if (filter == NULL) {
        /* bp event with no location filter */
        error = JVMDI_ERROR_INTERNAL; 
    } else {
        LocationFilter *lf = &(filter->u.LocationOnly);

        /* if this is the last handler for this 
         * location, clear bp at jvmdi level 
         */
        if (!eventHandlerRestricted_iterator(
                JVMDI_EVENT_BREAKPOINT, matchBreakpoint, lf)) {
            error = jvmdi->ClearBreakpoint(lf->clazz, lf->method, 
                                           lf->location);
        }
    }
    return error;
}
Ejemplo n.º 15
0
SvgFilterHelper* SvgParser::findFilter(const QString &id, const QString &href)
{
    // check if filter was already parsed, and return it
    if (m_filters.contains(id))
        return &m_filters[ id ];

    // check if filter was stored for later parsing
    if (!m_context.hasDefinition(id))
        return 0;

    const KoXmlElement &e = m_context.definition(id);
    if (e.childNodesCount() == 0) {
        QString mhref = e.attribute("xlink:href").mid(1);

        if (m_context.hasDefinition(mhref))
            return findFilter(mhref, id);
        else
            return 0;
    } else {
        // ok parse filter now
        if (! parseFilter(m_context.definition(id), m_context.definition(href)))
            return 0;
    }

    // return successfully parsed filter or NULL
    QString n;
    if (href.isEmpty())
        n = id;
    else
        n = href;

    if (m_filters.contains(n))
        return &m_filters[ n ];
    else
        return 0;
}
Ejemplo n.º 16
0
void
filteredDataServer::addSubscription(fdsSubscriber sub,
				    metricHandle mh,
				    focus f,
				    filterType ft,
				    bool flag)
{
  // is there already a filter for this met/focus pair?
  filter *subfilter = findFilter(mh, f);

  if (subfilter) {
    if (flag) subfilter->setcostFlag();
    // add subscriber to filter, which already exists

    if (subfilter->status == filter::Active) {
      subfilter->addConsumer (sub);
      subfilter->sendEnableReply(mh, f, subfilter->getMI(), true);
    } else if (subfilter->status == filter::Inactive) {
      subfilter->addConsumer (sub);
      subfilter->wakeUp();
    } else if (subfilter->status == filter::ActivationRequestPending) {
      subfilter->addConsumer(sub);
    }
    return;
  }

  // this is first request received for this met focus pair; construct new filter
  if (ft == nonfiltering)
    subfilter = new valFilter (this, mh, f, flag);
  else
    subfilter = new avgFilter (this, mh, f, flag);
  AllDataFilters += subfilter;
  (*(miIndex[mh])) [f] = subfilter;  
  subfilter->addConsumer(sub);
  subfilter->wakeUp();
}
Ejemplo n.º 17
0
void
filteredDataServer::newDataEnabled(pdvector<metricInstInfo> *newlyEnabled)
{
  //** cache focus name here??
  filter *curr = NULL;
  metricInstInfo *miicurr;
  unsigned nesz = newlyEnabled->size();
  for (unsigned i = 0; i < nesz; i++) {
    miicurr = &((*newlyEnabled)[i]);

#ifdef PCDEBUG
    cout << "enable REPLY for m=" << miicurr->m_id << " f=" << miicurr->r_id 
      << " mi=" << miicurr->mi_id  
      << "  enabled=" << miicurr->successfully_enabled << endl;
#endif

    bool beenEnabled = DataFilters.find(miicurr->mi_id, curr);

    if (beenEnabled && curr) {
      // this request was part of a PC pause; there is no pending
      // record and metricInstanceHandle is unchanged
      curr->sendEnableReply(miicurr->m_id, miicurr->r_id, 
			    miicurr->mi_id, miicurr->successfully_enabled, false);
      return;
    } 
    // mihandle not in use; get filter for this mh/f pair
    filter *curr = findFilter(miicurr->m_id, miicurr->r_id);
    if (!curr) {
      //**
      //cout << "UH-OH, FILTER NOT FOUND! mh=" << miicurr->m_id << " f=" 
	//<< miicurr->r_id << endl;
      return;
    }
    if (curr->status != filter::ActivationRequestPending) {
      // this enable request was cancelled while it was being handled by the dm
      // so we need to send back an explicit cancel request
      if (phType == GlobalPhase)
	dataMgr->disableDataAndClearPersistentData
	  (performanceConsultant::pstream,0,miicurr->mi_id,phType,true,false);
      else
	dataMgr->disableDataAndClearPersistentData
	  (performanceConsultant::pstream,0,miicurr->mi_id,phType,false,true);

#ifdef PCDEBUG
      cout << "PCdisableData: m=" << miicurr->m_id << " f=" << miicurr->r_id 
	<< " mi=" << miicurr->mi_id << endl;
#endif
    } else {
      if( miicurr->deferred )
      {
        curr->sendEnableReply( miicurr->mi_id,  miicurr->r_id,
                                    0,
                                    false,
                                    true );     // this one has been deferred
      }
      else if (miicurr->successfully_enabled) {
	curr->mi = miicurr->mi_id;
	DataFilters[(fdsDataID) curr->mi] = curr;
	curr->status = filter::Active;
	curr->sendEnableReply(miicurr->m_id, miicurr->r_id, miicurr->mi_id, true);
      } else { 
        // enable failed 
        //**
        curr->sendEnableReply(miicurr->m_id, miicurr->r_id,
                                0,
                                false, false, miicurr->emsg );
        curr->status = filter::Inactive;
      }
    }
  }

#ifdef PCDEBUG
  if (performanceConsultant::printDataCollection) 
    printPendings();
    ;
#endif
}
Ejemplo n.º 18
0
void
EIBNetIPTunnel::read_cb (EIBNetIPPacket *p1)
{
  LDataPtr c;

  switch (p1->service)
    {
    case CONNECTION_RESPONSE:
      {
        EIBnet_ConnectResponse cresp;
        if (mod)
          goto err;
        if (parseEIBnet_ConnectResponse (*p1, cresp))
          {
            TRACEPRINTF (t, 1, "Recv wrong connection response");
            break;
          }
        if (cresp.status != 0)
          {
            TRACEPRINTF (t, 1, "Connect failed with error %02X", cresp.status);
            if (cresp.status == 0x23 && support_busmonitor && monitor)
              {
                TRACEPRINTF (t, 1, "Disable busmonitor support");
                restart();
                return;
                // support_busmonitor = false;
                // connect_busmonitor = false;

                // EIBnet_ConnectRequest creq = get_creq();
                // creq.CRI[1] = 0x02;

                // EIBNetIPPacket p = creq.ToPacket ();
                // TRACEPRINTF (t, 1, "Connectretry");
                // sock->Send (p, caddr);
                // conntimeout.start(10,0);
              }
            break;
          }
        if (cresp.CRD.size() != 3)
          {
            TRACEPRINTF (t, 1, "Recv wrong connection response");
            break;
          }

        auto cn = std::dynamic_pointer_cast<LinkConnect>(conn.lock());
        if (cn != nullptr)
          cn->setAddress((cresp.CRD[1] << 8) | cresp.CRD[2]);
        auto f = findFilter("single");
        if (f != nullptr)
          std::dynamic_pointer_cast<NatL2Filter>(f)->setAddress((cresp.CRD[1] << 8) | cresp.CRD[2]);

        // TODO else reject
        daddr = cresp.daddr;
        if (!cresp.nat)
          {
            if (NAT)
              {
                daddr.sin_addr = caddr.sin_addr;
                if (dataport != 0)
                  daddr.sin_port = htons (dataport);
              }
          }
        channel = cresp.channel;
        mod = 1; trigger.send();
        sno = 0;
        rno = 0;
        sock->recvaddr2 = daddr;
        sock->recvall = 3;
        if (heartbeat_time)
          conntimeout.start(heartbeat_time,0);
        heartbeat = 0;
        BusDriver::start();
        break;
      }
    case TUNNEL_REQUEST:
      {
        EIBnet_TunnelRequest treq;
        if (mod == 0)
          {
            TRACEPRINTF (t, 1, "Not connected");
            goto err;
          }
        if (parseEIBnet_TunnelRequest (*p1, treq))
          {
            TRACEPRINTF (t, 1, "Invalid request");
            break;
          }
        if (treq.channel != channel)
          {
            TRACEPRINTF (t, 1, "Not for us (treq.chan %d != %d)", treq.channel,channel);
            break;
          }
        if (((treq.seqno + 1) & 0xff) == rno)
          {
            EIBnet_TunnelACK tresp;
            tresp.status = 0;
            tresp.channel = channel;
            tresp.seqno = treq.seqno;

            EIBNetIPPacket p = tresp.ToPacket ();
            sock->Send (p, daddr);
            sock->recvall = 0;
            break;
          }
        if (treq.seqno != rno)
          {
            TRACEPRINTF (t, 1, "Wrong sequence %d<->%d",
                          treq.seqno, rno);
            if (treq.seqno < rno)
              treq.seqno += 0x100;
            if (treq.seqno >= rno + 5)
              restart();
            break;
          }
        rno++;
        if (rno > 0xff)
          rno = 0;
        EIBnet_TunnelACK tresp;
        tresp.status = 0;
        tresp.channel = channel;
        tresp.seqno = treq.seqno;

        EIBNetIPPacket p = tresp.ToPacket ();
        sock->Send (p, daddr);

        //Confirmation
        if (treq.CEMI[0] == 0x2E)
          {
            if (mod == 3)
              {
                mod = 1; trigger.send();
              }
            break;
          }
        if (treq.CEMI[0] == 0x2B)
          {
            LBusmonPtr l2 = CEMI_to_Busmonitor (treq.CEMI, std::dynamic_pointer_cast<Driver>(shared_from_this()));
            recv_L_Busmonitor (std::move(l2));
            break;
          }
        if (treq.CEMI[0] != 0x29)
          {
            TRACEPRINTF (t, 1, "Unexpected CEMI Type %02X",
                          treq.CEMI[0]);
            break;
          }
        c = CEMI_to_L_Data (treq.CEMI, t);
        if (c)
          {
            if (!monitor)
              recv_L_Data (std::move(c));
            else
              {
                LBusmonPtr p1 = LBusmonPtr(new L_Busmonitor_PDU ());
                p1->pdu = c->ToPacket ();
                recv_L_Busmonitor (std::move(p1));
              }
            break;
          }
        TRACEPRINTF (t, 1, "Unknown CEMI");
        break;
      }
    case TUNNEL_RESPONSE:
      {
        EIBnet_TunnelACK tresp;
        if (mod == 0)
          {
            TRACEPRINTF (t, 1, "Not connected");
            goto err;
          }
        if (parseEIBnet_TunnelACK (*p1, tresp))
          {
            TRACEPRINTF (t, 1, "Invalid response");
            break;
          }
        if (tresp.channel != channel)
          {
            TRACEPRINTF (t, 1, "Not for us (tresp.chan %d != %d)", tresp.channel,channel);
            break;
          }
        if (tresp.seqno != sno)
          {
            TRACEPRINTF (t, 1, "Wrong sequence %d<->%d",
                          tresp.seqno, sno);
            break;
          }
        if (tresp.status)
          {
            TRACEPRINTF (t, 1, "Error in ACK %d", tresp.status);
            break;
          }
        if (mod == 2)
          {
            sno++;
            if (sno > 0xff)
              sno = 0;
            out.clear();
            send_Next();
            mod = 1; trigger.send();
            retry = 0;
          }
        else
          TRACEPRINTF (t, 1, "Unexpected ACK mod=%d",mod);
        break;
      }
    case CONNECTIONSTATE_RESPONSE:
      {
        EIBnet_ConnectionStateResponse csresp;
        if (parseEIBnet_ConnectionStateResponse (*p1, csresp))
          {
            TRACEPRINTF (t, 1, "Invalid response");
            break;
          }
        if (csresp.channel != channel)
          {
            TRACEPRINTF (t, 1, "Not for us (csresp.chan %d != %d)", csresp.channel,channel);
            break;
          }
        if (csresp.status == 0)
          {
            if (heartbeat > 0)
              {
                heartbeat = 0;
                TRACEPRINTF (t, 1, "got Connection State Response");
              }
            else
              TRACEPRINTF (t, 1, "Duplicate Connection State Response");
          }
        else if (csresp.status == 0x21)
          {
            TRACEPRINTF (t, 1, "Connection State Response: not connected");
            restart();
          }
        else
          {
            TRACEPRINTF (t, 1, "Connection State Response Error %02x", csresp.status);
            errored();
          }
        break;
      }
    case DISCONNECT_REQUEST:
      {
        EIBnet_DisconnectRequest dreq;
        if (mod == 0)
          {
            TRACEPRINTF (t, 1, "Not connected");
            goto err;
          }
        if (parseEIBnet_DisconnectRequest (*p1, dreq))
          {
            TRACEPRINTF (t, 1, "Invalid request");
            break;
          }
        if (dreq.channel != channel)
          {
            TRACEPRINTF (t, 1, "Not for us (dreq.chan %d != %d)", dreq.channel,channel);
            break;
          }

        EIBnet_DisconnectResponse dresp;
        dresp.channel = channel;
        dresp.status = 0;

        EIBNetIPPacket p = dresp.ToPacket ();
        t->TracePacket (1, "SendDis", p.data);
        sock->Send (p, caddr);
        sock->recvall = 0;
        mod = 0;
        conntimeout.start(0.1,0);
        break;
      }
    case DISCONNECT_RESPONSE:
      {
        EIBnet_DisconnectResponse dresp;
        if (mod == 0)
          {
            TRACEPRINTF (t, 1, "Not connected");
            break;
          }
        if (parseEIBnet_DisconnectResponse (*p1, dresp))
          {
            TRACEPRINTF (t, 1, "Invalid request");
            break;
          }
        if (dresp.channel != channel)
          {
            TRACEPRINTF (t, 1, "Not for us (dresp.chan %d != %d)", dresp.channel,channel);
            break;
          }
        mod = 0;
        sock->recvall = 0;
        TRACEPRINTF (t, 1, "Disconnected");
        restart();
        conntimeout.start(0.1,0);
        break;
      }
    default:
    err:
      TRACEPRINTF (t, 1, "Recv unexpected service %04X", p1->service);
    }
  delete p1;
}
Ejemplo n.º 19
0
void SvgParser::applyFilter(KoShape *shape)
{
    SvgGraphicsContext *gc = m_context.currentGC();
    if (! gc)
        return;

    if (gc->filterId.isEmpty())
        return;

    SvgFilterHelper *filter = findFilter(gc->filterId);
    if (! filter)
        return;

    KoXmlElement content = filter->content();

    // parse filter region
    QRectF bound(shape->position(), shape->size());
    // work on bounding box without viewbox tranformation applied
    // so user space coordinates of bounding box and filter region match up
    bound = gc->viewboxTransform.inverted().mapRect(bound);

    QRectF filterRegion(filter->position(bound), filter->size(bound));

    // convert filter region to boundingbox units
    QRectF objectFilterRegion;
    objectFilterRegion.setTopLeft(SvgUtil::userSpaceToObject(filterRegion.topLeft(), bound));
    objectFilterRegion.setSize(SvgUtil::userSpaceToObject(filterRegion.size(), bound));

    KoFilterEffectLoadingContext context(m_context.xmlBaseDir());
    context.setShapeBoundingBox(bound);
    // enable units conversion
    context.enableFilterUnitsConversion(filter->filterUnits() == SvgFilterHelper::UserSpaceOnUse);
    context.enableFilterPrimitiveUnitsConversion(filter->primitiveUnits() == SvgFilterHelper::UserSpaceOnUse);

    KoFilterEffectRegistry *registry = KoFilterEffectRegistry::instance();

    KoFilterEffectStack *filterStack = 0;

    QSet<QString> stdInputs;
    stdInputs << "SourceGraphic" << "SourceAlpha";
    stdInputs << "BackgroundImage" << "BackgroundAlpha";
    stdInputs << "FillPaint" << "StrokePaint";

    QMap<QString, KoFilterEffect*> inputs;

    // create the filter effects and add them to the shape
    for (KoXmlNode n = content.firstChild(); !n.isNull(); n = n.nextSibling()) {
        KoXmlElement primitive = n.toElement();
        KoFilterEffect *filterEffect = registry->createFilterEffectFromXml(primitive, context);
        if (!filterEffect) {
            debugFlake << "filter effect" << primitive.tagName() << "is not implemented yet";
            continue;
        }

        const QString input = primitive.attribute("in");
        if (!input.isEmpty()) {
            filterEffect->setInput(0, input);
        }
        const QString output = primitive.attribute("result");
        if (!output.isEmpty()) {
            filterEffect->setOutput(output);
        }

        QRectF subRegion;
        // parse subregion
        if (filter->primitiveUnits() == SvgFilterHelper::UserSpaceOnUse) {
            const QString xa = primitive.attribute("x");
            const QString ya = primitive.attribute("y");
            const QString wa = primitive.attribute("width");
            const QString ha = primitive.attribute("height");

            if (xa.isEmpty() || ya.isEmpty() || wa.isEmpty() || ha.isEmpty()) {
                bool hasStdInput = false;
                bool isFirstEffect = filterStack == 0;
                // check if one of the inputs is a standard input
                foreach(const QString &input, filterEffect->inputs()) {
                    if ((isFirstEffect && input.isEmpty()) || stdInputs.contains(input)) {
                        hasStdInput = true;
                        break;
                    }
                }
                if (hasStdInput || primitive.tagName() == "feImage") {
                    // default to 0%, 0%, 100%, 100%
                    subRegion.setTopLeft(QPointF(0, 0));
                    subRegion.setSize(QSizeF(1, 1));
                } else {
                    // defaults to bounding rect of all referenced nodes
                    foreach(const QString &input, filterEffect->inputs()) {
                        if (!inputs.contains(input))
                            continue;

                        KoFilterEffect *inputFilter = inputs[input];
                        if (inputFilter)
                            subRegion |= inputFilter->filterRect();
                    }
                }
            } else {
                const qreal x = parseUnitX(xa);
                const qreal y = parseUnitY(ya);
                const qreal w = parseUnitX(wa);
                const qreal h = parseUnitY(ha);
                subRegion.setTopLeft(SvgUtil::userSpaceToObject(QPointF(x, y), bound));
                subRegion.setSize(SvgUtil::userSpaceToObject(QSizeF(w, h), bound));
            }
        } else {