int GadgetInstrumentationStreamController::prepend_gadget(const char* gadgetname, const char* dllname, const char* classname) { GadgetModule* m = create_gadget_module(dllname, classname, gadgetname); Gadget* g = dynamic_cast<Gadget*>(m->writer());//Get the gadget out of the module //We will set this very high to prevent race conditions in "mixed environments" such as when using Python or Matlab in Gadgets g->msg_queue()->high_water_mark(ACE_Message_Queue_Base::DEFAULT_HWM*100000); if (!m) { GERROR("Failed to create GadgetModule from %s:%s\n", classname, dllname); return GADGET_FAIL; } if (stream_.push(m) < 0) { GERROR("Failed to push Gadget %s onto stream\n", gadgetname); delete m; return GADGET_FAIL; } return GADGET_OK; }
std::string ViewportGadget::getToolTip( const IECore::LineSegment3f &line ) const { std::string result = Gadget::getToolTip( line ); if( result.size() ) { return result; } std::vector<GadgetPtr> gadgets; gadgetsAt( V2f( line.p0.x, line.p0.y ), gadgets ); for( std::vector<GadgetPtr>::const_iterator it = gadgets.begin(), eIt = gadgets.end(); it != eIt; it++ ) { Gadget *gadget = it->get(); while( gadget && gadget != this ) { IECore::LineSegment3f lineInGadgetSpace = rasterToGadgetSpace( V2f( line.p0.x, line.p0.y), gadget ); result = gadget->getToolTip( lineInGadgetSpace ); if( result.size() ) { return result; } gadget = gadget->parent<Gadget>(); } } return result; }
void GadgetInstrumentationStreamController::set_parameter(const char* gadgetname, const char* parameter, const char* value) { Gadget* g = this->find_gadget(gadgetname); if (!g) { throw std::runtime_error("Unable to find Gadget for setting parameter"); } g->set_parameter(parameter,value,false); }
void Gadget::requestRender() { Gadget *g = this; while( g ) { g->renderRequestSignal()( g ); g = g->parent<Gadget>(); } }
void StandardConnectionGadget::setPositionsFromNodules() { const Gadget *p = parent<Gadget>(); if( !p ) { return; } if( dstNodule() && m_dragEnd!=Gaffer::Plug::In ) { Gadget *dstNodeGadget = dstNodule()->ancestor<NodeGadget>(); if( dstNodeGadget ) { /// \todo /// this is a hack. we're calling bound() to trigger /// recomputation of the child positions within /// the nodule row - this is currently necessary when a /// nodule has just been added as connections are /// rendered before nodules and the nodule transforms /// would otherwise not be updated in time. see the todo item /// in Gadget.h which suggests that transforms are returned from /// a childTransform() virtual method - this would mean the /// container could update the transform as we request it. dstNodeGadget->bound(); } M44f m = dstNodule()->fullTransform( p ); m_dstPos = V3f( 0 ) * m; const NodeGadget *dstNoduleNodeGadget = dstNodule()->ancestor<NodeGadget>(); m_dstTangent = dstNoduleNodeGadget ? dstNoduleNodeGadget->noduleTangent( dstNodule() ) : V3f( 0, 1, 0 ); } if( srcNodule() && m_dragEnd!=Gaffer::Plug::Out ) { Gadget *srcNodeGadget = srcNodule()->ancestor<NodeGadget>(); if( srcNodeGadget ) { /// \todo See above. srcNodeGadget->bound(); } M44f m = srcNodule()->fullTransform( p ); m_srcPos = V3f( 0 ) * m; const NodeGadget *srcNoduleNodeGadget = srcNodule()->ancestor<NodeGadget>(); m_srcTangent = srcNoduleNodeGadget ? srcNoduleNodeGadget->noduleTangent( srcNodule() ) : V3f( 0, -1, 0 ); } else if( m_dragEnd != Gaffer::Plug::Out ) { // not dragging and don't have a source nodule. // we're a dangling connection because the source // node is hidden. m_srcPos = m_dstPos + m_dstTangent * 1.5f; m_srcTangent = -m_dstTangent; } }
void GroupControl::timeSelectionInactive(Gadget *source) { QPoint point(-1, -1); QMouseEvent release(QEvent::MouseButtonRelease, point, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier); for (int i = 0; i < gadgetCount(); i++) { Gadget *gadget = my.gadgetsList.at(i); if (source != gadget) gadget->deactivateTime(&release); } }
void GroupControl::timeSelectionReactive(Gadget *source, int timestamp) { QPoint point(timestamp, -1); QMouseEvent moved(QEvent::MouseMove, point, Qt::NoButton, Qt::LeftButton, Qt::NoModifier); for (int i = 0; i < gadgetCount(); i++) { Gadget *gadget = my.gadgetsList.at(i); if (source != gadget) gadget->reactivateTime(&moved); } }
bool Gadget::visible( Gadget *relativeTo ) { Gadget *g = this; while( g && g != relativeTo ) { if( !g->getVisible() ) { return false; } g = g->parent<Gadget>(); } return true; }
void PmChart::fileSaveView() { // If we have one host only, we default to "host dynamic" views. // Otherwise (multiple hosts), default to explicit host names. int i, ngadgets = activeTab()->gadgetCount(); bool hostDynamic = true; for (i = 0; i < ngadgets; i++) { Gadget *gadget = activeTab()->gadget(i); if (gadget->hosts().size() > 1) hostDynamic = false; } setupDialogs(); my.saveview->reset(hostDynamic); my.saveview->show(); }
void Gadget::setVisible( bool visible ) { if( visible == m_visible ) { return; } m_visible = visible; Gadget *p = parent<Gadget>(); if( !p || p->visible() ) { emitDescendantVisibilityChanged(); visibilityChangedSignal()( this ); } requestRender(); }
int GadgetStreamController::open (void) { //We will set up the controllers message queue such that when a packet is enqueued write will be triggered. this->notifier_.reactor (this->reactor ()); this->msg_queue ()->notification_strategy (&this->notifier_); ACE_TCHAR peer_name[MAXHOSTNAMELEN]; ACE_INET_Addr peer_addr; if (peer().get_remote_addr (peer_addr) == 0 && peer_addr.addr_to_string (peer_name, MAXHOSTNAMELEN) == 0) { GINFO("Connection from %s\n", peer_name); } //We have to have these basic types to be able to receive configuration file for stream readers_.insert(GADGET_MESSAGE_CONFIG_FILE, new GadgetMessageConfigFileReader()); readers_.insert(GADGET_MESSAGE_CONFIG_SCRIPT, new GadgetMessageScriptReader()); readers_.insert(GADGET_MESSAGE_PARAMETER_SCRIPT, new GadgetMessageScriptReader()); GadgetModule *head = 0; GadgetModule *tail = 0; if (tail == 0) { Gadget* eg = new EndGadget(); if (eg) { eg->set_controller(this); } ACE_NEW_RETURN(tail, ACE_Module<ACE_MT_SYNCH>( ACE_TEXT("EndGadget"), eg ), -1); stream_.open(0,head,tail); } this->writer_task_.open(); return this->activate( THR_NEW_LWP | THR_JOINABLE, 1); }
int DistributeGadget::process_config(ACE_Message_Block* m) { started_nodes_ = 0; node_parameters_ = std::string(m->rd_ptr()); //Grab the original XML conifguration std::string xml = controller_->get_xml_configuration(); GadgetronXML::GadgetStreamConfiguration cfg; GadgetronXML::deserialize(xml.c_str(),cfg); //Delete Gadgets up to this Gadget std::vector<GadgetronXML::Gadget>::iterator it = cfg.gadget.begin(); while ((it->name != std::string(this->module()->name())) && (it != cfg.gadget.end())) it++; it++; cfg.gadget.erase(cfg.gadget.begin(),it); //Delete Gadgets after collector it = cfg.gadget.begin(); while ((it->name != collector.value()) && (it != cfg.gadget.end())) it++; it++; cfg.gadget.erase(it,cfg.gadget.end()); std::stringstream o; GadgetronXML::serialize(cfg,o); node_xml_config_ = o.str(); Gadget* tmp = this; while (tmp->next()) { if (std::string(tmp->module()->name()) == collector.value()) break; tmp = dynamic_cast<Gadget*>(tmp->next()); } collect_gadget_ = tmp; if (!collect_gadget_) { GERROR("Failed to locate collector Gadget with name %s\n", collector.value().c_str()); return GADGET_FAIL; } else { collect_gadget_->set_parameter("pass_through_mode","true"); } return GADGET_OK; }
int GadgetInstrumentationStreamController::open() { GadgetModule *head = 0; GadgetModule *tail = 0; if (tail == 0) { Gadget* eg = new EndGadget(); if (eg) { eg->set_controller(this); } ACE_NEW_RETURN(tail, ACE_Module<ACE_MT_SYNCH>( ACE_TEXT("EndGadget"), eg ), -1); stream_.open(0,head,tail); } //Adding some gadgets to "capture data and return to the stream" if (this->prepend_gadget("ImageFinishFloat","gadgetron_mricore","ImageFinishGadget") != GADGET_OK) return GADGET_FAIL; this->find_gadget("ImageFinishFloat")->pass_on_undesired_data(true); /* if (this->prepend_gadget("ImageFinishCplx","gadgetron_mricore","ImageFinishGadgetCPLX") != GADGET_OK) return GADGET_FAIL; this->find_gadget("ImageFinishCplx")->pass_on_undesired_data(true); if (this->prepend_gadget("ImageFinishUShort","gadgetron_mricore","ImageFinishGadgetUSHORT") != GADGET_OK) return GADGET_FAIL; this->find_gadget("ImageFinishUShort")->pass_on_undesired_data(true); */ if (this->prepend_gadget("AcquisitionFinish","gadgetron_mricore","AcquisitionFinishGadget") != GADGET_OK) return GADGET_FAIL; this->find_gadget("AcquisitionFinish")->pass_on_undesired_data(true); return GADGET_OK; }
std::multiset<Gadget*> BeaRopGadgetFinder::find_all_gadget_from_ret(const unsigned char* data, unsigned long long vaddr, const DISASM* ending_instr_disasm, unsigned int len_ending_instr) { std::multiset<Gadget*> gadgets; DISASM dis; init_disasm_struct(&dis); /* We go back, trying to create the longuest gadget possible with the longuest instructions "On INTEL processors, (in IA-32 or intel 64 modes), instruction never exceeds 15 bytes." -- beaengine.org */ dis.EIP = (UIntPtr)(ending_instr_disasm->EIP - m_depth*15); // /!\ Warning to pointer arith dis.VirtualAddr = ending_instr_disasm->VirtualAddr - m_depth*15; /* going back yeah, but not too much :)) */ if(dis.EIP < (UIntPtr)data) { dis.EIP = (UIntPtr)data; dis.VirtualAddr = vaddr; } while(dis.EIP < ending_instr_disasm->EIP) { std::list<Instruction> list_of_instr; /* save where we were in memory */ UIntPtr saved_eip = dis.EIP; UInt64 saved_vaddr = dis.VirtualAddr; bool is_a_valid_gadget = false; /* now we'll try to find suitable sequence */ for(unsigned int nb_ins = 0; nb_ins < m_depth; nb_ins++) { int len_instr = Disasm(&dis); /* if the instruction isn't valid, let's try the process one byte after */ if(len_instr == UNKNOWN_OPCODE || is_valid_instruction(&dis) == false) break; list_of_instr.push_back(Instruction( std::string(dis.CompleteInstr), std::string(dis.Instruction.Mnemonic), dis.EIP - (UIntPtr)data, len_instr )); dis.EIP += len_instr; dis.VirtualAddr += len_instr; /* if the address of the latest instruction found points on the ending one, we have a winner */ if(dis.EIP == ending_instr_disasm->EIP) { is_a_valid_gadget = true; /* NB: I reach the ending instruction without depth instruction */ break; } /* if we point after the ending one, it's not a valid sequence */ if(dis.EIP > ending_instr_disasm->EIP) break; } if(is_a_valid_gadget) { /* we have a valid gadget, time to build it ; add the instructions found & finally add the ending instruction */ /* Don't forget to include the ending instruction in the chain of instruction */ list_of_instr.push_back(Instruction( std::string(ending_instr_disasm->CompleteInstr), std::string(ending_instr_disasm->Instruction.Mnemonic), ending_instr_disasm->EIP - (UIntPtr)data, len_ending_instr )); Gadget *gadget = new (std::nothrow) Gadget(); if(gadget == NULL) RAISE_EXCEPTION("Cannot allocate gadget"); /* Now we populate our gadget with the instructions previously found.. */ gadget->add_instructions(list_of_instr, vaddr); gadgets.insert(gadget); } /* goto the next byte */ dis.EIP = saved_eip + 1; dis.VirtualAddr = saved_vaddr + 1; } return gadgets; }
bool operator==(const Gadget& gadget1, const Gadget& gadget2) { return gadget1.getType() == gadget2.getType(); }
static StylePtr style( Gadget &g ) { return const_cast<Style *>( g.style() ); }
void LinearContainer::calculateChildTransforms() const { if( m_clean ) { return; } int axis = m_orientation - 1; V3f size( 0 ); vector<Box3f> bounds; for( ChildContainer::const_iterator it=children().begin(); it!=children().end(); it++ ) { const Gadget *child = static_cast<const Gadget *>( it->get() ); if( !child->getVisible() ) { continue; } Box3f b = child->bound(); if( !b.isEmpty() ) { for( int a=0; a<3; a++ ) { if( a==axis ) { size[a] += b.size()[a]; } else { size[a] = max( size[a], b.size()[a] ); } } } bounds.push_back( b ); } size[axis] += (bounds.size() - 1) * m_spacing; float offset = size[axis] / 2.0f * ( m_direction==Increasing ? -1.0f : 1.0f ); int i = 0; for( ChildContainer::const_iterator it=children().begin(); it!=children().end(); it++ ) { Gadget *child = static_cast<Gadget *>( it->get() ); if( !child->getVisible() ) { continue; } const Box3f &b = bounds[i++]; V3f childOffset( 0 ); if( !b.isEmpty() ) { for( int a=0; a<3; a++ ) { if( a==axis ) { childOffset[a] = offset - ( m_direction==Increasing ? b.min[a] : b.max[a] ); } else { switch( m_alignment ) { case Min : childOffset[a] = -size[a]/2.0f - b.min[a]; break; case Centre : childOffset[a] = -b.center()[a]; break; default : // max childOffset[a] = size[a]/2.0f - b.max[a]; } } } offset += b.size()[axis] * ( m_direction==Increasing ? 1.0f : -1.0f ); } offset += m_spacing * ( m_direction==Increasing ? 1.0f : -1.0f ); M44f m; m.translate( childOffset ); child->setTransform( m ); } m_clean = true; }
void PmChart::painter(QPainter *qp, int pw, int ph, bool transparent, bool currentOnly) { double scale_h = 0; double scale_w = 0; int i, ngadgets = activeTab()->gadgetCount(); QSize size; QRect rect; // used for print layout calculations qp->setFont(*globalFont); console->post("painter() pw=%d ph=%d ngadgets=%d", pw, ph, ngadgets); for (i = 0; i < ngadgets; i++) { Gadget *gadget = activeTab()->gadget(i); if (currentOnly && gadget != activeTab()->currentGadget()) continue; size = gadget->size(); console->post(" [%d] w=%d h=%d", i, size.width(), size.height()); if (size.width() > scale_w) scale_w = size.width(); scale_h += size.height(); } console->post(" final_w=%d final_h=%d", (int)scale_w, (int)scale_h); // timeaxis is _always_ less narrow than the plot(s) // datelabel is _never_ wider than the timeaxis // so width calculation is done, just need to consider the heights size = my.statusBar->timeAxis()->size(); console->post(" timeaxis w=%d h=%d", size.width(), size.height()); scale_h += size.height() - TIMEAXISFUDGE; size = my.statusBar->dateLabel()->size(); console->post(" datelabel w=%d h=%d", size.width(), size.height()); scale_h += size.height(); console->post(" final_w=%d final_h=%d", (int)scale_w, (int)scale_h); if (scale_w/pw > scale_h/ph) { // window width drives scaling scale_w = pw / scale_w; scale_h = scale_w; } else { // window height drives scaling scale_h = ph / scale_h; scale_w = scale_h; } console->post(" final chart scale_w=%.2f scale_h=%.2f", scale_w, scale_h); rect.setX(0); rect.setY(0); for (i = 0; i < ngadgets; i++) { Gadget *gadget = activeTab()->gadget(i); if (currentOnly && gadget != activeTab()->currentGadget()) continue; size = gadget->size(); rect.setWidth((int)(size.width()*scale_w+0.5)); rect.setHeight((int)(size.height()*scale_h+0.5)); console->post(" [%d] @ (%d,%d) w=%d h=%d", i, rect.x(), rect.y(), rect.width(), rect.height()); gadget->print(qp, rect, transparent); rect.setY(rect.y()+rect.height()); } // time axis rect.setY(rect.y() - TIMEAXISFUDGE); size = my.statusBar->timeAxis()->size(); rect.setX(pw-(int)(size.width()*scale_w+0.5)); rect.setWidth((int)(size.width()*scale_w+0.5)); rect.setHeight((int)(size.height()*scale_h+0.5)); console->post(" timeaxis @ (%d,%d) w=%d h=%d", rect.x(), rect.y(), rect.width(), rect.height()); my.statusBar->timeAxis()->print(qp, rect, transparent); rect.setY(rect.y()+rect.height()); // date label below time axis size = my.statusBar->dateLabel()->size(); rect.setX(pw-(int)(size.width()*scale_w+0.5)); rect.setWidth((int)(size.width()*scale_w+0.5)); rect.setHeight((int)(size.height()*scale_h+0.5)); console->post(" datelabel @ (%d,%d) w=%d h=%d", rect.x(), rect.y(), rect.width(), rect.height()); qp->drawText(rect, Qt::AlignRight, my.statusBar->dateText()); }
int GadgetStreamController::configure(std::string config_xml_string) { //Store a copy config_xml_ = config_xml_string; GadgetronXML::GadgetStreamConfiguration cfg; try { deserialize(config_xml_string.c_str(), cfg); } catch (const std::runtime_error& e) { GERROR("Failed to parse Gadget Stream Configuration: %s\n", e.what()); return GADGET_FAIL; } GINFO("Found %d readers\n", cfg.reader.size()); GINFO("Found %d writers\n", cfg.writer.size()); GINFO("Found %d gadgets\n", cfg.gadget.size()); //Configuration of readers for (std::vector<GadgetronXML::Reader>::iterator i = cfg.reader.begin(); i != cfg.reader.end(); ++i) { long slot = 0; std::string dllname(""); std::string classname(""); slot = i->slot; dllname = i->dll; classname = i->classname; GINFO("--Found reader declaration\n"); GINFO(" Reader dll: %s\n", dllname.c_str()); GINFO(" Reader class: %s\n", classname.c_str()); GINFO(" Reader slot: %d\n", slot); GadgetMessageReader* r = load_dll_component<GadgetMessageReader>(dllname.c_str(), classname.c_str()); if (!r) { GERROR("Failed to load GadgetMessageReader from DLL\n"); return GADGET_FAIL; } readers_.insert(slot, r); } //Configuration of readers end //Configuration of writers for (std::vector<GadgetronXML::Writer>::iterator i = cfg.writer.begin(); i != cfg.writer.end(); ++i) { long slot = 0; std::string dllname(""); std::string classname(""); slot = i->slot; dllname = i->dll; classname = i->classname; GINFO("--Found writer declaration\n"); GINFO(" Writer dll: %s\n", dllname.c_str()); GINFO(" Writer class: %s\n", classname.c_str()); GINFO(" Writer slot: %d\n", slot); GadgetMessageWriter* w = load_dll_component<GadgetMessageWriter>(dllname.c_str(), classname.c_str()); if (!w) { GERROR("Failed to load GadgetMessageWriter from DLL\n"); return GADGET_FAIL; } writer_task_.register_writer(slot, w); } //Configuration of writers end //Let's configure the stream GDEBUG("Processing %d gadgets in reverse order\n",cfg.gadget.size()); for (std::vector<GadgetronXML::Gadget>::reverse_iterator i = cfg.gadget.rbegin(); i != cfg.gadget.rend(); ++i) { std::string gadgetname(""); std::string dllname(""); std::string classname(""); gadgetname = i->name; dllname = i->dll; classname = i->classname; GINFO("--Found gadget declaration\n"); GINFO(" Gadget Name: %s\n", gadgetname.c_str()); GINFO(" Gadget dll: %s\n", dllname.c_str()); GINFO(" Gadget class: %s\n", classname.c_str()); GadgetModule* m = create_gadget_module(dllname.c_str(), classname.c_str(), gadgetname.c_str()); if (!m) { GERROR("Failed to create GadgetModule from %s:%s\n", classname.c_str(), dllname.c_str()); return GADGET_FAIL; } Gadget* g = dynamic_cast<Gadget*>(m->writer());//Get the gadget out of the module GINFO(" Gadget parameters: %d\n", i->property.size()); for (std::vector<GadgetronXML::GadgetronParameter>::iterator p = i->property.begin(); p != i->property.end(); ++p) { std::string pname(p->name); std::string pval(p->value); GINFO("Setting parameter %s = %s\n", pname.c_str(),pval.c_str()); g->set_parameter(pname.c_str(),pval.c_str(),false); } // set the global gadget parameters for every gadget std::map<std::string, std::string>::const_iterator iter; for ( iter=global_gadget_parameters_.begin(); iter!=global_gadget_parameters_.end(); iter++ ) { std::string key = iter->first; std::string value = iter->second; g->set_parameter(key.c_str(), value.c_str(), false); } if (stream_.push(m) < 0) { GERROR("Failed to push Gadget %s onto stream\n", gadgetname.c_str()); delete m; return GADGET_FAIL; } } GINFO("Gadget Stream configured\n"); stream_configured_ = true; return GADGET_OK; }
uint qHash(const Gadget& gadget) { return qHash(gadget.getType()); }
int DistributeGadget::process_config(ACE_Message_Block* m) { started_nodes_ = 0; node_parameters_ = std::string(m->rd_ptr()); //Grab the original XML conifguration std::string xml = controller_->get_xml_configuration(); GadgetronXML::GadgetStreamConfiguration cfg; GadgetronXML::deserialize(xml.c_str(),cfg); //Delete Gadgets up to this Gadget std::vector<GadgetronXML::Gadget>::iterator it = cfg.gadget.begin(); while ((it->name != std::string(this->module()->name())) && (it != cfg.gadget.end())) it++; it++; cfg.gadget.erase(cfg.gadget.begin(),it); //Delete Gadgets after collector it = cfg.gadget.begin(); while ((it->name != collector.value()) && (it != cfg.gadget.end())) it++; it++; cfg.gadget.erase(it,cfg.gadget.end()); std::stringstream o; GadgetronXML::serialize(cfg,o); node_xml_config_ = o.str(); Gadget* tmp = this; while (tmp->next()) { if (std::string(tmp->module()->name()) == collector.value()) break; tmp = dynamic_cast<Gadget*>(tmp->next()); } collect_gadget_ = tmp; if (!collect_gadget_) { GERROR("Failed to locate collector Gadget with name %s\n", collector.value().c_str()); return GADGET_FAIL; } else { collect_gadget_->set_parameter("pass_through_mode","true"); } // get current node ip addresses ACE_INET_Addr* the_addr_array = NULL; size_t num_of_ip = 0; int rc = ACE::get_ip_interfaces (num_of_ip, the_addr_array); if (rc != 0) { GERROR_STREAM("Retreive local ip addresses failed ... "); num_of_ip = 0; } if (the_addr_array!=NULL ) delete [] the_addr_array; for (size_t ii=0; ii<num_of_ip; ii++) { std::string ip = std::string(the_addr_array[ii].get_host_addr()); local_address_.push_back(ip); GDEBUG_STREAM("--> Local address : " << ip); } return GADGET_OK; }