Poco c ++ library learning and analysis-notifications and events (1) 1. information exchange methods before discussing events and notifications in Poco, we will first talk about information exchange methods, which may help us understand the subsequent discussions. We all know that there is a relationship between data. In the database model, the relationship is divided into one-to-one, one-to-many, and many-to-many. When using computers to solve data relationships, many-to-many relationships are often divided into several one-to-many relationships, and one-to-many relationships are eventually divided into several one-to-one relationships. If you look at the message flow from a relational perspective, one or more initiators exist in the message, that is, the Source of the message. The message also has one or more receivers, that is, the Target object; at the same time, the Message itself has content, that is, multiple messages. Simplified to the final one-to-one model to describe messages. The three elements in this model are Source, Message, and Target. Put this model in the C ++ language. Source, Message, and Target are abstracted into three classes respectively. The message transmission method can be written into the following two methods: 1.1 Placement Model for programming languages to consider the issue from the perspective of the message source, the entire message sending process is:) the target registers with the message Source, Source. the Register (Target) function implementation is roughly like this [cpp] Source. register (Target) {source. vec. add (Target);} B) the message generates Source create a msg c) the message is sent, soure. the above function of Send (Msg) is roughly as follows: [cpp] Soucre. send (Msg) {Target. receive (Msg);} Target. the implementation of the Receive (Msg) function is roughly like this, [cpp] Target. receive (Msg) {switch (Msg) {case Msg1: doing something; case Msg2: doing somet Hing; default: doing something;} is the most common method to call. When I first wrote C code, I started to use it. It was also in the C ++ era. From another perspective, in the C ++ era, everything is an object. From the message perspective, the entire message sending process becomes: a) the target registers with the message, Msg. register (Target); Msg. the Register (Target) function implementation is roughly like this [cpp] Msg. register (Target) Msg. vec. add (Target); B) Message generation a msg create by some one source c) message sending, Msg. send (Source) Msg. the implementation of the Send (Source) function is roughly like this. [cpp] Msg. send (Source) {switch (Source) {case Source1: doing something; case Source2: doing something; default: doing something;} the above is the notifications and events in Poco. General idea. Notifications are considered from the perspective of the message source, while events are considered from the perspective of messages. In one sentence, events and proxies in Poco come from C #. That is to say, analyzing events in Poco is actually interpreting the proxy and event implementation of c. 1.2 place the model in a multi-threaded environment. Let's leave the language aside and put the message passing process into multiple threads. What should I do with multithreading? The message is generated for final processing. What if the message processing is time consuming? No way, no silver in your pocket. How can we say that, Gao fushuai has soared to hardware, and he has made algorithms. After all, we are not all in the Ministry of Railways, right? Since it is not a good idea to put the generation and processing of messages in two threads, there is no doubt that the efficiency of message processing has been improved. This is the producer and consumer model. Www.2cto.com if you want to consider this issue, we get another division of message transmission. Synchronously process messages and asynchronously process messages. Therefore, we can divide the message transmission process into the following four types: Notification | event | synchronization (supported) | (supported) --------- asynchronous (supported) |