qnx pps
1、什么是pps
pps:Persistent Publish/Subscribe?
With?PPS, publishing is asynchronous: the subscriber need not be waiting for the publisher.
對于發布者來說是異步的,訂閱者也不需要等待發布者
In fact, the publisher and subscriber rarely know each other; their only connection is an object that has a meaning and purpose for both publisher and subscriber.
?
2、為什么需要pps
在默認狀態下,QNX PPS服務是作為推送式發布系統運行的;也就是說,發布者會將數據推送到對象中,訂閱者會根據通知或在閑暇時讀取數據。(手機app更新消息就是這樣)
但有些數據(如接口上的數據包計數)變化太快,因此無法通過使用默認推送發布的PPS有效地進行發布。為此,QNX PPS還提供了一種選項,允許訂閱者將PPS變成提取式發布系統。當訂閱者打開具有該選項的對象并發出一個read()調用時,該對象的所有發布者會收到一個通知以在對象中寫入當前數據。訂閱者的讀取會一直阻塞直至對象的數據得到更新并返回新的數據。利用這種提取機制,PPS訂閱者能按其需要的速度向發布者檢索數據,從而實現了真正意義上的按需發布。
3、pps 的功能作用
4、qnx 中如何使用pps
http://www.qnx.com/developers/docs/7.1/index.html#com.qnx.doc.pps.developer/topic/examples.html???????q???????http://www.qnx.com/developers/docs/7.1/index.html#com.qnx.doc.pps.developer/topic/examples.html
qnx 使用案例:
One publisher:
#include <stdlib.h> #include <stdio.h> #include <unistd.h> #include <fcntl.h> #include <string.h>int main(int argc, char *argv[]) {int fd;int state = 0;char buf[256];struct stat stat_buf;int count = 0;ssize_t len, bytes_written;/* Is PPS running? */if (stat( "/pps", &stat_buf) != 0){if (errno == ENOENT)printf ("The PPS server isn't running.\n");elseperror ("stat (/pps)");return EXIT_FAILURE;}/* Create the "button" object (if it doesn't already exist). */fd = open( "/pps/example/button", O_RDWR | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO );if ( fd < 0 ){perror ("Couldn't open /pps/example/button");return EXIT_FAILURE;}/* Loop forever, toggling the state of the button. */while ( 1 ){usleep (500);count++;len = snprintf(buf, 256, "state::%s\npub1::%d", state ? "on" : "off", count);bytes_written = write( fd, buf, len );if (bytes_written == -1){perror ("write()");}else if (bytes_written != len){printf ("Bytes written: %d String length: %d\n", bytes_written, len);}if ( state == 0 )state = 1;elsestate = 0;}return EXIT_SUCCESS; }One Subscribers:
#include <stdlib.h> #include <stdio.h> #include <unistd.h> #include <fcntl.h> #include <string.h>int main(int argc, char *argv[]) {int fd;char buf[256];int num_bytes;fd = open( "/pps/example/button?wait,delta", O_RDONLY );if ( fd < 0 ){perror ("Couldn't open /pps/example/button");return EXIT_FAILURE;}/* Loop, echoing the attributes of the button. */while (1){num_bytes = read( fd, buf, sizeof(buf) );if (num_bytes > 0){write (STDOUT_FILENO, buf, num_bytes);}}return EXIT_SUCCESS; }?
總結
- 上一篇: 高通软件发布版本简称
- 下一篇: camera 输入数据格式 lcd 显