1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-30 00:00:11 +01:00
VILLASnode/include/node.h
2014-06-05 09:34:29 +00:00

79 lines
1.6 KiB
C

/**
* Nodes
*
* The S2SS server connects multiple nodes.
* There are multiple types of nodes:
* - simulators
* - servers
* - workstations
*
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
* @copyright 2014, Institute for Automation of Complex Power Systems, EONERC
*/
#ifndef _NODE_H_
#define _NODE_H_
#include <sys/socket.h>
#include <netinet/in.h>
enum node_type
{
SIMULATOR,
SERVER,
WORKSTATION
};
struct node
{
/// The socket descriptor
int sd;
// Remote address of the socket
struct sockaddr_in addr;
/// The type of this node
enum node_type type;
/// A short identifier of the node
char *name;
};
struct msg; /* forward decl */
/**
* @brief Create a new node
*
* Memory is allocated dynamically and has to be freed by node_destroy()
*
* @param name An acroynm, describing the node
* @param type The type of a node (SERVER, SIMULATOR, WORKSTATION)
* @param addr A string containing the node address
* @param port The UDP port of the node
* @return
* - 0 on success
* - otherwise on error occured
*/
struct node* node_create(const char *name, enum node_type type, const char *addr, int port);
/**
* @brief Delete a node created by node_create()
*
* @param p A pointer to the node struct
*/
void node_destroy(struct node* n);
/**
* Send a single message to a node
*
* @param sd The descriptor of the UDP socket
* @param msg A pointer to the UDP message
*/
int node_send(struct node *n, struct msg *m);
/**
* Receive a single message from a node
*
* @param sd The descriptor of the UDP socket
* @param msg A pointer to the UDP message
*/
int node_recv(struct node *n, struct msg *m);
#endif /* _NODE_H_ */