00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <stdint.h>
00021 #include <stdbool.h>
00022 #include <stdlib.h>
00023 #include <string.h>
00024 #include <unistd.h>
00025
00026 #include "report.h"
00027 #include "invokelib.h"
00028
00029 void invoke_send_msg(int fd, uint32_t msg)
00030 {
00031 debug("%s: %08x\n", __FUNCTION__, msg);
00032 write(fd, &msg, sizeof(msg));
00033 }
00034
00035 bool invoke_recv_msg(int fd, uint32_t *msg)
00036 {
00037 uint32_t readBuf = 0;
00038 int len = sizeof(readBuf);
00039 ssize_t numRead = read(fd, &readBuf, len);
00040
00041 if (numRead == -1)
00042 {
00043 debug("%s: Error reading message: %s\n", __FUNCTION__, strerror(errno));
00044 *msg = 0;
00045 return false;
00046 }
00047 else if (numRead < len)
00048 {
00049 debug("%s: Error: unexpected end-of-file \n", __FUNCTION__);
00050 *msg = 0;
00051 return false;
00052 }
00053 else
00054 {
00055 debug("%s: %08x\n", __FUNCTION__, readBuf);
00056 *msg = readBuf;
00057 return true;
00058 }
00059 }
00060
00061 void invoke_send_str(int fd, char *str)
00062 {
00063 if (str)
00064 {
00065 uint32_t size;
00066
00067
00068 size = strlen(str) + 1;
00069 invoke_send_msg(fd, size);
00070
00071 debug("%s: '%s'\n", __FUNCTION__, str);
00072
00073
00074 write(fd, str, size);
00075 }
00076 }
00077