Moos Study notes-Multi-threading

Source: Internet
Author: User

/** A simple example showing how to use A comms client*/#include "moos/libmoos/comms/moosasynccommclient.h"#include "moos/libmoos/utils/commandlineparser.h"#include "moos/libmoos/utils/consolecolours.h"#include "moos/libmoos/utils/threadprint.h"Moos::threadprint gprinter (std:: cout);BOOLOnConnect (voidPparam) {cmooscommclient PC = reinterpret_ cast<cmooscommclient?> (pparam); Pc?>register ("X",0.0) ; Pc?>register ("Y",0.0) ; Pc?>register ("Z",0.0) ; Retu RNtrue;}BOOLOnmail (void? pparam) {Cmooscommclient *pc = Reinterpret _ Cast<cmooscommclient?> (Pparam); Moosmsg_list M;//Get the MailPc?>fetch (M); Moosmsg_list:: Iterator Q;//P R o C e s s i t for(Q=m.begin (); Q!=m.end (); q++) {Gprinter. Simplyprinttimeandmessage ("Mail:"+q?>getsource (), MOOS::-threadprint:: GREEN);} R ETU RN T RU e;BOOLFuncx (Cmoosmsg & M,void? Theparameteryousaidtopassontocallback) {Gprinter. Simplyprinttimeandmessage ("c A l l back F o r X", MOOS:: threadprint::-cyan); r ETU rn T RU e;}BOOLFuncy (Cmoosmsg & M,void? Theparameteryousaidtopassontocallback) {Gprinter. Simplyprinttimeandmessage ("c A l l back F o r Y", MOOS:: threadprint::-magenta); r ETU rn T RU e;} I n T Main (intARGC,Char? argv []) {//Unde R stand the command L N eMOOS:: Commandlineparser P (argc, argv); std:: string db_host="L o c a l h o s T"; P. GetVariable ("?? Moos_host ", db_host); i n t db_port =9000; P. GetVariable ("?? Moos_port ", db_port); std:: string my_name ="ex40"; P. GetVariable ("?? Moos_name ", my_name);//C o n f i g u r e the commsMOOS:: Moosasynccommclient Comms; Comms. Setonmailcallback (Onmail, &comms); Comms. Setonconnectcallback (OnConnect, &comms);//Here we add per message C a l l B a C K s//FI R S t parameter i s the Channel Nick?name, then the f u n c t i o n//to C a l l, then a parameter we want passed when c a l l b a C K i s//invokedComms.addmessagecallback ("Callback_x","X", Funcx, NULL); Comms.addmessagecallback ("Callback_y","Y", Funcy, NULL);//Start the comms runningComms. Run (Db_host, Db_port, my_name);//F o r ever loop sending dataSTD:: vector<unsigned Char> X ( +); F o r (;;) {Moospause (Ten) ; Comms.notify ("X", X);//For callback_xComms.notify ("Y","This is Y");//F o r callback_yComms.notify ("Z",7.0);//no callb a C k}return 0;}

Moos Learning notes-multithreading

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.