// check button state and send messages if a button is pressed. static void check_buttons (void) { const uint8_t registers[8] = {0, 1, 2, 3, 4, 5, 6, 7}; uint8_t temp, msglen, msg[8]; static uint8_t regidx = 0, light = 0; // check button g_buttons = PIND & (1<<BTN_TEST | 1<<BTN_EXP); temp = g_buttons ^ g_oldbuttons; g_oldbuttons = g_buttons; if ((g_buttons & 1<<BTN_TEST) && (temp & 1<<BTN_TEST)) { regidx++; if (regidx > 7) regidx = 0; msg[0] = eCMD_REQUEST_REG; msg[1] = registers[regidx]; msglen = 2; bus_send_message(&g_bus, get_receiver(1), msglen, msg); } else if ((g_buttons & 1<<BTN_EXP) && (temp & 1<<BTN_EXP)) { if (light) light = 0; else light = 1; msg[0] = eCMD_SET_REG_8BIT; msg[1] = MOD_eReg_FirstAppSpecific; msg[2] = light; msglen = 3; bus_send_message(&g_bus, get_receiver(1), msglen, msg); } }
Signal* Input::get_signal(std::string name){ Receiver* receiver=get_receiver(name); if(receiver){ return receiver->get_signal(); } return 0; }
// Get the receiver object and slot signature from a callable or signal. sipErrorState qpycore_get_receiver_slot_signature(PyObject *slot, QObject *transmitter, const Chimera::Signature *signal_signature, bool single_shot, QObject **receiver, QByteArray &slot_signature) { // See if the slot is a signal. if (PyObject_TypeCheck(slot, &qpycore_pyqtBoundSignal_Type)) { qpycore_pyqtBoundSignal *bs = (qpycore_pyqtBoundSignal *)slot; *receiver = bs->bound_qobject; slot_signature = bs->unbound_signal->signature->signature; return sipErrorNone; } // Make sure the slot is callable. if (!PyCallable_Check(slot)) return sipErrorContinue; // See if the slot can be used directly (ie. it wraps a Qt slot) or if it // needs a proxy. if (!get_receiver(slot, signal_signature, receiver, slot_signature)) return sipErrorFail; if (slot_signature.isEmpty()) { slot_signature = PyQtSlotProxy::proxy_slot_signature; // Create a proxy for the slot. PyQtSlotProxy *proxy; Py_BEGIN_ALLOW_THREADS proxy = new PyQtSlotProxy(slot, transmitter, signal_signature, single_shot); if (proxy->metaObject()) { if (*receiver) proxy->moveToThread((*receiver)->thread()); *receiver = proxy; } else { delete proxy; proxy = 0; } Py_END_ALLOW_THREADS if (!proxy) return sipErrorFail; }
void test2() { std::cout << "===test2" << std::endl; const MockObj* mock = nullptr; std::cout << "consts: " << std::is_const<const MockObj*>::value << std::endl; Receiver* rec = get_receiver(mock); bool res = rec == nullptr; std::cout << "Result: " << res << std::endl; std::cout << "Should Be: TRUE" << std::endl; }
void test4() { std::cout << "===test4" << std::endl; const MockObj mock; std::cout << "consts: " << std::is_const<const MockObj>::value << std::endl; // By SFINAE, mock will lose its const qualifier Receiver* rec = get_receiver(mock); bool res = rec == nullptr; std::cout << "Result: " << res << std::endl; std::cout << "Should Be: TRUE" << std::endl; }
// traffic source/sinks owns link exclusively, so it does not need to check // whether it has access to link or not bool Traffic_source::can_send(void) const { if (buffer.is_empty()) return false; // This is somehow trick, we need to verify whether the first flit in the fifo // is received right in this clock cycle. If so, we can not send it const Flit * first_flit = buffer.peek_flit(); if (first_flit->arrived_in_this_cycle()) return false; pConnector receiver = get_receiver(); if (receiver) return receiver->can_receive(); else return false; }
/// Receives a payload virtual void receive(packet payload) { for(uint32_t j = 0; j < receiver_count(); ++j) { std::string recv_id = get_receiver(j)->node_id(); std::string src_id = payload.get_sender(); // If true we drop if(m_channel_condition->generate()) { ++m_counter[node_id()+"_"+src_id+"_to_"+recv_id+"_dropped"]; } else { ++m_counter[node_id()+"_"+src_id+"_to_"+recv_id+"_ok"]; // Deliver packet to receiver j forward(j, payload); } } }
int main() { setup_classes(); // c = C() pyobj c = create_object(C); // d = D() pyobj d = create_object(D); // TODO: call the __init__ method if it exists #ifdef TAGGING pyobj one = inject_int(1); pyobj three = inject_int(3); #else pyobj one = create_int(1); pyobj three = create_int(3); #endif // c.f = 1 set_attr(c, "f", one); // d.f = 1 set_attr(d, "f", one); pyobj i, j, k, h; // i = c.m() { pyobj meth = get_attr(c, "m"); pyobj fun = get_function(meth); void *fp = get_fun_ptr(fun); pyobj (*f)(pyobj) = (pyobj (*)(pyobj)) fp; // cast to a function pointer type i = f(get_receiver(meth)); } // j = d.m() { pyobj meth = get_attr(d, "m"); pyobj fun = get_function(meth); void *fp = get_fun_ptr(fun); pyobj (*f)(pyobj) = (pyobj (*)(pyobj)) fp; // cast to a function pointer type j = f(get_receiver(meth)); } // d.n(3) { pyobj (*f)(pyobj, pyobj) = (pyobj (*)(pyobj, pyobj)) get_fun_ptr_from_attr(d, "n"); f(d, three); } // k = d.m() { pyobj meth = get_attr(d, "m"); pyobj fun = get_function(meth); void *fp = get_fun_ptr(fun); pyobj (*f)(pyobj) = (pyobj (*)(pyobj)) fp; // cast to a function pointer type k = f(get_receiver(meth)); } // h = i + j + k { #ifdef TAGGING // optimized, but assumes i and j are integers // h = i + j + k // unoptimized, but checks that i and j are integers h = inject_int(project_int(i) + project_int(j) + project_int(k)); #else h = create_int(project_int(i) + project_int(j) + project_int(k)); #endif } // print i, j, k print_any(i); print_any(j); print_any(k); print_any(h); return 0; }
void PasteCommand::execute() { get_receiver()->paste_action(); }
void CopyCommand::execute() { get_receiver()->copy_action(); }
// Disconnect a signal. static PyObject *pyqtBoundSignal_disconnect(PyObject *self, PyObject *args) { qpycore_pyqtBoundSignal *bs = (qpycore_pyqtBoundSignal *)self; PyObject *slot_obj = 0, *res_obj; Chimera::Signature *signature = bs->unbound_signal->signature; #if PY_VERSION_HEX >= 0x02050000 if (!PyArg_ParseTuple(args, "|O:disconnect", &slot_obj)) #else if (!PyArg_ParseTuple(args, const_cast<char *>("|O:disconnect"), &slot_obj)) #endif return 0; // See if we are disconnecting everything from the overload. if (!slot_obj) { res_obj = disconnect(bs, 0, 0); PyQtProxy::deleteSlotProxies(bs->bound_qobject, signature->signature.constData()); return res_obj; } // See if the slot is a signal. if (Py_TYPE(slot_obj) == &qpycore_pyqtBoundSignal_Type) { qpycore_pyqtBoundSignal *slot_bs = (qpycore_pyqtBoundSignal *)slot_obj; return disconnect(bs, slot_bs->bound_qobject, slot_bs->unbound_signal->signature->signature.constData()); } if (!PyCallable_Check(slot_obj)) { PyErr_Format(PyExc_TypeError, "disconnect() argument should be callable, not '%s'", Py_TYPE(slot_obj)->tp_name); return 0; } // See if the slot has been used directly (ie. it wraps a Qt slot) or if it // has a proxy. QByteArray rx_name; QObject *rx_qobj = get_receiver(bs, slot_obj, rx_name); if (PyErr_Occurred()) return 0; if (!rx_name.isEmpty()) return disconnect(bs, rx_qobj, rx_name.constData()); const char *member; PyQtProxy *proxy = PyQtProxy::findSlotProxy(bs->bound_qobject, signature->signature.constData(), slot_obj, 0, &member); if (!proxy) { PyErr_Format(PyExc_TypeError, "'%s' object is not connected", Py_TYPE(slot_obj)->tp_name); return 0; } res_obj = disconnect(bs, proxy, member); proxy->disable(); return res_obj; }
// Connect a signal. static PyObject *pyqtBoundSignal_connect(PyObject *self, PyObject *args, PyObject *kwd_args) { qpycore_pyqtBoundSignal *bs = (qpycore_pyqtBoundSignal *)self; static const char *kwds[] = { "slot", "type", 0 }; PyObject *slot_obj, *type_obj = 0; if (!PyArg_ParseTupleAndKeywords(args, kwd_args, #if PY_VERSION_HEX >= 0x02050000 "O|O:connect", #else const_cast<char *>("O|O:connect"), #endif const_cast<char **>(kwds), &slot_obj, &type_obj)) return 0; Qt::ConnectionType type = Qt::AutoConnection; if (type_obj) { if (!sipCanConvertToEnum(type_obj, sipType_Qt_ConnectionType)) { PyErr_Format(PyExc_TypeError, "connect() type argument should be Qt.ConnectionType, not '%s'", Py_TYPE(slot_obj)->tp_name); return 0; } type = (Qt::ConnectionType)SIPLong_AsLong(type_obj); } // See if the slot is a signal. if (Py_TYPE(slot_obj) == &qpycore_pyqtBoundSignal_Type) { qpycore_pyqtBoundSignal *slot_bs = (qpycore_pyqtBoundSignal *)slot_obj; // Check we are not connecting to ourself. We do this because Qt // doesn't do a similar check and will recurse its way to a crash. if (slot_bs->unbound_signal == bs->unbound_signal && slot_bs->bound_qobject == bs->bound_qobject) { PyErr_SetString(PyExc_ValueError, "cannot connect a signal to itself"); return 0; } return connect(bs, slot_bs->bound_qobject, slot_bs->unbound_signal->signature->signature.constData(), type); } // Make sure the slot is callable. if (!PyCallable_Check(slot_obj)) { PyErr_Format(PyExc_TypeError, "connect() slot argument should be a callable or a signal, not '%s'", Py_TYPE(slot_obj)->tp_name); return 0; } // See if the slot can be used directly (ie. it wraps a Qt slot) or if it // needs a proxy. QByteArray rx_name; QObject *rx_qobj = get_receiver(bs, slot_obj, rx_name); if (PyErr_Occurred()) return 0; if (!rx_name.isEmpty()) return connect(bs, rx_qobj, rx_name.constData(), type); // Create a proxy for the slot. PyQtProxy *proxy; const char *member; Py_BEGIN_ALLOW_THREADS proxy = new PyQtProxy(bs, slot_obj, &member); if (proxy->metaObject()) { if (rx_qobj) proxy->moveToThread(rx_qobj->thread()); } else { delete proxy; proxy = 0; } Py_END_ALLOW_THREADS if (!proxy) return 0; return connect(bs, proxy, member, type); }
// Get the receiver object and slot signature from a callable or signal. // Optionally disable the receiver check. static sipErrorState get_receiver_slot_signature(PyObject *slot, QObject *transmitter, const Chimera::Signature *signal_signature, bool single_shot, QObject **receiver, QByteArray &slot_signature, bool unique_connection_check, int no_receiver_check) { // See if the slot is a signal. if (PyObject_TypeCheck(slot, &qpycore_pyqtBoundSignal_Type)) { qpycore_pyqtBoundSignal *bs = (qpycore_pyqtBoundSignal *)slot; *receiver = bs->bound_qobject; slot_signature = bs->unbound_signal->parsed_signature->signature; return sipErrorNone; } // Make sure the slot is callable. if (!PyCallable_Check(slot)) return sipErrorContinue; // See if the slot can be used directly (ie. it wraps a Qt slot) or if it // needs a proxy. if (!get_receiver(slot, signal_signature, receiver, slot_signature)) return sipErrorFail; if (slot_signature.isEmpty()) { slot_signature = PyQtSlotProxy::proxy_slot_signature; // Create a proxy for the slot. PyQtSlotProxy *proxy; if (unique_connection_check) { proxy = PyQtSlotProxy::findSlotProxy(transmitter, signal_signature->signature, slot); if (proxy) { // We give more information than we could if it was a Qt slot // but to be consistent we raise a TypeError even though it's // not the most appropriate for the type of error. PyErr_SetString(PyExc_TypeError, "connection is not unique"); return sipErrorFail; } } Py_BEGIN_ALLOW_THREADS proxy = new PyQtSlotProxy(slot, transmitter, signal_signature, single_shot); if (no_receiver_check) proxy->disableReceiverCheck(); if (proxy->metaObject()) { if (*receiver) proxy->moveToThread((*receiver)->thread()); *receiver = proxy; } else { delete proxy; proxy = 0; } Py_END_ALLOW_THREADS if (!proxy) return sipErrorFail; }
void interface::process_msg() { get_receiver().wait() .handle<issue_money>( [&](issue_money const& msg) { { std::lock_guard<std::mutex> lk(iom); std::cout << "Issuing " << msg.amount << std::endl; } } ) .handle<display_insufficient_funds>( [&](display_insufficient_funds const& msg) { (void)msg; { std::lock_guard<std::mutex> lk(iom); std::cout << "Insufficient funds" << std::endl; } } ) .handle<display_enter_pin>( [&](display_enter_pin const& msg) { (void)msg; { std::lock_guard<std::mutex> lk(iom); std::cout << "Please enter your PIN (0-9)" << std::endl; } } ) .handle<display_enter_card>( [&](display_enter_card const& msg) { (void)msg; { std::lock_guard<std::mutex> lk(iom); std::cout << "Please enter your card (i)" << std::endl; } } ) .handle<display_balance>( [&](display_balance const& msg) { { std::lock_guard<std::mutex> lk(iom); std::cout << "The balance of your account is " << msg.amount << std::endl; } } ) .handle<display_withdrawal_options>( [&](display_withdrawal_options const& msg) { (void)msg; { std::lock_guard<std::mutex> lk(iom); std::cout << "Withdraw 50? (w)" << std::endl; std::cout << "Display Balance? (b)" << std::endl; std::cout << "Cancel? (c)" << std::endl; } } ) .handle<display_withdrawal_cancelled>( [&](display_withdrawal_cancelled const& msg) { (void)msg; { std::lock_guard<std::mutex> lk(iom); std::cout << "Withdrawal cancelled" << std::endl; } } ) .handle<display_pin_incorrect_message>( [&](display_pin_incorrect_message const& msg) { (void)msg; { std::lock_guard<std::mutex> lk(iom); std::cout << "PIN incorrect" << std::endl; } } ) .handle<eject_card>( [&](eject_card const& msg) { (void)msg; { std::lock_guard<std::mutex> lk(iom); std::cout << "Ejecting card" << std::endl; } } ); }
void Input::sent_signal(Signal* signal){ Receiver* receiver=get_receiver(signal->get_sent_to()); if(!receiver)receiver=default_receiver; receiver->push_signal(signal); }