Archived
3
0
This repository has been archived on 2024-06-18. You can view files and clone it, but cannot push or open issues or pull requests.
libipc-old/remote/lib/remotec.c

75 lines
1.7 KiB
C
Raw Normal View History

#include "../../core/communication.h"
#include "../../core/error.h"
2018-10-09 13:20:26 +02:00
#include "message.h"
#include "remotec.h"
#include "remoted.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
2018-10-04 00:30:47 +02:00
int remotec_connection (int argc, char **argv, char **env, struct ipc_service *srv)
{
2018-10-03 21:52:11 +02:00
int ret = ipc_application_connection (argc, argv, env
, srv, REMOTED_SERVICE_NAME, NULL, 0);
if (ret != 0) {
2018-10-03 21:24:20 +02:00
handle_err ("remote remotec_connection", "application_connection != 0");
}
return ret;
}
2018-10-04 00:30:47 +02:00
int remotec_disconnection (struct ipc_service *srv)
{
2018-10-03 21:52:11 +02:00
return ipc_application_close (srv);
}
2018-10-04 00:30:47 +02:00
int remotec_message_send (struct ipc_service *srv, const struct remoted_msg * m)
{
size_t msize = 0;
char * buf = NULL;
2018-10-03 21:52:11 +02:00
remote_message_serialize (m, &buf, &msize);
2018-10-03 22:02:37 +02:00
struct ipc_message m_data;
memset (&m_data, 0, sizeof (struct ipc_message));
// format the connection msg
2018-10-04 01:22:50 +02:00
if (ipc_message_format_data (&m_data, buf, msize) < 0) {
handle_err ("remotec_message_send", "ipc_message_format_data");
if (buf != NULL)
free (buf);
return -1;
}
2018-10-03 21:52:11 +02:00
ipc_application_write (srv, &m_data);
ipc_message_free (&m_data);
if (buf != NULL)
free(buf);
return 0;
}
2018-10-04 00:30:47 +02:00
int remotec_message_recv (struct ipc_service *srv, struct remoted_msg *m)
{
if (srv == NULL) {
2018-10-03 21:52:11 +02:00
handle_err ("remotec_message_recv", "srv == NULL");
return -1;
}
if (m == NULL) {
2018-10-03 21:52:11 +02:00
handle_err ("remotec_message_recv", "m == NULL");
return -1;
}
2018-10-03 22:02:37 +02:00
struct ipc_message m_recv;
memset (&m_recv, 0, sizeof (struct ipc_message));
2018-10-03 21:52:11 +02:00
ipc_application_read (srv, &m_recv);
2018-10-04 01:54:12 +02:00
remote_message_unserialize (m, m_recv.payload, m_recv.length);
2018-10-03 21:52:11 +02:00
ipc_message_free (&m_recv);
return 0;
}