blob: 237bb60f97a738fdffa1d13e4c391bbcb11a0e51 [file] [log] [blame]
San Mehatfa644ff2009-05-08 11:15:53 -07001#include <alloca.h>
2#include <errno.h>
3#include <sys/types.h>
4#include <pthread.h>
5
6#define LOG_TAG "FrameworkClient"
7#include <cutils/log.h>
8
9#include <sysutils/FrameworkClient.h>
10
11FrameworkClient::FrameworkClient(int socket) {
12 mSocket = socket;
13 pthread_mutex_init(&mWriteMutex, NULL);
14}
15
16int FrameworkClient::sendMsg(char *msg) {
17 LOGD("FrameworkClient::sendMsg(%s)", msg);
18 if (mSocket < 0) {
19 errno = EHOSTUNREACH;
20 return -1;
21 }
22
23 pthread_mutex_lock(&mWriteMutex);
24 if (write(mSocket, msg, strlen(msg) +1) < 0) {
25 LOGW("Unable to send msg '%s' (%s)", msg, strerror(errno));
26 }
27 pthread_mutex_unlock(&mWriteMutex);
28 return 0;
29}
30
31int FrameworkClient::sendMsg(char *msg, char *data) {
32 char *buffer = (char *) alloca(strlen(msg) + strlen(data) + 1);
33 if (!buffer) {
34 errno = -ENOMEM;
35 return -1;
36 }
37 strcpy(buffer, msg);
38 strcat(buffer, data);
39 return sendMsg(buffer);
40}
41