include/nmxp_base.h File Reference

Base for Nanometrics Protocol Library. More...

#include "nmxp_data.h"
#include "nmxp_chan.h"
#include "nmxp_log.h"

Include dependency graph for nmxp_base.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define NMXP_BASE_H   1
#define NMXP_SLEEPMAX   60
#define NMXP_SOCKET_OK   0
#define NMXP_SOCKET_ERROR   -1

Functions

int nmxp_openSocket (char *hostname, int portNum, int(*func_cond)(void))
 Looks up target host, opens a socket and connects.
int nmxp_closeSocket (int isock)
 Close a socket.
int nmxp_send_ctrl (int isock, void *buffer, int length)
 Sends a buffer on a socket.
int nmxp_setsockopt_RCVTIMEO (int isock, int timeoutsec)
 Receives length bytes in a buffer from a socket.
char * nmxp_strerror (int errno_value)
 Wrapper to strerror, strerror_r or WSAGetLastErrorMessage.
int nmxp_recv_ctrl (int isock, void *buffer, int length, int timeoutsec, int *recv_errno)
 Receives length bytes in a buffer from a socket.
int nmxp_sendHeader (int isock, NMXP_MSG_CLIENT type, int32_t length)
 Sends header of a message.
int nmxp_receiveHeader (int isock, NMXP_MSG_SERVER *type, int32_t *length, int timeoutsec, int *recv_errno)
 Receives header of a message.
int nmxp_sendMessage (int isock, NMXP_MSG_CLIENT type, void *buffer, int32_t length)
 Sends header and body of a message.
int nmxp_receiveMessage (int isock, NMXP_MSG_SERVER *type, void **buffer, int32_t *length, int timeoutsec, int *recv_errno)
 Receives header and body of a message.
NMXP_DATA_PROCESSnmxp_processCompressedData (char *buffer_data, int length_data, NMXP_CHAN_LIST_NET *channelList, const char *network_code_default)
 Process Compressed Data message by function func_processData().
NMXP_DATA_PROCESSnmxp_processDecompressedData (char *buffer_data, int length_data, NMXP_CHAN_LIST_NET *channelList, const char *network_code_default)
 Process decompressed Data message by function func_processData().
unsigned int nmxp_sleep (unsigned int sleep_time)
 Wrapper for functions sleep on different platforms.
unsigned int nmxp_usleep (unsigned int sleep_time)
 Wrapper for functions usleep on different platforms.


Detailed Description

Base for Nanometrics Protocol Library.

Author: Matteo Quintiliani Istituto Nazionale di Geofisica e Vulcanologia - Italy quintiliani@ingv.it

Id

Define Documentation

#define NMXP_BASE_H   1

#define NMXP_SLEEPMAX   60

Maximum time between connection attempts (seconds).

#define NMXP_SOCKET_OK   0

Return message for succes on socket.

#define NMXP_SOCKET_ERROR   -1

Return message for error on socket.


Function Documentation

int nmxp_openSocket ( char *  hostname,
int  portNum,
int(*)(void)  func_cond 
)

Looks up target host, opens a socket and connects.

Parameters:
hostname hostname
portNum port number
Return values:
sd A descriptor referencing the socket.
-1 "Empty host name", "Cannot lookup host", ...

int nmxp_closeSocket ( int  isock  ) 

Close a socket.

Parameters:
isock A descriptor referencing the socket.
Return values:
0 Success
-1 Error

int nmxp_send_ctrl ( int  isock,
void *  buffer,
int  length 
)

Sends a buffer on a socket.

Parameters:
isock A descriptor referencing the socket.
buffer Data buffer.
length Length in bytes.
Return values:
NMXP_SOCKET_OK on success
NMXP_SOCKET_ERROR on error

int nmxp_setsockopt_RCVTIMEO ( int  isock,
int  timeoutsec 
)

Receives length bytes in a buffer from a socket.

Parameters:
isock A descriptor referencing the socket.
timeoutsec Time-out in seconds
Returns:
getsockopt() return value

char* nmxp_strerror ( int  errno_value  ) 

Wrapper to strerror, strerror_r or WSAGetLastErrorMessage.

