mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
simplified code
git-svn-id: https://zerberus.eonerc.rwth-aachen.de:8443/svn/s2ss/trunk@35 8ec27952-4edc-4aab-86aa-e87bb2611832
This commit is contained in:
parent
861707ecac
commit
92ed4b4709
5 changed files with 5 additions and 64 deletions
|
@ -32,9 +32,6 @@ struct node
|
|||
/// The socket descriptor
|
||||
int sd;
|
||||
|
||||
/// Reference counter
|
||||
int ref_cnt;
|
||||
|
||||
// Local address of the socket
|
||||
struct sockaddr_in local;
|
||||
|
||||
|
@ -65,13 +62,6 @@ struct msg; /* forward decl */
|
|||
int node_create(struct node *n, const char *name, enum node_type type,
|
||||
struct sockaddr_in local, struct sockaddr_in remote);
|
||||
|
||||
/**
|
||||
* @brief Delete a node created by node_create()
|
||||
*
|
||||
* @param p A pointer to the node struct
|
||||
*/
|
||||
void node_destroy(struct node *n);
|
||||
|
||||
/**
|
||||
* @brief Connect and bind the UDP socket of this node
|
||||
*
|
||||
|
|
|
@ -14,14 +14,6 @@
|
|||
#include "node.h"
|
||||
#include "msg.h"
|
||||
|
||||
enum path_state
|
||||
{
|
||||
UNKNOWN,
|
||||
CONNECTED,
|
||||
RUNNING,
|
||||
STOPPED
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief The datastructure for a path
|
||||
*/
|
||||
|
@ -53,9 +45,7 @@ struct path
|
|||
};
|
||||
|
||||
/**
|
||||
* @brief Create a new path
|
||||
*
|
||||
* Memory is allocated dynamically and has to be freed by path_destroy()
|
||||
* @brief Setup a new path
|
||||
*
|
||||
* @param p A pointer to the path structure
|
||||
* @param in The node we are receiving messages from
|
||||
|
@ -67,13 +57,6 @@ struct path
|
|||
*/
|
||||
int path_create(struct path *p, struct node *in, struct node *out);
|
||||
|
||||
/**
|
||||
* @brief Delete a path created by path_create()
|
||||
*
|
||||
* @param p A pointer to the path struct
|
||||
*/
|
||||
void path_destroy(struct path *p);
|
||||
|
||||
/**
|
||||
* @brief Start a path
|
||||
*
|
||||
|
|
22
src/path.c
22
src/path.c
|
@ -25,22 +25,13 @@ int path_create(struct path *p, struct node *in, struct node *out)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void path_destroy(struct path *p)
|
||||
{
|
||||
assert(p);
|
||||
}
|
||||
|
||||
static void * path_run(void *arg)
|
||||
{
|
||||
struct path *p = (struct path *) arg;
|
||||
struct msg m;
|
||||
|
||||
assert(p);
|
||||
|
||||
debug(1, "Established path: %12s => %s => %-12s", p->in->name, config.name, p->out->name);
|
||||
|
||||
/* main thread loop */
|
||||
while (p->state == RUNNING) {
|
||||
while (1) {
|
||||
/* Receive message */
|
||||
msg_recv(&m, p->in);
|
||||
|
||||
|
@ -70,22 +61,15 @@ static void * path_run(void *arg)
|
|||
|
||||
int path_start(struct path *p)
|
||||
{
|
||||
assert(p);
|
||||
|
||||
p->state = RUNNING;
|
||||
pthread_create(&p->tid, NULL, &path_run, (void *) p);
|
||||
}
|
||||
|
||||
int path_stop(struct path *p)
|
||||
{
|
||||
void * ret;
|
||||
|
||||
assert(p);
|
||||
|
||||
p->state = STOPPED;
|
||||
void *ret;
|
||||
|
||||
pthread_cancel(p->tid);
|
||||
pthread_join(p->tid, &ret);
|
||||
|
||||
return 0; // TODO
|
||||
return 0;
|
||||
}
|
||||
|
|
16
src/random.c
16
src/random.c
|
@ -21,12 +21,6 @@
|
|||
#define CLOCKID CLOCK_REALTIME
|
||||
#define SIG SIGRTMIN
|
||||
|
||||
void quit(int sig, siginfo_t *si, void *ptr)
|
||||
{
|
||||
debug(1, "Good night");
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
void tick(int sig, siginfo_t *si, void *ptr)
|
||||
{
|
||||
struct msg *m = (struct msg*) si->si_value.sival_ptr;
|
||||
|
@ -62,17 +56,7 @@ int main(int argc, char *argv[])
|
|||
.sa_sigaction = tick
|
||||
};
|
||||
|
||||
struct sigaction sa_quit = {
|
||||
.sa_flags = SA_SIGINFO,
|
||||
.sa_sigaction = quit
|
||||
};
|
||||
|
||||
sigemptyset(&sa_tick.sa_mask);
|
||||
sigemptyset(&sa_quit.sa_mask);
|
||||
|
||||
if (sigaction(SIGINT, &sa_quit, NULL)) {
|
||||
error("Failed sigaction(): %s", strerror(errno));
|
||||
}
|
||||
|
||||
if (sigaction(SIG, &sa_tick, NULL)) {
|
||||
error("Failed sigaction(): %s", strerror(errno));
|
||||
|
|
|
@ -71,8 +71,8 @@ int main(int argc, char *argv[])
|
|||
|
||||
while (!feof(stdin)) {
|
||||
msg_fscan(stdin, &msg);
|
||||
msg_fprint(stdout, &msg);
|
||||
send(sd, &msg, 8 + msg.length, 0);
|
||||
msg_fprint(stdout, &msg);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
Loading…
Add table
Reference in a new issue