FunctionPointerRJ(T *object, void (T::*member)(void)) { attach(object, member); }
GPS::GPS(PinName tx, PinName rx) : RawSerial(tx, rx) { RawSerial::baud(57600); attach(this, &GPS::RxIrqHandler); }
Shader::ShaderLoader Shader::ShaderLoader::attachPS( ShaderSourcePtr src ) { return attach( GL_FRAGMENT_SHADER_ARB, src ); }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //Module implementation bool SpeechRecognizerModule::configure(ResourceFinder &rf ) { setName( rf.check("name",Value("speechRecognizer")).asString().c_str() ); m_timeout = rf.check("timeout",Value(10000)).asInt(); USE_LEGACY = !rf.check("noLegacy"); m_forwardSound = rf.check("forwardSound"); m_tmpFileFolder = rf.getHomeContextPath().c_str(); interruptRecognition = false; //Deal with speech recognition string grammarFile = rf.check("grammarFile",Value("defaultGrammar.grxml")).asString().c_str(); grammarFile = rf.findFile(grammarFile).c_str(); std::wstring tmp = s2ws(grammarFile); LPCWSTR cwgrammarfile = tmp.c_str(); m_useTalkBack = rf.check("talkback"); //Initialise the speech crap bool everythingIsFine = true; HRESULT hr; everythingIsFine = SUCCEEDED( m_cpRecoEngine.CoCreateInstance(CLSID_SpInprocRecognizer)); everythingIsFine &= SUCCEEDED( SpCreateDefaultObjectFromCategoryId(SPCAT_AUDIOIN, &m_cpAudio)); everythingIsFine &= SUCCEEDED( m_cpRecoEngine->CreateRecoContext( &m_cpRecoCtxt )); // Here, all we are interested in is the beginning and ends of sounds, as well as // when the engine has recognized something const ULONGLONG ullInterest = SPFEI(SPEI_RECOGNITION); everythingIsFine &= SUCCEEDED(m_cpRecoCtxt->SetInterest(ullInterest, ullInterest)); // set the input for the engine everythingIsFine &= SUCCEEDED( m_cpRecoEngine->SetInput(m_cpAudio, TRUE)); everythingIsFine &= SUCCEEDED( m_cpRecoEngine->SetRecoState( SPRST_ACTIVE )); //Load grammar from file everythingIsFine &= SUCCEEDED( m_cpRecoCtxt->CreateGrammar( 1, &m_cpGrammarFromFile )); everythingIsFine &= SUCCEEDED( m_cpGrammarFromFile->SetGrammarState(SPGS_DISABLED)); everythingIsFine &= SUCCEEDED( m_cpGrammarFromFile->LoadCmdFromFile(cwgrammarfile, SPLO_DYNAMIC)); // everythingIsFine &= loadGrammarFromRf(rf); //Create a runtime grammar everythingIsFine &= SUCCEEDED( m_cpRecoCtxt->CreateGrammar( 2, &m_cpGrammarRuntime )); everythingIsFine &= SUCCEEDED( m_cpGrammarRuntime->SetGrammarState(SPGS_DISABLED)); //Create a dictation grammar everythingIsFine &= SUCCEEDED(m_cpRecoCtxt->CreateGrammar( GID_DICTATION, &m_cpGrammarDictation )); everythingIsFine &= SUCCEEDED(m_cpGrammarDictation->LoadDictation(NULL, SPLO_STATIC)); everythingIsFine &= SUCCEEDED(m_cpGrammarDictation->SetDictationState(SPRS_INACTIVE)); //Setup thing for the raw audio processing everythingIsFine &= SUCCEEDED(m_cAudioFmt.AssignFormat(SPSF_22kHz16BitMono)); hr = m_cpRecoCtxt->SetAudioOptions(SPAO_RETAIN_AUDIO, &m_cAudioFmt.FormatId(), m_cAudioFmt.WaveFormatExPtr()); //everythingIsFine &= SUCCEEDED(hr = SPBindToFile((const WCHAR *)"C:\\temp.wav", SPFM_CREATE_ALWAYS, &m_streamFormat, &m_cAudioFmt.FormatId(), m_cAudioFmt.WaveFormatExPtr())); //CComPtr <ISpStream> cpStream = NULL; //CSpStreamFormat cAudioFmt; //hr = cAudioFmt.AssignFormat(SPSF_22kHz16BitMono); //hr = SPBindToFile((const WCHAR *)"c:\\ttstemp.wav", SPFM_CREATE_ALWAYS, &cpStream, &cAudioFmt.FormatId(), cAudioFmt.WaveFormatExPtr()); if( everythingIsFine ) { string pName = "/"; pName += getName().c_str(); pName += "/recog/continuous:o"; m_portContinuousRecognition.open( pName.c_str() ); pName = "/"; pName += getName().c_str(); pName += "/recog/continuousGrammar:o"; m_portContinuousRecognitionGrammar.open( pName.c_str() ); pName = "/"; pName += getName().c_str(); pName += "/recog/sound:o"; m_portSound.open(pName.c_str()); //iSpeak pName = "/"; pName += getName().c_str(); pName += "/tts/iSpeak:o"; m_port2iSpeak.open( pName.c_str() ); pName = "/"; pName += getName().c_str(); pName += "/tts/iSpeak/rpc"; m_port2iSpeakRpc.open( pName.c_str() ); if (Network::connect(m_port2iSpeak.getName().c_str(),"/iSpeak")&&Network::connect(m_port2iSpeakRpc.getName().c_str(),"/iSpeak/rpc")) yInfo() <<"Connection to iSpeak succesfull" ; else yWarning() <<"Unable to connect to iSpeak. Connect manually." ; pName = "/"; pName += getName().c_str(); pName += "/rpc"; m_portRPC.open( pName.c_str() ); attach(m_portRPC); //Start recognition //everythingIsFine &= SUCCEEDED(m_cpRecoEngine->SetRecoState(SPRST_ACTIVE_ALWAYS)); everythingIsFine &= SUCCEEDED(m_cpGrammarFromFile->SetRuleState(NULL, NULL, SPRS_ACTIVE)); everythingIsFine &= SUCCEEDED( m_cpGrammarFromFile->SetGrammarState(SPGS_ENABLED)); } return (everythingIsFine); }
int NFP::shm::RatingsShmSegment::load() { std::ifstream in(dataFileName_.c_str()); if (in.is_open()) { LOG(INFO) << "Parsing file " << dataFileName_; std::string line; int movie_id = -1; int user_id = -1; int rate = -1; char date[11]; std::list<NFP::model::Rating*> ratings; while (!in.eof()) { getline(in, line); if (movie_id == -1) { sscanf(line.c_str(), "%d", &movie_id); } else { if (sscanf(line.c_str(), "%d,%d,%s", &user_id, &rate, (char*)&date) == 3) { NFP::model::Rating* r = new NFP::model::Rating(movie_id, user_id, rate, std::string(date)); ratings.push_back(r); } } } in.close(); LOG(INFO) << "File read for movie " << movie_id << ", " << ratings.size() << " ratings found."; std::ofstream out(keyFileName_.c_str()); out << ratings.size() << std::endl; out.close(); size(ratings.size() * RATING_DATA_SIZE); int err = 0; if (create()) { LOG(ERROR) << "An error occured while creating shm segment"; err++; } if (attach()) { LOG(ERROR) << "An error occured while attaching shm segment"; err++; } if (err == 0) { LOG(INFO) << "Loading ShmSegment (size " << size() << ") ..."; int i = 0; std::list<NFP::model::Rating*>::const_iterator it; char* data = new char[RATING_DATA_SIZE]; for (it = ratings.begin(); it != ratings.end(); it++) { (*it)->data(data); memcpy((NFP::model::Rating*)(ptr()) + i, data, RATING_DATA_SIZE); i++; } LOG(INFO) << "... done"; } return 0; } else { LOG(ERROR) << "Unable to open file \"" << keyFileName_ << "\" for reading."; return -1; } }
void application::attach(application *app,std::string const &name,std::string const &url) { attach(app); mapper().mount(name,url,*app); }
template <> inline ElementProxy< ::jace::proxy::java::lang::Throwable >::ElementProxy(jarray array, jvalue element, int _index): ::jace::proxy::java::lang::Throwable(element), index(_index) { JNIEnv* env = attach(); parent = static_cast<jarray>(newGlobalRef(env, array)); }
/// \brief Opens \p filename in the given mode. /// \warning The string at \p filename must exist until the object is closed. void fstream::open (const char* filename, openmode mode, mode_t perms) { int nfd = ::open (filename, om_to_flags(mode), perms); attach (nfd, filename); }
void CInventoryOwner::OnItemSlot (CInventoryItem *inventory_item, EItemPlace previous_place) { attach (inventory_item); }
void ROPWM::write(byte pwmVal) { // make sure we're attached attach(); RobotOpen.writePWM(_channel, pwmVal < 255 ? pwmVal : 254); }
Object* World::attach(Object* obj) { return attach(obj->getName(), obj); }
void dv_selector_widget::set_source_count(unsigned count) { if (count > thumbnails_.size()) { resize(count, 1); mixer::source_id first_new_source_id = thumbnails_.size(); try { thumbnails_.resize(count); for (mixer::source_id i = first_new_source_id; i != count; ++i) { unsigned column = 1; unsigned row = i * row_multiplier; if (0)//(i != 0 && i != count - 1) { Gtk::HSeparator * sep = manage(new Gtk::HSeparator); sep->show(); attach(*sep, column - 1, column, row, row + row_multiplier, Gtk::FILL, Gtk::FILL, 0, 0); } dv_thumb_display_widget * thumb = manage(new dv_thumb_display_widget); thumb->show(); attach(*thumb, column + column_display, column + column_display + 1, row, row + row_multiplier, Gtk::FILL, Gtk::FILL, 0, 0); thumbnails_[i] = thumb; char label_text[4]; snprintf(label_text, sizeof(label_text), (i < 9) ? "_%u" : "%u", unsigned(1 + i)); Gtk::Label * label = manage(new Gtk::Label(label_text, true)); label->show(); attach(*label, column + column_labels, column + column_labels + 1, row + row_text_label, row + row_text_label + 1, Gtk::FILL, Gtk::FILL, 0, 0); Gtk::RadioButton * pri_video_button = create_radio_button(pri_video_button_group_, pri_video_source_pixbuf_); pri_video_button->signal_pressed().connect( sigc::bind( sigc::mem_fun(*this, &dv_selector_widget::on_pri_video_selected), i)); pri_video_button->show(); attach(*pri_video_button, column + column_labels, column + column_labels + 1, row + row_pri_video_button, row + row_pri_video_button + 1, Gtk::FILL, Gtk::FILL, 0, 0); Gtk::RadioButton * audio_button = create_radio_button(audio_button_group_, audio_source_pixbuf_); audio_button_list_.push_back(audio_button); // disable by default, if not in expert mode audio_button->set_sensitive(expert_mode ? true : false); audio_button->signal_pressed().connect( sigc::bind( sigc::mem_fun(*this, &dv_selector_widget::on_audio_selected), i)); audio_button->show(); attach(*audio_button, column + column_labels, column + column_labels + 1, row + row_audio_button, row + row_audio_button + 1, Gtk::FILL, Gtk::FILL, 0, 0); if (i < 9) { // Make the mnemonic on the label work. Also make // the numeric keypad and Alt-keys work. label->set_mnemonic_widget(*pri_video_button); pri_video_button->add_accelerator("activate", accel_group_, GDK_KP_1 + i, Gdk::ModifierType(0), Gtk::AccelFlags(0)); pri_video_button->signal_activate().connect( sigc::bind( sigc::mem_fun( *this, &dv_selector_widget::on_pri_video_selected), i)); audio_button->add_accelerator("activate", accel_group_, '1' + i, Gdk::MOD1_MASK, Gtk::AccelFlags(0)); audio_button->add_accelerator("activate", accel_group_, GDK_KP_1 + i, Gdk::MOD1_MASK, Gtk::AccelFlags(0)); audio_button->signal_activate().connect( sigc::bind( sigc::mem_fun( *this, &dv_selector_widget::on_audio_selected), i)); } } } catch (std::exception & e) { // Roll back size changes thumbnails_.resize(first_new_source_id); std::cerr << "ERROR: Failed to add source display: " << e.what() << "\n"; } } }
void local_actor::monitor(const actor_addr& whom) { if (!whom) return; auto ptr = detail::raw_access::get(whom); ptr->attach(attachable_ptr{new down_observer(address(), whom)}); }
rendering_buffer::rendering_buffer(byte* buf, unsigned int width, unsigned int height, int stride) : m_impl(0) { attach(buf, width, height, stride); }
void Dispatcher::link(int fd, DispatcherMask mask, IOHandler* handler) { if (fd < 0 || fd >= NOFILE) { abort(); } attach(fd, mask, handler); }
uint8_t Servo::attach(int pin) { return attach(pin, MIN_PULSE_WIDTH, MAX_PULSE_WIDTH); }
int CFilePool::attach(CHFile& _file, void* _context, u_int32 _flag) { return attach((handle_t)_file, _context, _flag); }
storage(self&& value) { attach(value); }
void application::attach(application *app,std::string const &name,std::string const &url,std::string const ®ex,int part) { attach(app); dispatcher().mount(regex,*app,part); mapper().mount(name,url,*app); }
static SANE_Status attach_one(const char *devnam) { attach (devnam, NULL); return SANE_STATUS_GOOD; }
template <> inline ElementProxy< ::jace::proxy::java::lang::Throwable >::ElementProxy(const jace::ElementProxy< ::jace::proxy::java::lang::Throwable >& proxy): ::jace::proxy::java::lang::Throwable(proxy), index(proxy.index) { JNIEnv* env = attach(); parent = static_cast<jarray>(newGlobalRef(env, proxy.parent)); }
module_loader(const wchar_t * module_name, bool attached = false) : m_attached(false) , m_module(NULL) { attached ? attach(module_name) : load(module_name); }
static SANE_Status attach_one (const char *devname) { return attach (devname, 0, SANE_FALSE); }
Spi::Spi(int MOSI_pin, int MISO_pin, int SCK_pin, int CS_pin0, int CS_pin1, int CS_pin2, int CS_pin3) { m_bps = 400000; attach(MOSI_pin, MISO_pin, SCK_pin, CS_pin0, CS_pin1, CS_pin2, CS_pin3); }
Attachment (OpenGLContext& c, Component& comp) : ComponentMovementWatcher (&comp), context (c) { if (canBeAttached (comp)) attach(); }
do_rooms() { int i; struct room *rp; struct linked_list *item; struct thing *tp; int left_out; coord top; coord bsze; coord mp; /* * bsze is the maximum room size */ bsze.x = COLS / 3; bsze.y = (LINES - 2) / 3; /* * Clear things for a new level */ for (rp = rooms; rp < &rooms[MAXROOMS]; rp++) rp->r_nexits = rp->r_flags = rp->r_fires = 0; /* * Put the gone rooms, if any, on the level */ left_out = rnd(4); for (i = 0; i < left_out; i++) rooms[rnd_room()].r_flags |= ISGONE; /* * dig and populate all the rooms on the level */ for (i = 0, rp = rooms; i < MAXROOMS; rp++, i++) { bool has_gold = FALSE; /* * Find upper left corner of box that this room goes in */ top.x = (i % 3) * bsze.x; top.y = i / 3 * bsze.y + 1; if (rp->r_flags & ISGONE) { /* * Place a gone room. Make certain that there is a * blank line for passage drawing. */ do { rp->r_pos.x = top.x + rnd(bsze.x - 2) + 1; rp->r_pos.y = top.y + rnd(bsze.y - 2) + 1; rp->r_max.x = -COLS; rp->r_max.x = -LINES; } while (rp->r_pos.y < 1 || rp->r_pos.y > LINES - 3); continue; } if (rnd(80) < level - 15) rp->r_flags |= ISDARK; /* * Find a place and size for a random room */ do { rp->r_max.x = rnd(bsze.x - 4) + 4; rp->r_max.y = rnd(bsze.y - 4) + 4; rp->r_pos.x = top.x + rnd(bsze.x - rp->r_max.x); rp->r_pos.y = top.y + rnd(bsze.y - rp->r_max.y); } while (rp->r_pos.y == 0); /* Draw the room */ draw_room(rp); /* * Put the gold in */ if (rnd(100) < 50 && (!has_artifact || level >= max_level)) { struct linked_list *item; struct object *cur; coord tp; has_gold = TRUE; /* This room has gold in it */ item = spec_item(GOLD, NULL, NULL, NULL); cur = OBJPTR(item); /* Put it somewhere */ rnd_pos(rp, &tp); cur->o_pos = tp; /* Put the gold into the level list of items */ add_obj(item, tp.y, tp.x); if (roomin(&tp) != rp) { endwin(); abort(); } } /* * Put the monster in */ if (rnd(100) < (has_gold ? 80 : 40)) { short which; int i, count; item = new_item(sizeof *tp); tp = THINGPTR(item); do { rnd_pos(rp, &mp); } while (mvwinch(stdscr, mp.y, mp.x) != FLOOR); which = randmonster(NOWANDER, NOGRAB); new_monster(item, which, &mp, NOMAXSTATS); /* * See if we want to give it a treasure to carry * around. */ if (rnd(100) < monsters[tp->t_index].m_carry) attach(tp->t_pack, new_thing()); /* * If it has a fire, mark it */ if (on(*tp, HASFIRE)) { rp->r_flags |= HASFIRE; rp->r_fires++; } /* * If it carries gold, give it some */ if (on(*tp, CARRYGOLD)) { struct object *cur; item = spec_item(GOLD, NULL, NULL, NULL); cur = OBJPTR(item); cur->o_count = GOLDCALC + GOLDCALC + GOLDCALC; cur->o_pos = tp->t_pos; attach(tp->t_pack, item); } i = rnd(7); if (on(*tp, ISSWARM) && i < 5) count = roll(2, 4); else if (on(*tp, ISFLOCK) && i < 5) count = roll(1, 4); else count = 0; for (i = 1; i <= count; i++) { coord *mpos; if ((mpos = place_mons(mp.y, mp.x)) != NULL) { struct linked_list *nitem; nitem = new_item(sizeof(struct thing)); new_monster(nitem, which, mpos, NOMAXSTATS); /* * If the monster is on a trap, trap * it */ if (isatrap(mvinch(mpos->y, mpos->x))) be_trapped(THINGPTR(nitem), mp); if (on(*tp, ISFRIENDLY)) turn_on(*(THINGPTR(nitem)), ISFRIENDLY); else turn_off(*(THINGPTR(nitem)), ISFRIENDLY); } } if (count > 0) { int boost = rnd(3) + 1; if (on(*tp, LOWCAST) || on(*tp, MEDCAST) || on(*tp, HIGHCAST)) turn_on(*tp, CANCAST); tp->t_stats.s_hpt += 3 * boost; tp->t_stats.s_arm -= 2 * boost; tp->t_stats.s_lvl += 2 * boost; tp->t_stats.s_str += 2 * boost; tp->t_stats.s_intel += 2 * boost; tp->t_stats.s_exp += 4 * boost * monsters[which].m_add_exp; } } } }
/* * Configure method, connect to different subsystem */ bool abmInteraction::configure(yarp::os::ResourceFinder &rf) { string moduleName = rf.check("name", Value("abmInteraction")).asString().c_str(); setName(moduleName.c_str()); nameGrammarHumanFeedback = rf.findFileByName(rf.check("nameGrammarHumanFeedback", Value("hFeedback.xml")).toString()); //nameGrammarHumanFeedback = rf.findFileByName(rf.check("nameGrammarHumanFeedback", Value("hFeedbackDescription")).toString()); nameGrammarYesNo = rf.findFileByName(rf.check("nameGrammarYesNo", Value("nodeYesNo.xml")).toString()); cout << moduleName << ": finding configuration files..." << endl; period = rf.check("period", Value(0.1)).asDouble(); //tryAgain = false ; //at start, iCub will explain and speaks //bestRank = 0 ; //Create an iCub Client and check that all dependencies are here before starting bool isRFVerbose = false; iCub = new ICubClient(moduleName, "abmInteraction", "client.ini", isRFVerbose); iCub->opc->isVerbose = false; if (!iCub->connect()) { cout << "iCubClient : Some dpeendencies are not running..." << endl; Time::delay(1.0); } rpc.open(("/" + moduleName + "/rpc").c_str()); attach(rpc); if (!iCub->getRecogClient()) { cout << "WARNING SPEECH RECOGNIZER NOT CONNECTED" << endl; } if (!iCub->getABMClient()) { cout << "WARNING ABM NOT CONNECTED" << endl; } rememberedInstance = rf.check("rememberedInstance", Value(1333)).asInt(); agentName = rf.check("agentName", Value("Bob")).asString().c_str(); img_provider_port = rf.check("img_provider_port", Value("/icub/camcalib/left/out/kinematic_structure")).asString().c_str(); //resume : no (take all the augmented_time from the instance) //resume : yes (take only the augmented_time without feedback from the instance) //resume : agent (take only the augmented_time with no feedback from the agent, from the instance) resume = rf.check("resume", Value("agent")).asString().c_str(); it_augmentedTime = vAugmentedTime.begin(); /*pair<string, int> bestTimeAndRank("", -1); if (createAugmentedTimeVector(bestTimeAndRank) == -1){ yError() << " Something is wrong with the augmented memories! quit"; return false; }*/ //testing /*Bottle bRecognized; bool blop = true; while (blop){ iCub->say("Check for sending a grammar"); bRecognized = iCub->getRecogClient()->recogFromGrammarLoop(grammarToString(nameGrammarHumanFeedback)); yInfo() << "bRecognized " << bRecognized.toString(); cout << bRecognized.get(1).toString() << endl; bRecognized.clear(); } */ //end testing return true; }
channel(reactor_t& reactor, const std::shared_ptr<socket_type>& socket): rd(new decoder<readable_stream<socket_type>>()), wr(new encoder<writable_stream<socket_type>>()) { attach(reactor, socket); }
Shader::ShaderLoader Shader::ShaderLoader::attachVS( ShaderSourcePtr src ) { return attach( GL_VERTEX_SHADER_ARB, src ); }
void CSoundRender_TargetA::source_changed() { dettach(); attach(); }