Returns:
String message of errno_value. It is static, not need to be freed.

int nmxp_recv_ctrl ( int  isock,
void *  buffer,
int  length,
int  timeoutsec,
int *  recv_errno 
)

Receives length bytes in a buffer from a socket.

Parameters:
isock A descriptor referencing the socket.
[out] buffer Data buffer.
length Length in bytes.
timeoutsec Time-out in seconds
[out] recv_errno errno value after recv()
Warning:
Data buffer it has to be allocated before and big enough to contain length bytes!
Return values:
NMXP_SOCKET_OK on success
NMXP_SOCKET_ERROR on error

int nmxp_sendHeader ( int  isock,
NMXP_MSG_CLIENT  type,
int32_t  length 
)

Sends header of a message.

Parameters:
isock A descriptor referencing the socket.
type Type of message within NMXP_MSG_CLIENT.
length Length in bytes.
Return values:
NMXP_SOCKET_OK on success
NMXP_SOCKET_ERROR on error

int nmxp_receiveHeader ( int  isock,
NMXP_MSG_SERVER type,
int32_t *  length,
int  timeoutsec,
int *  recv_errno 
)

Receives header of a message.

Parameters:
isock A descriptor referencing the socket.
[out] type Type of message within NMXP_MSG_CLIENT.
[out] length Length in bytes.
timeoutsec Time-out in seconds
[out] recv_errno errno value after recv()
Return values:
NMXP_SOCKET_OK on success
NMXP_SOCKET_ERROR on error

int nmxp_sendMessage ( int  isock,
NMXP_MSG_CLIENT  type,
void *  buffer,
int32_t  length 
)

Sends header and body of a message.

Parameters:
isock A descriptor referencing the socket.
type Type of message within NMXP_MSG_CLIENT.
buffer Data buffer. It could be NULL.
length Length in bytes. It must be greater or equal to zero.
Return values:
NMXP_SOCKET_OK on success
NMXP_SOCKET_ERROR on error

int nmxp_receiveMessage ( int  isock,
NMXP_MSG_SERVER type,
void **  buffer,
int32_t *  length,
int  timeoutsec,
int *  recv_errno 
)

Receives header and body of a message.

Parameters:
isock A descriptor referencing the socket.
[out] type Type of message within NMXP_MSG_SERVER.
[out] buffer Data buffer. It will need to be freed!
[out] length Length in bytes.
timeoutsec Time-out in seconds
[out] recv_errno errno value after recv()
Warning:
buffer will need to be freed!
Return values:
NMXP_SOCKET_OK on success
NMXP_SOCKET_ERROR on error

NMXP_DATA_PROCESS* nmxp_processCompressedData ( char *  buffer_data,
int  length_data,
NMXP_CHAN_LIST_NET channelList,
const char *  network_code_default 
)

Process Compressed Data message by function func_processData().

Parameters:
buffer_data Pointer to the data buffer containing Compressed Nanometrics packets.
length_data Buffer length in bytes.
channelList Pointer to the Channel List.
network_code_default Value of network code to assign returned structure. It should not be NULL.
Returns:
Return a pointer to static struct NMXP_DATA_PROCESS.

NMXP_DATA_PROCESS* nmxp_processDecompressedData ( char *  buffer_data,
int  length_data,
NMXP_CHAN_LIST_NET channelList,
const char *  network_code_default 
)

Process decompressed Data message by function func_processData().

Parameters:
buffer_data Pointer to the data buffer containing Decompressed Nanometrics packets.
length_data Buffer length in bytes.
channelList Pointer to the Channel List.
network_code_default Value of network code to assign returned structure. It should not be NULL.
Returns:
Return a pointer to static struct NMXP_DATA_PROCESS.

unsigned int nmxp_sleep ( unsigned int  sleep_time  ) 

Wrapper for functions sleep on different platforms.

Parameters:
sleep_time time in seconds
Return values:
.... 

unsigned int nmxp_usleep ( unsigned int  sleep_time  ) 

Wrapper for functions usleep on different platforms.

Parameters:
usleep_time time in microseconds
Return values:
.... 


Generated on Wed Jul 23 02:18:05 2008 for libnmxp by  doxygen 1.5.3