Moos Learning notes 4--different callbacks for separate threads

Source: Internet
Author: User
Tags call back

Moos Learning notes 4--different callbacks for separate threads
/***@fn Independent thread different callback *@Version V1. 0*@author*/#include "moos/libmoos/comms/moosasynccommclient.h"#include "moos/libmoos/utils/commandlineparser.h"//control change the font color inside the class defines a number of colors#include "moos/libmoos/utils/consolecolours.h"#include "moos/libmoos/utils/threadprint.h"Moos::threadprint gprinter (std:: cout);BOOLOnConnect (void*pparam) {Cmooscommclient *pc =reinterpret_cast<CMOOSCommClient*> (Pparam); Pc->register ("X", 0.0) ; Pc->register ("Y", 0.0) ; Pc->register ("Z", 0.0) ;return true;}BOOLOnmail (void*pparam) {Cmooscommclient *pc =reinterpret_cast<CMOOSCommClient*> (Pparam); Moosmsg_list M;//Get the MailPc->fetch (M); Moosmsg_list::iterator Q;//Process it    for(Q=m.begin (); Q!=m.end (); q++) {//getsource (): Returns the name of the process that issued the notification      //simplyprinttimeandmessage (): Output thread-safe formatting information, the first parameter is the data to be output      //The second parameter is a color, default is nullGprinter.simplyprinttimeandmessage ("Mail:"+Q->getsource (), moos::threadprint::green); }return true;}BOOLFuncx (Cmoosmsg &m,void*theparameteryousaidtopassontocallback) {Gprinter.simplyprinttimeandmessage ("Call back for X" , MOOS:: Threadprint::cyan);return true;}BOOLFuncy (Cmoosmsg &m,void*theparameteryousaidtopassontocallback) {Gprinter.simplyprinttimeandmessage ("Call back for Y" , Moos::threadprint::magenta);return true;}intMainintARGC,Char*ARGV []) {//Understand the commandlineMoos::commandlineparser P (ARGC,ARGV); std::string db_host="localhost" ; P.getvariable ("--moos_host" , db_host);intDb_port =9000; P.getvariable ("--moos_port" , Db_port); std::string my_name ="ex40" ; P.getvariable ("--moos_name" , my_name);//Configure the CommsMoos::moosasynccommclient Comms;   Comms.setonmailcallback (Onmail, &comms); Comms.setonconnectcallback (OnConnect, &comms);/***@Name Addmessagecallback () *@FN Adds a callback function for each message *@Param[in] * The first one is the alias of the channel * The second is the variable that you want to pass when the callback occurs* @note Use this function to call the function specified, do not use the function to call the default Onmail ()*/Comms.addmessagecallback ("Callback_x","X",Funcx,null); Comms.addmessagecallback ("Callback_y","Y",Funcy,null);//Start the comms runningComms. Run (Db_host, Db_port, my_name);//Forever loop sending dataSTD:: vector<unsigned Char>x ( +) ; for( ; ; ) {Moospause ( +) ; Comms.notify ("X",X);//For callback_xComms.notify ("Y","This is Y");//For callback_yComms.notify ("Z",7.0);//no Callback}return 0;}

Moos Learning notes 4--different callbacks for separate threads

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.