NodeConnection::NodeConnection(NCID id1, NCID id2)
	: id(reg.registerId(this))
{
	NodeConnector	*nc1 = NodeConnector::getNC(id1),
					*nc2 = NodeConnector::getNC(id2);

	if(nc1 && nc2 && NodeConnector::validConnection(id1, id2))
	{
		fromId = isOutput(nc1->ioType) ? id1 : (isOutput(nc2->ioType) ? id2 : -1);
		toId = isInput(nc1->ioType) ? id1 : (isInput(nc2->ioType) ? id2 : -1);

		fromNc = NodeConnector::getNC(fromId);
		toNc = NodeConnector::getNC(toId);

		//Connect given nodes
		if(fromNc)
		{
			fromNc->onConnect(toId, this);
			fromNode = fromNc->getNode();
		}
		if(toNc)
		{
			toNc->onConnect(fromId, this);
			toNode = toNc->getNode();
		}
	}
	//else invalid connection
}
Exemple #2
0
void MediaJack::setPosition(
	float offset,
	float leftTopBoundary,
	float rightBottomBoundary,
	BRegion *updateRegion)
{
	D_METHOD(("MediaJack::setPosition\n"));
	switch (dynamic_cast<MediaRoutingView *>(view())->getLayout())
	{
		case MediaRoutingView::M_ICON_VIEW:
		{
			if (isInput())
			{
				moveTo(BPoint(leftTopBoundary, offset), updateRegion);
			}
			else if (isOutput())
			{
				moveTo(BPoint(rightBottomBoundary - Frame().Width(), offset), updateRegion);
			}
			break;
		}
		case MediaRoutingView::M_MINI_ICON_VIEW:
		{
			if (isInput())
			{
				moveTo(BPoint(offset, leftTopBoundary), updateRegion);
			}
			else if (isOutput())
			{
				moveTo(BPoint(offset, rightBottomBoundary - Frame().Height()), updateRegion);
			}
			break;
		}
	}
}
Exemple #3
0
BPoint MediaJack::connectionPoint() const
{
	D_METHOD(("MediaJack::connectionPoint()\n"));

	switch (dynamic_cast<MediaRoutingView *>(view())->getLayout())
	{
		case MediaRoutingView::M_ICON_VIEW:
		{
			if (isInput())
			{
				return BPoint(Frame().left - 1.0, Frame().top + Frame().Height() / 2.0);
			}
			else if (isOutput())
			{
				return BPoint(Frame().right + 1.0, Frame().top + Frame().Height() / 2.0);
			}
			break;
		}
		case MediaRoutingView::M_MINI_ICON_VIEW:
		{
			if (isInput())
			{
				return BPoint(Frame().left + Frame().Width() / 2.0, Frame().top - 1.0);
			}
			else if (isOutput())
			{
				return BPoint(Frame().left + Frame().Width() / 2.0, Frame().bottom + 1.0);
			}
			break;
		}
	}
	return BPoint(-1.0, -1.0);
}
/**
 * read callback on data characteristic.
 * reads all the pins marked as inputs, and updates the data stored in the BLE stack.
 */
