2017-08-25 11:42:43 +02:00
|
|
|
#include "../../core/communication.h"
|
2017-08-23 20:57:44 +02:00
|
|
|
#include "../../core/error.h"
|
|
|
|
#include "../lib/remoted.h"
|
2017-08-28 00:03:35 +02:00
|
|
|
#include "../lib/remotec.h"
|
|
|
|
#include "../lib/msg.h"
|
2017-08-23 20:57:44 +02:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <pthread.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
void usage (char **argv) {
|
|
|
|
printf ( "usage: %s uri service\n", argv[0]);
|
|
|
|
}
|
|
|
|
|
2017-08-25 11:42:43 +02:00
|
|
|
#if 0
|
2017-08-23 20:57:44 +02:00
|
|
|
void * listener (void *params)
|
|
|
|
{
|
|
|
|
int s = 0;
|
|
|
|
s = pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, NULL);
|
|
|
|
if (s != 0) {
|
|
|
|
handle_err ("listener", "pthread_setcancelstate != 0");
|
|
|
|
}
|
|
|
|
|
|
|
|
struct service *srv = NULL;
|
|
|
|
srv = (struct service *) params;
|
|
|
|
if (srv == NULL) {
|
|
|
|
handle_err ("listener", "no service passed");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// main loop
|
|
|
|
while (1) {
|
2017-08-28 00:03:35 +02:00
|
|
|
struct remoted_msg m;
|
|
|
|
memset (&m, 0, sizeof (struct remoted_msg));
|
2017-08-23 20:57:44 +02:00
|
|
|
|
|
|
|
remote_msg_recv (srv, &m);
|
|
|
|
printf ("\r\033[31m>\033[00m %s\n", m.data);
|
|
|
|
print_cmd ();
|
|
|
|
|
|
|
|
remote_msg_free (&m);
|
|
|
|
}
|
|
|
|
|
|
|
|
pthread_exit (NULL);
|
|
|
|
}
|
2017-08-25 11:42:43 +02:00
|
|
|
#endif
|
2017-08-23 20:57:44 +02:00
|
|
|
|
|
|
|
void main_loop (int argc, char **argv, char **env
|
|
|
|
, int index, int version, char *uri, char *service)
|
|
|
|
{
|
|
|
|
printf ("connection to remoted: index %d version %d uri %s service %s\n"
|
|
|
|
, index, version, uri, service);
|
|
|
|
|
2017-08-25 11:42:43 +02:00
|
|
|
(void) argc;
|
|
|
|
(void) argv;
|
|
|
|
(void) env;
|
|
|
|
|
2017-08-23 20:57:44 +02:00
|
|
|
struct service srv;
|
|
|
|
memset (&srv, 0, sizeof (struct service));
|
2017-08-26 01:07:29 +02:00
|
|
|
|
2017-08-28 00:03:35 +02:00
|
|
|
remotec_connection (argc, argv, env, &srv);
|
|
|
|
log_debug ("remotec connected");
|
|
|
|
log_debug ("remotec main loop");
|
2017-08-23 20:57:44 +02:00
|
|
|
|
2017-08-28 00:03:35 +02:00
|
|
|
struct remoted_msg msg;
|
|
|
|
memset (&msg, 0, sizeof (struct remoted_msg));
|
2017-08-23 20:57:44 +02:00
|
|
|
|
2017-08-28 00:03:35 +02:00
|
|
|
#if 0
|
2017-08-23 20:57:44 +02:00
|
|
|
// msg loop
|
|
|
|
for (;;) {
|
|
|
|
char buf[BUFSIZ];
|
|
|
|
memset (buf, 0, BUFSIZ);
|
|
|
|
|
2017-08-28 00:03:35 +02:00
|
|
|
/* TODO */
|
|
|
|
msg.datalen = 5; // FIXME: take parameters into account
|
|
|
|
msg.data = malloc (msg.datalen);
|
2017-08-23 20:57:44 +02:00
|
|
|
memset (msg.data, 0, msg.datalen);
|
2017-08-28 00:03:35 +02:00
|
|
|
strncpy ((char *) msg.data, "salut", msg.datalen);
|
2017-08-23 20:57:44 +02:00
|
|
|
|
|
|
|
/* TODO */
|
2017-08-28 00:03:35 +02:00
|
|
|
remotec_msg_send (&srv, &msg);
|
2017-08-23 20:57:44 +02:00
|
|
|
free (msg.data);
|
|
|
|
msg.data = NULL;
|
|
|
|
msg.datalen = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// free everything
|
|
|
|
remote_msg_free (&msg);
|
2017-08-28 00:03:35 +02:00
|
|
|
#endif
|
2017-08-23 20:57:44 +02:00
|
|
|
|
2017-08-28 00:03:35 +02:00
|
|
|
log_debug ("remotec disconnection...");
|
2017-08-23 20:57:44 +02:00
|
|
|
// disconnect from the server
|
2017-08-28 00:03:35 +02:00
|
|
|
remotec_disconnection (&srv);
|
2017-08-23 20:57:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv, char **env)
|
|
|
|
{
|
|
|
|
if (argc != 3) {
|
|
|
|
usage (argv);
|
|
|
|
exit (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int index = 0;
|
|
|
|
int version = 0;
|
|
|
|
|
|
|
|
main_loop (argc, argv, env, index, version, argv[1], argv[2]);
|
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|