Beispiel #1
0
bool TextEditorRemoteNode::deinitialise()
{
	disconnect( mPinOutputText->qobject(), SIGNAL(linked(QSharedPointer<fugio::PinInterface>)), this, SLOT(textLinked(QSharedPointer<fugio::PinInterface>)) );
	disconnect( mPinOutputText->qobject(), SIGNAL(unlinked(QSharedPointer<fugio::PinInterface>)), this, SLOT(textUninked(QSharedPointer<fugio::PinInterface>)) );

	return( NodeControlBase::deinitialise() );
}
rmc_noinline
optional<T> MSQueue<T>::dequeue() {
    auto guard = Epoch::pin();

    MSQueueNode *head, *next;

    for (;;) {
        head = this->head_;
        smp_mb();
        next = head->next_;

        // Consistency check; see note above
        if (head != this->head_) continue;

        // Is the queue empty?
        if (next == nullptr) {
            return optional<T>{};
        } else {
            // OK, now we try to actually read the thing out.
            smp_mb();
            if (this->head_.compare_exchange_weak(head, next)) {
                break;
            }
        }
    }

    // OK, everything set up.
    // next contains the value we are reading
    // head can be freed
    guard.unlinked(head);
    optional<T> ret(std::move(next->data_));
    next->data_ = optional<T>{}; // destroy the object

    return ret;
}
optional<T> TStack<T>::pop() {
    auto guard = Epoch::pin();
    TStackNode *node = stack_.popNode();

    if (!node) return optional<T>{};

    optional<T> ret(std::move(node->data_));
    node->data_ = optional<T>{}; // destroy the object
    guard.unlinked(node);

    return ret;
}
Beispiel #4
0
bool TextEditorRemoteNode::initialise()
{
	if( !NodeControlBase::initialise() )
	{
		return( false );
	}

	connect( mPinOutputText->qobject(), SIGNAL(linked(QSharedPointer<fugio::PinInterface>)), this, SLOT(textLinked(QSharedPointer<fugio::PinInterface>)) );
	connect( mPinOutputText->qobject(), SIGNAL(unlinked(QSharedPointer<fugio::PinInterface>)), this, SLOT(textUninked(QSharedPointer<fugio::PinInterface>)) );

	return( true );
}
rmc_noinline
optional<T> MSQueue<T>::dequeue() {
    auto guard = Epoch::pin();

    // Core message passing: reading the data out of the node comes
    // after getting the pointer to it.
    XEDGE(get_next, node_use);
    // Make sure we see at least head's init
    XEDGE(get_head, get_next);
    // Need to make sure anything visible through the next pointer
    // stays visible when it gets republished at the head or tail
    VEDGE(get_next, dequeue);

    lf_ptr<MSQueueNode> head, next;

    for (;;) {
        head = L(get_head, this->head_);
        next = L(get_next, head->next_);

        // Consistency check; see note above
        if (head != this->head_) continue;

        // Is the queue empty?
        if (next == nullptr) {
            return optional<T> {};
        } else {
            // OK, now we try to actually read the thing out.
            if (L(dequeue, this->head_.compare_exchange_weak(head, next))) {
                break;
            }
        }
    }

    LPOST(node_use);

    // OK, everything set up.
    // next contains the value we are reading
    // head can be freed
    guard.unlinked(head);
    optional<T> ret(std::move(next->data_));
    next->data_ = optional<T> {}; // destroy the object

    return ret;
}
Beispiel #6
0
TextEditorRemoteNode::TextEditorRemoteNode( QSharedPointer<fugio::NodeInterface> pNode )
	: NodeControlBase( pNode ), mLastTime( 0 )
{
	FUGID( PIN_INPUT_PACKETS, "9e154e12-bcd8-4ead-95b1-5a59833bcf4e" );
	FUGID( PIN_INPUT_TEXT, "1b5e9ce8-acb9-478d-b84b-9288ab3c42f5" );
	FUGID( PIN_OUTPUT_PACKETS, "261cc653-d7fa-4c34-a08b-3603e8ae71d5" );
	FUGID( PIN_OUTPUT_TEXT, "249f2932-f483-422f-b811-ab679f006381" );

	mPinInputPackets = pinInput( "Packets", PIN_INPUT_PACKETS );

	mValInputText = pinInput<fugio::SyntaxErrorInterface *>( "Text", mPinInputText, PID_SYNTAX_ERROR, PIN_INPUT_TEXT );

	mValOutputPackets = pinOutput<fugio::VariantInterface *>( "Packets", mPinOutputPackets, PID_BYTEARRAY, PIN_OUTPUT_PACKETS );

	mValOutputText = pinOutput<fugio::VariantInterface *>( "Text", mPinOutputText, PID_STRING, PIN_OUTPUT_TEXT );

	connect( mPinOutputText->qobject(), SIGNAL(linked(QSharedPointer<fugio::PinInterface>)), this, SLOT(textLinked(QSharedPointer<fugio::PinInterface>)) );
	connect( mPinOutputText->qobject(), SIGNAL(unlinked(QSharedPointer<fugio::PinInterface>)), this, SLOT(textUninked(QSharedPointer<fugio::PinInterface>)) );
}
// Insert an object into a widgetlist, replacing an old object with
// the same key, if necessary.
// Must *not* be called from an Epoch read-side critical section.
void widget_insert(widgetlist *list, widget *obj) noexcept {
    list->write_lock.lock();
    // We needn't give any constraints on the node lookup here.  Since
    // insertions always happen under the lock, any list modifications
    // are already visible to us.
    widget *old = widget_find_fine(list, obj->key);

    // If nothing to replace we just insert it normally
    if (!old) {
        insert_before(obj, &list->head);
        list->write_lock.unlock();
        return;
    }

    replace(old, obj);
    list->write_lock.unlock();

    // Register node to be reclaimed
    auto guard = Epoch::pin();
    guard.unlinked(old);
}
rmc_noinline
optional<T> MSQueue<T>::dequeue() {
    auto guard = Epoch::pin();

    lf_ptr<MSQueueNode> head, next;

    for (;;) {
        head = this->head_.load(mo_acq);
        // This one could maybe use an acq/rel fence
        next = head->next_.load(mo_acq);

        // Consistency check; see note above
        // no ordering because just an optimization thing
        if (head != this->head_.load(mo_rlx)) continue;

        // Queue empty?
        if (next == nullptr) {
            return optional<T> {};
        } else {
            // OK, now we try to actually read the thing out.
            // release because we're republishing; don't care what we read
            if (this->head_.compare_exchange_weak(head, next,
                                                  mo_rel, mo_rlx)) {
                break;
            }
        }
    }

    // OK, everything set up.
    // next contains the value we are reading
    // head can be freed
    guard.unlinked(head);
    optional<T> ret(std::move(next->data_));
    next->data_ = optional<T> {}; // destroy the object

    return ret;
}
Beispiel #9
0
int  readdata()
/*
**--------------------------------------------------------------
**  Input:   none
**  Output:  returns error code
**  Purpose: reads contents of input data file
**--------------------------------------------------------------
*/
{
   char  line[MAXLINE+1],     /* Line from input data file       */
         wline[MAXLINE+1];    /* Working copy of input line      */
   int   sect,newsect,        /* Data sections                   */
         errcode = 0,         /* Error code                      */
         inperr,errsum;       /* Error code & total error count  */

/* Allocate input buffer */
   X = (double *) calloc(MAXTOKS, sizeof(double));
   ERRCODE(MEMCHECK(X));

   if (!errcode)
   {

   /* Initialize number of network components */
      Ntitle    = 0;
      Nnodes    = 0;
      Njuncs    = 0;
      Ntanks    = 0;
      Nlinks    = 0;
      Npipes    = 0;
      Npumps    = 0;
      Nvalves   = 0;
      Ncontrols = 0;
      Nrules    = 0;
      Ncurves   = MaxCurves;
      Npats     = MaxPats;
      PrevPat   = NULL;
      PrevCurve = NULL;
      sect      = -1;
      errsum    = 0;

   /* Read each line from input file. */
      while (fgets(line,MAXLINE,InFile) != NULL)
      {

      /* Make copy of line and scan for tokens */
         strcpy(wline,line);
         Ntokens = gettokens(wline);

       /* Skip blank lines and comments */
         if (Ntokens == 0) continue;
         if (*Tok[0] == ';') continue;

      /* Check if max. length exceeded */
         if (strlen(line) >= MAXLINE)
         {
            sprintf(Msg,ERR214);
            writeline(Msg);
            writeline(line);
            errsum++;
         }

      /* Check if at start of a new input section */
         if (*Tok[0] == '[')
         {
            newsect = findmatch(Tok[0],SectTxt);
            if (newsect >= 0)
            {
               sect = newsect;
               if (sect == _END) break;
               continue;
            }
            else
            {
                inperrmsg(201,sect,line);
                errsum++;
                break;
            }
         }

      /* Otherwise process next line of input in current section */
         else
         {
            inperr = newline(sect,line);
            if (inperr > 0)
            {
               inperrmsg(inperr,sect,line);
               errsum++;
            }
         }

      /* Stop if reach end of file or max. error count */
         if (errsum == MAXERRS) break;
      }   /* End of while */

   /* Check for errors */
      if (errsum > 0)  errcode = 200;
   }

/* Check for unlinked nodes */
   if (!errcode) errcode = unlinked();

/* Get pattern & curve data from temp. lists */
   if (!errcode) errcode = getpatterns();
   if (!errcode) errcode = getcurves();
   if (!errcode) errcode = getpumpparams();

/* Free input buffer */
   free(X);
   return(errcode);

}                        /*  End of readdata  */
Beispiel #10
0
void QgsColorButton::setButtonBackground( const QColor &color )
{
  QColor backgroundColor = color;
  bool isProjectColor = false;
  if ( !backgroundColor.isValid() && !mLinkedColorName.isEmpty() )
  {
    backgroundColor = linkedProjectColor();
    isProjectColor = backgroundColor.isValid();
    if ( !isProjectColor )
    {
      mLinkedColorName.clear(); //color has been deleted, renamed, etc...
      emit unlinked();
    }
  }
  if ( !backgroundColor.isValid() )
  {
    backgroundColor = mColor;
  }

  QSize currentIconSize;
  //icon size is button size with a small margin
  if ( menu() )
  {
    if ( !mIconSize.isValid() )
    {
      //calculate size of push button part of widget (ie, without the menu drop-down button part)
      QStyleOptionToolButton opt;
      initStyleOption( &opt );
      QRect buttonSize = QApplication::style()->subControlRect( QStyle::CC_ToolButton, &opt, QStyle::SC_ToolButton,
                         this );
      //make sure height of icon looks good under different platforms
#ifdef Q_OS_WIN
      mIconSize = QSize( buttonSize.width() - 10, height() - 6 );
#else
      mIconSize = QSize( buttonSize.width() - 10, height() - 12 );
#endif
    }
    currentIconSize = mIconSize;
  }
  else
  {
    //no menu
#ifdef Q_OS_WIN
    currentIconSize = QSize( width() - 10, height() - 6 );
#else
    currentIconSize = QSize( width() - 10, height() - 12 );
#endif
  }

  if ( !currentIconSize.isValid() || currentIconSize.width() <= 0 || currentIconSize.height() <= 0 )
  {
    return;
  }

  //create an icon pixmap
  QPixmap pixmap( currentIconSize );
  pixmap.fill( Qt::transparent );

  if ( backgroundColor.isValid() )
  {
    QRect rect( 0, 0, currentIconSize.width(), currentIconSize.height() );
    QPainter p;
    p.begin( &pixmap );
    p.setRenderHint( QPainter::Antialiasing );
    p.setPen( Qt::NoPen );
    if ( mAllowOpacity && backgroundColor.alpha() < 255 )
    {
      //start with checkboard pattern
      QBrush checkBrush = QBrush( transparentBackground() );
      p.setBrush( checkBrush );
      p.drawRoundedRect( rect, 3, 3 );
    }

    //draw semi-transparent color on top
    p.setBrush( backgroundColor );
    p.drawRoundedRect( rect, 3, 3 );
    p.end();
  }

  setIconSize( currentIconSize );
  setIcon( pixmap );
}
Beispiel #11
0
void QgsColorButton::unlink()
{
  linkToProjectColor( QString() );
  emit unlinked();
}