void MicroBitIOPinService::onDataRead(GattReadAuthCallbackParams *params)
{
    if (params->handle == ioPinServiceDataCharacteristic->getValueHandle())
    {

        // Scan through all pins that our BLE client may be listening for. If any have changed value, update the BLE characterisitc, and NOTIFY our client.
        int pairs = 0;

        for (int i=0; i < MICROBIT_IO_PIN_SERVICE_PINCOUNT; i++)
        {
            if (isInput(i))
            {
                uint8_t value;

                if (isDigital(i))
                    value = MicroBitIOPins[i]->getDigitalValue();
                else
                    value = MicroBitIOPins[i]->getAnalogValue();

                ioPinServiceIOData[i] = value;
                ioPinServiceDataCharacteristicBuffer[pairs].pin = i;
                ioPinServiceDataCharacteristicBuffer[pairs].value = value;

                pairs++;

                if (pairs >= MICROBIT_IO_PIN_SERVICE_DATA_SIZE)
                    break;
            }
        }

        // If there's any data, issue a BLE notification.
        if (pairs > 0)
            ble.gattServer().notify(ioPinServiceDataCharacteristic->getValueHandle(), (uint8_t *)ioPinServiceDataCharacteristicBuffer, pairs * sizeof(IOData));
    }
}
Exemple #5
0
void CompositionNodeSlot::setInitValue(const util::Any& v){
	ensure(isInput());
	ensure(!v.empty());
	RuntimeSignalTypeTraits::checkValue(identifier.signalType, v);
	initValue= v;
	ensure(!initValue.empty());
}
bool NodeConnector::pullData(PullPacket &output)//, NCID other_id)
{
	bool pulled = false;

	if(isInput(ioType))	//Only input nodes can pull
	{
		node->nodeLock.lockWait();
		//Pull data from all connections
		for(auto c : connections)
		{
			NCID other_nc = c.second->getOppositeNc(id);
			NodeConnector *nc = getNC(other_nc);
			if(nc)
			{
				c.second->setPulling(true);
				if(nc->node->pullData(output, other_nc, id))
				{
					pulled = true;
					c.second->setActive(NCDir::BACKWARD);
				}
			}
		}
		node->nodeLock.unlock();
	}

	return pulled;
}
Exemple #7
0
QString AVDemuxer::formatName(AVFormatContext *ctx, bool longName) const
{
    if (isInput())
        return longName ? ctx->iformat->long_name : ctx->iformat->name;
    else
        return longName ? ctx->oformat->long_name : ctx->oformat->name;
}
Exemple #8
0
void CompositionNodeSlot::setDefaultValue(const util::Any& v){
	ensure(isInput());
	defaultValue= v;
	RuntimeSignalTypeTraits::checkValue(identifier.signalType, defaultValue);
	
	getOwner().onDefaultValueChange(*this);
}
Exemple #9
0
// EVALUATE -- RECURSIVE
double Neuron::evaluate()
{
	// IF INPUT, RETURN VALUE
	if( isInput() )
        return value;

	// ELSE EVALUATE

	// FIND WEIGHTED SUM
	double sum = 0.;
	for( int i = 0; i < num_inputs; i++ )
		sum += weights[i] * inputs[i]->evaluate();

	// ACTIVATION FUNCTION
    switch( config->activation_function )
    {
    case SIGMOID:
		return fsigmoid( sum, config->activation_slope );
    case BINARY:
        return binary_activation( sum, threshold );
	case HYPERBOLIC_TANGENT:
		return hyperbolic_tangent( sum, config->activation_slope );
    }
    return 0.;
}
Exemple #10
0
void MediaJack::showContextMenu(
	BPoint point)
{
	D_METHOD(("MediaJack::showContextMenu()\n"));

	BPopUpMenu *menu = new BPopUpMenu("MediaJack PopUp", false, false, B_ITEMS_IN_COLUMN);
	menu->SetFont(be_plain_font);
	BMenuItem *item;

	// add the "Get Info" item
	if (isInput())
	{
		media_input input;
		getInput(&input);
		BMessage *message = new BMessage(InfoWindowManager::M_INFO_WINDOW_REQUESTED);
		message->AddData("input", B_RAW_TYPE,
						 reinterpret_cast<const void *>(&input), sizeof(input));
		menu->AddItem(item = new BMenuItem("Get info", message));
	}
	else if (isOutput())
	{
		media_output output;
		getOutput(&output);
		BMessage *message = new BMessage(InfoWindowManager::M_INFO_WINDOW_REQUESTED);
		message->AddData("output", B_RAW_TYPE,
						 reinterpret_cast<const void *>(&output), sizeof(output));
		menu->AddItem(item = new BMenuItem("Get info", message));
	}

	menu->SetTargetForItems(view());
	view()->ConvertToScreen(&point);
	point -= BPoint(1.0, 1.0);
	menu->Go(point, true, true, true);
}
Exemple #11
0
      ~ClauseBackground()
	{
	  CALL("desctructor ~ClauseBackground()");
	  if (BK::DestructionMode::isThorough()) 
	    {
	      if (!isInput()) ClauseList::destroyList(_ancestors);
	    };
	}; 
