Created
May 29, 2020 14:35
-
-
Save fernandoc1/b31c75e0fe7e572bc86b7b05232db60c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "shared_memory_communicator.hpp" | |
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <string.h> | |
| enum | |
| { | |
| MSG_DV_TYPE_START = 0, | |
| MSG_DV_TYPE_MSG1, | |
| MSG_DV_TYPE_MSG2, | |
| MSG_DV_TYPE_MSG3, | |
| MSG_DV_TYPE_MSG4, | |
| MSG_DV_TYPE_MSG5, | |
| MSG_DV_TYPE_MSG6, | |
| MSG_DV_TYPE_MSG7, | |
| MSG_DV_TYPE_MSG8, | |
| MSG_DV_TYPE_END | |
| }; | |
| #define DV_MSG_KEY 0x61766C79 | |
| struct MsgStr | |
| { | |
| long type; | |
| char msg[128]; | |
| }; | |
| int main(int argc, char** argv) | |
| { | |
| SharedMemoryCommunicator shm(DV_MSG_KEY, MSG_DV_TYPE_MSG1); | |
| MsgStr msgStr; | |
| memset(&msgStr, 0, sizeof(MsgStr)); | |
| msgStr.type = MSG_DV_TYPE_MSG1; | |
| int ret = shm.recvMessage(&msgStr, sizeof(msgStr)); | |
| printf("RET=%d : MSG=%s\n", ret, msgStr.msg); | |
| return 0; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "shared_memory_communicator.hpp" | |
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <string.h> | |
| enum | |
| { | |
| MSG_DV_TYPE_START = 0, | |
| MSG_DV_TYPE_MSG1, | |
| MSG_DV_TYPE_MSG2, | |
| MSG_DV_TYPE_MSG3, | |
| MSG_DV_TYPE_MSG4, | |
| MSG_DV_TYPE_MSG5, | |
| MSG_DV_TYPE_MSG6, | |
| MSG_DV_TYPE_MSG7, | |
| MSG_DV_TYPE_MSG8, | |
| MSG_DV_TYPE_END | |
| }; | |
| #define DV_MSG_KEY 0x61766C79 | |
| struct MsgStruct | |
| { | |
| long type; | |
| char buf[128]; | |
| }; | |
| int main(int argc, char** argv) | |
| { | |
| SharedMemoryCommunicator shm(DV_MSG_KEY, MSG_DV_TYPE_MSG1); | |
| char msg[] = "ABCDEFG"; | |
| MsgStruct msgStr; | |
| memset(&msgStr, 0, sizeof(msgStr)); | |
| msgStr.type = MSG_DV_TYPE_MSG1; | |
| strcpy(msgStr.buf, msg); | |
| shm.sendMessage(&msgStr, sizeof(msgStr)); | |
| /* | |
| int queueId; | |
| key_t key = DV_MSG_KEY; | |
| queueId = msgget(key, 0); | |
| if(queueId < 0) | |
| { | |
| queueId = msgget(key, IPC_CREAT|0666); | |
| printf("Created queue id: %d\n", queueId); | |
| } | |
| printf("Queue id:%d\n", queueId); | |
| */ | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment