void CInputEventsTranslator::activateKeyboardTranslation() { Messages::MessageType keyDown("KEYBOARD_KEYDOWN"); Messages::MessageType keyUp("KEYBOARD_KEYUP"); Messages::MessageType updateKeyboard("UPDATE_KEYBOARD"); DynamicObjectManager *dom = DynamicObjectManager::getInstancePtr(); shared_ptr< Gnoll::DynamicObject::DynamicObject > keyboardConfig = dom->load("keyboardConfig"); /** * How often will the keyboard module get updated (millisecond) */ unsigned long int period = 300; shared_ptr< Gnoll::DynamicObject::Integer > periodFromConfig = keyboardConfig->getAttribute< Gnoll::DynamicObject::Integer >("period"); period = *periodFromConfig; CMessageModule* messageModule = CMessageModule::getInstancePtr(); Messages::Messenger* messageManager = messageModule->getMessageManager(); keyboardEventsTranslator = shared_ptr<Messages::Listener> ( new CKeyboardEventsTranslator() ); keyboardEventsTrigger = shared_ptr<Messages::Listener> ( new CKeyboardEventsTrigger(static_pointer_cast<CKeyboardEventsTranslator>(keyboardEventsTranslator) )); keyboardStateTranslator = shared_ptr<Messages::Listener> ( new CKeyboardStateTranslator() ); try { /** * Continuous keyboard messages */ messageManager->addListener ( keyboardEventsTranslator, keyDown ); Gnoll::Log::CLogModule::getInstancePtr()->logMessage( "KeyboardEventsTranslator listener installed" ); messageManager->addListener ( keyboardEventsTranslator, keyUp ); Gnoll::Log::CLogModule::getInstancePtr()->logMessage( "KeyboardEventsTranslator listener installed" ); messageManager->addListener ( keyboardEventsTrigger, updateKeyboard ); Gnoll::Log::CLogModule::getInstancePtr()->logMessage( "KeyboardEventsTrigger listener installed" ); /** * State based keyboard messages */ messageManager->addListener ( keyboardStateTranslator, keyDown ); Gnoll::Log::CLogModule::getInstancePtr()->logMessage( "KeyboardStateTranslator listener installed" ); messageManager->addListener ( keyboardStateTranslator, keyUp ); Gnoll::Log::CLogModule::getInstancePtr()->logMessage( "KeyboardStateTranslator listener installed" ); } catch(...) { throw; } CTimeModule* timeModule = CTimeModule::getInstancePtr(); m_periodData = shared_ptr<boost::any> (new boost::any(period)) ; shared_ptr<CMessage> message (new CMessage(updateKeyboard, m_periodData )); timeModule->addPeriodicEvent(0, message, period); }
CMouseButtonEventsTranslator::CMouseButtonEventsTranslator(): mouseButtonPressedEvent("MOUSE_PRESSED"), mouseButtonReleasedEvent("MOUSE_RELEASED") { DynamicObjectManager *pom = DynamicObjectManager::getInstancePtr(); /** * Loading translation map : Keycode -> Action */ this->mouseButtonEventTranslationMap = pom->load("mouseButtonEventTranslationMap"); /** * Mouse config */ this->mouseConfig = pom->load("mouseConfig"); }
int main() { cout << "Hello world !" << endl; DynamicObject toto = DynamicObject("toto"); shared_ptr<Scalar<float> > pi( new Scalar<float>("float", 3.145) ); shared_ptr<Integer> age( new Integer(345) ); shared_ptr<Scalar<Glib::ustring> > phrase ( new Scalar<Glib::ustring>("string", "c'etait un cafard qui vivait dans le noir") ); toto.setAttribute( Glib::ustring("pi"), pi); toto.setAttribute( "phrase", phrase); toto.setAttribute( "age", age); cout << (*pi)() << endl; cout << (*phrase)() << endl; cout << "Toto has attribute 'pi' : " << toto.hasAttribute("pi") << endl; cout << "Toto has attribute 'phrase' : " << toto.hasAttribute("phrase") << endl; cout << "Toto has attribute 'tournoyant' : " << toto.hasAttribute("tournoyant") << endl; const Glib::ustring pi_name("pi"); shared_ptr<Scalar<float> > pi2 = toto.getAttribute< Scalar<float> > (pi_name); shared_ptr<Scalar<Glib::ustring> > phrase2 = toto.getAttribute< Scalar<Glib::ustring> > ("phrase"); cout << "Get attribute 'pi' : " << *pi2 << endl; cout << "Get attribute 'phrase' : " << *phrase2 << endl; try { shared_ptr<Scalar<Glib::ustring> > phrase3 = toto.getAttribute< Scalar<Glib::ustring> > ("aioli"); } catch(Glib::ustring e) { cout << e << endl; } cout << endl << "Serializationed (I'am sure it exists :) toto : " << endl; shared_ptr<xmlpp::Document> output = toto.serializeXML(); cout << output->write_to_string_formatted() << endl; SourceFile sf("./"); shared_ptr<IStream> stream = sf.loadStream("testpo.cpp"); unsigned int bytesRead = 0; while (!stream->eof()) { char buffer[256]; unsigned int nbRead = stream->read(buffer, 255); buffer[nbRead] = 0; // cout << buffer; bytesRead += nbRead; } stream->close(); cout << endl << "Bytes Read : " << bytesRead << endl; sf.setOverWrite(true); shared_ptr<IStream> streamW = sf.saveStream("testpo.cppW"); unsigned int bytesWritten = streamW->write("Jesuislorsdelajusticeetdel'emeriteca\nvalier", 40); streamW->close(); cout << endl << "Bytes Written : " << bytesWritten << endl; shared_ptr<ISource> loadChannel(new SourceFile(".", false)); shared_ptr<ISource> saveChannel(new SourceFile(".", true)); DynamicObjectManager *pom = DynamicObjectManager::getInstancePtr(); pom->addLoadSource(loadChannel); pom->addSaveSource(saveChannel); shared_ptr<DynamicObject> Zelda = pom->load("zelda"); shared_ptr<Integer> ageZelda = Zelda->getAttribute< Integer > ("age"); shared_ptr<Integer> newAge(new Integer((*ageZelda)() + 1)); Zelda->setAttribute("age2", newAge); try { shared_ptr< Float > piZelda = Zelda->getAttribute< Float > ("pi"); cout << "Float pi**2 zelda : " << (*piZelda) * (*piZelda) << endl; shared_ptr< String > nut = Zelda->getAttribute< String > ("nut"); cout << "Attribute nut = '" << *nut << "'" << endl; shared_ptr< Double > dpi = Zelda->getAttribute< Double > ("dpi"); cout << "Double PI in Zelda : " << setprecision(16) << *dpi << endl; cout << "Squared Double PI in Zelda : " << setprecision(16) << (*dpi) * (*dpi) << endl; typedef list< shared_ptr<IAttribute> >::iterator ListIterator; shared_ptr< List > list = Zelda->getAttribute< List > ("ListPreums"); for (ListIterator it = list->begin(); it != list->end(); it++) { if (shared_ptr<String> str = dynamic_pointer_cast<String>(*it)) { cout << "String element in list : '" << (*str) << "'" << endl; } if (shared_ptr<Integer> integer = dynamic_pointer_cast<Integer>(*it)) { cout << "Integer element in list : [" << (*integer) + 2 << "]" << endl; } if (shared_ptr<Double> dbl = dynamic_pointer_cast<Double>(*it)) { cout << "Double element in list : [" << (*dbl) << "]" << endl; } if (shared_ptr<Float> flt = dynamic_pointer_cast<Float>(*it)) { cout << "Float element in list : [" << (*flt) << "]" << endl; } } } catch(Glib::ustring e) { cout << e << endl; } pom->save(Zelda->getInstance()); cout << endl << "Serializationed (I'am sure it exists :) Zelda : " << endl; shared_ptr<xmlpp::Document> outputZelda = Zelda->serializeXML(); cout << outputZelda->write_to_string_formatted() << endl; cout << endl << endl << "--------------------------------------------" << endl << endl; shared_ptr<DynamicObject> Zelda2 = pom->load("zelda2"); shared_ptr<xmlpp::Document> outputZelda2 = Zelda2->serializeXML(); cout << outputZelda2->write_to_string_formatted() << endl; return 0; }
void CInputEventsTranslator::activateMouseButtonTranslation() { Messages::MessageType mousePressed("MOUSE_PRESSED"); Messages::MessageType mouseReleased("MOUSE_RELEASED"); Messages::MessageType updateMouse("UPDATE_MOUSE"); DynamicObjectManager *dom = DynamicObjectManager::getInstancePtr(); shared_ptr< Gnoll::DynamicObject::DynamicObject > mouseConfig = dom->load("mouseConfig"); /** * How often will the mouse button module get updated (millisecond) */ unsigned long int period = 300; shared_ptr< Gnoll::DynamicObject::Integer > periodFromConfig = mouseConfig->getAttribute< Gnoll::DynamicObject::Integer >("period"); period = *periodFromConfig; CMessageModule* messageModule = CMessageModule::getInstancePtr(); Messages::Messenger* messageManager = messageModule->getMessageManager(); mouseButtonEventsTranslator = shared_ptr<Messages::Listener> ( new CMouseButtonEventsTranslator() ); mouseButtonEventsTrigger = shared_ptr<Messages::Listener> ( new CMouseButtonEventsTrigger(static_pointer_cast<CMouseButtonEventsTranslator>(mouseButtonEventsTranslator) ) ); mouseButtonStateTranslator = shared_ptr<Messages::Listener> ( new CMouseButtonStateTranslator() ); try { /** * Continuous mouse messages */ messageManager->addListener ( mouseButtonEventsTranslator, mousePressed ); Gnoll::Log::CLogModule::getInstancePtr()->logMessage( "mouseButtonEventsTranslator listener installed for MOUSE_PRESSED" ); messageManager->addListener ( mouseButtonEventsTranslator, mouseReleased ); Gnoll::Log::CLogModule::getInstancePtr()->logMessage( "mouseButtonEventsTranslator listener installed for MOUSE_RELEASED" ); messageManager->addListener ( mouseButtonEventsTrigger, updateMouse ); Gnoll::Log::CLogModule::getInstancePtr()->logMessage ( "mouseButtonEventsTrigger listener installed" ); /** * State based mouse messages */ messageManager->addListener ( mouseButtonStateTranslator, mousePressed ); Gnoll::Log::CLogModule::getInstancePtr()->logMessage ( "mouseButtonStateTranslator listener installed for MOUSE_PRESSED" ); messageManager->addListener ( mouseButtonStateTranslator, mouseReleased ); Gnoll::Log::CLogModule::getInstancePtr()->logMessage ( "mouseButtonStateTranslator listener installed for MOUSE_RELEASED" ); } catch(...) { throw; } CTimeModule* timeModule = CTimeModule::getInstancePtr(); m_periodData = shared_ptr<boost::any> (new boost::any(period)) ; shared_ptr<CMessage> message (new CMessage(updateMouse, m_periodData )); timeModule->addPeriodicEvent(0, message, period); }
DynamicObjectProxy::DynamicObjectProxy(string instanceName) { DynamicObjectManager* pom = DynamicObjectManager::getInstancePtr(); m_self = pom->load(instanceName); }