Exemple #12
0
void Neuron::initInputs()
{
    if( !isInput() )
    {
        inputs = new Neuron*[num_inputs];
        for( int i = 0; i < num_inputs; i++ )
            inputs[i] = NULL;
    }
}
Exemple #13
0
Neuron::~Neuron()
{
    // DELETE WEIGHTS
    if( !isInput() )
    {
        delete [] weights;
        weights = NULL;
    }
    // DELETE BRANCHES
	if( !isInput() )
	{
		for( int i = 0; i < num_inputs; i++ )
			if( inputs[i] && !inputs[i]->isInput() )
				delete inputs[i];
        delete [] inputs;
        inputs = NULL;
	}
}
Exemple #14
0
      void destroy()
      {
	CALL("destroy()");
	if (BK::DestructionMode::isThorough()) 
	  {
	    if (!isInput()) ClauseList::destroyList(_ancestors);
	  };
	_rules.destroy();
      };
Exemple #15
0
void Neuron::initWeights()
{
    if( !isInput() )
    {
        weights = new double[num_inputs];
        for( int i = 0; i < num_inputs; i++ )
            weights[i] = 0.;
    }
}
Exemple #16
0
const util::Any& CompositionNodeSlot::getDefaultValue() const {
	ensure(isInput());
	ensure(!initValue.empty());
	
	if (defaultValue.empty()){
		return initValue;
	}
	
	return defaultValue;
}
Exemple #17
0
void AstVar::dump(ostream& str) {
    this->AstNode::dump(str);
    if (isSc()) str<<" [SC]";
    if (isPrimaryIO()) str<<(isInout()?" [PIO]":(isInput()?" [PI]":" [PO]"));
    else {
	if (isInout()) str<<" [IO]";
	else if (isInput()) str<<" [I]";
	else if (isOutput()) str<<" [O]";
    }
    if (isConst()) str<<" [CONST]";
    if (isUsedClock()) str<<" [CLK]";
    if (isSigPublic()) str<<" [P]";
    if (isUsedLoopIdx()) str<<" [LOOP]"; 
    if (attrClockEn()) str<<" [aCLKEN]";
    if (attrIsolateAssign()) str<<" [aISO]";
    if (attrFileDescr()) str<<" [aFD]";
    if (isFuncReturn()) str<<" [FUNCRTN]";
    else if (isFuncLocal()) str<<" [FUNC]";
    str<<" "<<varType();
}
string AstVar::verilogKwd() const {
    if (isInout()) {
	return "inout";
    } else if (isInput()) {
	return "input";
    } else if (isOutput()) {
	return "output";
    } else if (isTristate()) {
	return "tri";
    } else if (varType()==AstVarType::WIRE) {
	return "wire";
    } else {
	return dtypep()->name();
    }
}
Exemple #19
0
status_t MediaJack::getInput(
	media_input *input) const
{
	D_METHOD(("MediaJack::getInput()\n"));
	if (isInput())
	{
		input->node = m_node;
		input->source = m_source;
		input->destination = m_destination;
		input->format = m_format;
		strlcpy(input->name, m_label.String(), B_MEDIA_NAME_LENGTH);
		return B_OK;
	}
	return B_ERROR;
}
	void DocumentDatasLinksList::updateLinks(const graphics::DrawColors& colors)
	{
		LinksList::updateLinks(colors);

		auto pen = colors.penColor;
		int inputIndex = 0, outputIndex = 0;
		for (const auto& gdr : m_documentDatasView.dataRects())
		{
			const auto data = gdr.first;
			const auto& dataRect = gdr.second;
			if (data->isInput())
			{
				auto d1 = dataRect.center();
				for (const auto& output : data->getOutputs())
				{
					if (BaseData* data = dynamic_cast<BaseData*>(output))
					{
						Rect dataRect;
						if (!getDataRect(data, dataRect))
							continue;

						auto d2 = dataRect.center();
						Point w = { (d2.x - d1.x) / 2, 0 };
						m_linksDrawList->addBezierCurve(d1, d1 + w, d2 - w, d2, pen, 1);
					}
				}
			}
		
			if (data->isOutput())
			{
				auto d2 = dataRect.center();
				for (const auto& input : data->getInputs())
				{
					if (BaseData* data = dynamic_cast<BaseData*>(input))
					{
						Rect dataRect;
						if (!getDataRect(data, dataRect))
							continue;

						auto d1 = dataRect.center();
						Point w = { (d2.x - d1.x) / 2, 0 };
						m_linksDrawList->addBezierCurve(d1, d1 + w, d2 - w, d2, pen, 1);
					}
				}
			}
		}
	}
NodeConnection::NodeConnection(NCID id)
	: id(reg.registerId(this))
{
	NodeConnector *nc = NodeConnector::getNC(id);

	if(nc)
	{
		fromId = isOutput(nc->ioType) ? id : -1;
		toId = isInput(nc->ioType) ? id : -1;
		
		fromNc = NodeConnector::getNC(fromId);
		toNc = NodeConnector::getNC(toId);

		fromNode = fromNc ? fromNc->getNode() : nullptr;
		toNode = toNc ? toNc->getNode() : nullptr;
	}
	//Else invalid id
}
Exemple #22
0
bool CompositionNodeSlot::isCompatible(SubSignalType from_type, SubSignalType to_type, CompositionNodeSlot& other) const {
	if (isInput() == other.isInput()) return false;
	
	SignalType from= identifier.signalType;
	SignalType to= other.identifier.signalType;
	
	if (from_type != SubSignalType::None)
		from= RuntimeSubSignalTypeTraits::signalType(from_type);
		
	if (to_type != SubSignalType::None)
		to= RuntimeSubSignalTypeTraits::signalType(to_type);

	// SubSignalling
	ensure(identifier.signalType == from || hasSubSignalType(from_type));
	ensure(other.identifier.signalType == to || other.hasSubSignalType(to_type));
	
	return from == to;
	
}
/**
 * Periodic callback from MicroBit scheduler.
 *
 * Check if any of the pins we're watching need updating. Notify any connected
 * device with any changes.
 */
void MicroBitIOPinService::idleTick()
{
    // If we're not we're connected, then there's nothing to do...
    if (!ble.getGapState().connected)
        return;

    // Scan through all pins that our BLE client may be listening for. If any have changed value, update the BLE characterisitc, and NOTIFY our client.
    int pairs = 0;

    for (int i=0; i < MICROBIT_IO_PIN_SERVICE_PINCOUNT; i++)
    {
        if (isInput(i))
        {
            uint8_t value;

            if (isDigital(i))
               	value = io.pin[i].getDigitalValue();
                //value = MicroBitIOPins[i]->getDigitalValue();
            else
               	value = io.pin[i].getAnalogValue();
                //value = MicroBitIOPins[i]->getAnalogValue();

            // If the data has changed, send an update.
            if (value != ioPinServiceIOData[i])
            {
                ioPinServiceIOData[i] = value;

                ioPinServiceDataCharacteristicBuffer[pairs].pin = i;
                ioPinServiceDataCharacteristicBuffer[pairs].value = value;

                pairs++;

                if (pairs >= MICROBIT_IO_PIN_SERVICE_DATA_SIZE)
                    break;
            }
        }
    }

    // If there were any changes, issue a BLE notification.
    if (pairs > 0)
        ble.gattServer().notify(ioPinServiceDataCharacteristic->getValueHandle(), (uint8_t *)ioPinServiceDataCharacteristicBuffer, pairs * sizeof(IOData));
}
string AstVar::vlArgType(bool named, bool forReturn, bool forFunc) const {
    if (forReturn) named=false;
    if (forReturn) v3fatalSrc("verilator internal data is never passed as return, but as first argument");
    string arg;
    if (isWide() && isInOnly()) arg += "const ";
    AstBasicDType* bdtypep = basicp();
    bool strtype = bdtypep && bdtypep->keyword()==AstBasicDTypeKwd::STRING;
    if (bdtypep && bdtypep->keyword()==AstBasicDTypeKwd::CHARPTR) {
	arg += "const char*";
    } else if (bdtypep && bdtypep->keyword()==AstBasicDTypeKwd::SCOPEPTR) {
	arg += "const VerilatedScope*";
    } else if (bdtypep && bdtypep->keyword()==AstBasicDTypeKwd::DOUBLE) {
	arg += "double";
    } else if (bdtypep && bdtypep->keyword()==AstBasicDTypeKwd::FLOAT) {
	arg += "float";
    } else if (strtype) {
	if (isInOnly()) arg += "const ";
	arg += "string";
    } else if (widthMin() <= 8) {
	arg += "CData";
    } else if (widthMin() <= 16) {
	arg += "SData";
    } else if (widthMin() <= VL_WORDSIZE) {
	arg += "IData";
    } else if (isQuad()) {
	arg += "QData";
    } else if (isWide()) {
	arg += "WData";  // []'s added later
    }
    if (isWide() && !strtype) {
	arg += " (& "+name();
	arg += ")["+cvtToStr(widthWords())+"]";
    } else {
	if (forFunc && (isOutput() || (strtype && isInput()))) arg += "&";
	if (named) arg += " "+name();
    }
    return arg;
}
Exemple #25
0
SerializableBase* Stream::readBaseObject(SerializableBase *o) {
	if (!isInput()) {
		throw dnnException()<< "Stream isn't open in input mode. Need input stream\n";
	}

	vector<ProtoMessage> messages = readObjectProtos();
	
	if(messages.size() == 0) {
		return nullptr;		
	}
	
	std::reverse(messages.begin(), messages.end());

	Protos::ClassName *head = SerializableBase::getHeader(messages);
	if(!o) {
		SerializableBase *new_o = Factory::inst().createObject(head->class_name());	
		new_o->getDeserialized(messages);
		return new_o;
	} else {
		o->getDeserialized(messages);
		return o;
	}
}
void nsSocket::connect(nsSocket* oth)
{
	// ignore links on the same node
	if (oth && oth->m_parent == m_parent)
		return;

	if (oth)
	{
		if (m_from == oth)
		{
			// ignore linking to the same socket
			return;
		}

		if (m_from != 0)
		{
			nsSocketList& links = m_from->m_tosockets;

			// other is zero so erase this in the from node
			UT_ASSERT((!links.empty() && links.find(this)) && "Socket improperly linked!");
			links.erase(this);

			bool isFirst = getPrev() == 0;

			nsSocket* sock = 0;

			if (isFirst)
				sock = getNext();
			else
			{
				// try top down
				sock = getPrev();
				if (sock)
				{
					nsSocket* root = sock;
					while (root)
					{
						sock = root;
						root = root->getPrev();
						if (!root)
							break;
					}
				}
			}

			while (sock)
			{
				if (sock != this && !sock->isConnected())
				{
					if (m_from->canConnect(sock))
					{
						sock->connect(m_from);
						break;
					}
				}
				sock = sock->getNext();
			}
		}

		// linking to
		UT_ASSERT(oth->isOutput() && isInput());

		m_from = oth;
		m_from->m_tosockets.push_back(this);
	}
	else
	{
		// make sure this is an input
		UT_ASSERT(isInput());


		if (m_from)
		{
			nsSocketList& links = m_from->m_tosockets;

			// other is zero so erase this in the from node
			UT_ASSERT((!links.empty() && links.find(this)) && "Socket improperly linked!");
			links.erase(this);
			m_from = 0;
		}
	}
}
Exemple #27
0
      ClauseList* ancestors() 
	{
	  CALL("ancestors()");
	  ASSERT(!isInput());
	  return _ancestors; 
	};
Exemple #28
0
      const ClauseList* ancestors() const 
	{
	  CALL("ancestors() const");
	  ASSERT(!isInput());
	  return _ancestors; 
	};
Exemple #29
0
      void setInputClauseOrigin(void* orig)
	{
	  CALL("setInputClauseOrigin()");
	  ASSERT(isInput());
	  _inputClauseOrigin = orig; 
	};
Exemple #30
0
      void* inputClauseOrigin() const
	{
	  CALL("inputClauseOrigin() const");
	  ASSERT(isInput());
	  return _inputClauseOrigin; 
	};