Revision 507372bb

View differences:

common/common.c
1 1
/*
2
 * Common functions (mostly init stuff) for GRAPES
2
 * Common functions (mostly init stuff) for NAPA
3 3
 */
4 4

  
5 5
#include	<stdio.h>
......
9 9
#include	<event2/event.h>
10 10

  
11 11

  
12
#include	"grapes.h"
13
#include	"grapes_log.h"
12
#include	"napa.h"
13
#include	"napa_log.h"
14 14

  
15 15
struct event_base *eventbase = NULL;
16 16

  
......
22 22
#endif
23 23

  
24 24
/** Initialize the software. This should be called FIRST */
25
void grapesInit(void *event2_base) {
25
void napaInit(void *event2_base) {
26 26
	eventbase = event2_base;
27 27
#if 0
28 28
	/* Won't need this for normal operation */
......
31 31
#endif
32 32
}
33 33

  
34
void grapesYield() {
34
void napaYield() {
35 35
	event_base_loop(eventbase, EVLOOP_ONCE);
36 36
}
37 37

  
......
56 56
}
57 57

  
58 58

  
59
HANDLE grapesSchedulePeriodic(const struct timeval *start, double frequency, void(*cb)(HANDLE handle, void *arg), void *cbarg) {
59
HANDLE napaSchedulePeriodic(const struct timeval *start, double frequency, void(*cb)(HANDLE handle, void *arg), void *cbarg) {
60 60
	struct timeval t = { 0,0 };
61 61
	if (start) t = *start;
62 62
	struct periodic *h = malloc(sizeof(struct periodic));
......
70 70
	return h;
71 71
}
72 72

  
73
void grapesStopPeriodic(HANDLE h) {
73
void napaStopPeriodic(HANDLE h) {
74 74
	struct periodic *p = h;
75 75
	p->frequency = 0.0;
76 76
}
dclog/log.c
1 1
/*
2
 * This file implements logging functionality for the GRAPES framework
2
 * This file implements logging functionality for the NAPA framework
3 3
 */
4 4

  
5 5
#define _GNU_SOURCE
......
7 7
#include	<stdio.h>
8 8
#include	<stdlib.h>
9 9
#include	<stdarg.h>
10
#include	<grapes_log.h>
10
#include	<napa_log.h>
11 11
#include	"dclog.h"
12 12

  
13 13
DCLog *dclog = NULL;
......
16 16
char *logbuffer = NULL;
17 17
size_t logbuffer_size = 0;
18 18

  
19
void grapesInitLog(int log_level, const char *filename, const char *mode) {
19
void napaInitLog(int log_level, const char *filename, const char *mode) {
20 20
        if (initialized) return;
21 21

  
22 22
        /* Initialize the logger facility */
......
51 51
        initialized = 1;
52 52
}
53 53

  
54
void grapesCloseLog() {
54
void napaCloseLog() {
55 55
	if (!initialized) return;
56 56

  
57 57
	DCLogClose(dclog);
......
60 60
	initialized = 0;
61 61
}
62 62

  
63
void grapesWriteLog(const unsigned char lev, const char *fmt, ... ) {
63
void napaWriteLog(const unsigned char lev, const char *fmt, ... ) {
64 64
	va_list str_args;
65 65

  
66 66
	if (!initialized) return;
include/grapes.h
1
#ifndef _GRAPES_H
2
#define _GRAPES_H
3

  
4
/** @mainpage
5

  
6
   @section intro Introduction
7

  
8
   The GRAPES prototype code is the reference implementation for the evolving GRAPES (aka. PULSE+) API.
9
   The main point is to demonstrate the intended final <b>structure</b> of the implementation, with
10
   omitting as much details as possible. Thus, the pre-prototype contains C language bindings for
11
   most of the datatypes, API calls etc. without the actual implementation, or with a <i>stub</i>
12
   implementation only for internal testing and to demonstrate the intended structure.
13

  
14
   Thus, most of the information found in this documentation is intended for GRAPES developers.
15

  
16
   @section structure Code Structure
17

  
18
   Each module (listed below) is separated into a sub-directory within the source tree.
19
   The public interfaces (APIs) are located in the <i>include/</i> sub-directory in the 
20
   correspondingly named .h file (e.g. ml.h for the Messaging Layer which resides in sub-directory <i>ml/</i>
21
   Module subdirectories are as follows:
22
	- ml/ - <b>Messaging Layer</b> - ml.h
23
	- mon/ - <b>Monitoring Layer</b> - mon.h
24
	- rep/ - <b>Repository</b> - repoclient.h
25
	- som/ - <b>Scheduler and Overlay Manager</b> - som.h
26
	- ul/ - <b>User</b> (interface) <b>Layer</b> - ul.h
27

  
28
   @section deps Dependencies
29

  
30
   The pre-prototype code uses a number of external open-source libraries.
31
   Most importantly, the <A HREF="http://monkey.org/~provos/libevent/">libevent</A> framework 
32
   is used to implement the reactive architecture, which was chosen as the 
33
   model of computation for GRAPES.
34
   Additionally, further open-source libraries are used to perform common tasks
35
   such as config file parsing and logging.
36
   
37
   Included libraries are:
38
	- <A HREF="http://monkey.org/~provos/libevent/">libevent</A>: event loop library to implement 
39
	the reactive architecture
40
	- <A HREF="http://www.nongnu.org/confuse/">libconfuse</A>: configuration file parsing library
41
	- <A HREF="http://sourceforge.net/projects/dclog/">dclog</A>: log message writer library
42

  
43
   @section copyright Copyright and related issues
44

  
45
   This code is has been released to the public.
46
*/
47

  
48

  
49
/** @file grapes.h
50
 *
51
 * Common definitions for the GRAPES framework reference implementation, to be included by all 
52
 * applications using GRAPES.
53
 *
54
 * This header file contains basic, system-wide definitions (such as PeerID) which are necessary
55
 * for different GRAPES modules to interact.
56
 * 
57
 * Libraries and system-wide dependencies are included from this file, for example standard C
58
 * header files for common types (e.g. <i>bool</i> or <i>byte<i>
59
 *
60
 */
61

  
62
#include <sys/types.h>
63
#include <stdbool.h>
64
#include <stdlib.h>
65
#ifdef WIN32
66
#include <winsock2.h>
67
#endif
68

  
69
#ifndef byte
70
/** 8-bit unsigned type */
71
typedef u_char byte;
72
#endif
73

  
74
/** General-purpose opaque handle type */
75
typedef void *HANDLE;
76

  
77
/** Opaque network-wide PeerID */
78
typedef char PeerID[64];
79

  
80
/** eventbase pointer for the libevent2 framework */
81
extern struct event_base *eventbase;
82

  
83
#ifdef __cplusplus
84
extern "C" {
85
#endif
86

  
87
/** Function to initialize the GRAPES framework.
88
 *
89
 * This function has to be called first, before any other GRAPES-provided function.
90
 
91
   @param event2_base libevent2 base structure, provided by the external application
92
*/
93
void grapesInit(void *event2_base);
94

  
95
/** Function to yield control (sleep) 
96
*/
97
void grapesYield();
98

  
99
/**
100
  Register a function to be called periodically.
101

  
102
  Use this function for scheduling periodic activity. 
103
  The callback function supports one extra argument besides its own handle.
104

  
105
  @param[in] start time of first exection, in timeval units from now. NULL (or timeval {0,0}) means "now" or "asap". 
106
  @param[in] frequency invocation frequency .
107
  @param[in] cb callback function to be called periodically.
108
  @param[in] cbarg argument for the callback function.
109
  @return handle to the function or NULL on error.
110
  @see grapesStopPeriodic
111
*/
112
HANDLE grapesSchedulePeriodic(const struct timeval *start, double frequency, void(*cb)(HANDLE handle, void *arg), void *cbarg);
113

  
114
/**
115
  Stop periodically calling the callback registered to the handle.
116

  
117
  @param h handle to the callback.
118
  @see grapesStartPeriodic
119
*/
120
void grapesStopPeriodic(HANDLE h);
121

  
122

  
123
/** Convenience function to print a timeval */
124
const char *timeval2str(const struct timeval *ts);
125

  
126
#ifdef __cplusplus
127
}
128
#endif
129

  
130
#endif
include/grapes_log.h
1
#ifndef _GRAPES_LOG_H
2
#define _GRAPES_LOG_H
3

  
4
/** Logging facilities for GRAPES 
5

  
6
 * @file grapes_log.h
7
 * @brief This module provides convenient logging functions for other GRAPES modules
8
 *
9
 */
10

  
11
#include	<stdlib.h>
12

  
13
/* These log levels should match dclog's internal definition */
14
#define DCLOG_ALARM   0 //!< alarms
15
#define DCLOG_ERROR   1 //!< error messages
16
#define DCLOG_WARNING 2 //!< warnings
17
#define DCLOG_INFO    3 //!< information messages
18
#define DCLOG_DEBUG   4 //!< debugging messages
19
#define DCLOG_PROFILE 5 //!< profiling messages
20

  
21
/** log level for CRITICAL messages */
22
#define LOG_CRITICAL    DCLOG_ALARM
23
/** log level for ERROR messages */
24
#define LOG_ERROR       DCLOG_ERROR
25
/** log level for WARNING messages */
26
#define LOG_WARN        DCLOG_WARNING
27
/** log level for INFO messages */
28
#define LOG_INFO        DCLOG_INFO
29
/** log level for DEBUG messages */
30
#define LOG_DEBUG       DCLOG_DEBUG
31
/** log level for PROFILE messages */
32
#define LOG_PROFILE     DCLOG_PROFILE
33

  
34
/** general-purpose, module-aware log facility, to be used with a log priority */
35
#define grapes_log(priority, format, ... ) grapesWriteLog(priority,  format " [%s,%d]\n",  ##__VA_ARGS__ , __FILE__, __LINE__ )
36
/** Convenience macro to log TODOs */
37
#define todo(format, ...) grapes_log(LOG_WARN, "[TODO] " format " file: %s, line %d",  ##__VA_ARGS__ )
38

  
39
/** Convenience macro to log LOG_DEBUG messages */
40
#define debug(format, ... ) grapes_log(LOG_DEBUG, format, ##__VA_ARGS__ )
41
/** Convenience macro to log LOG_INFO messages */
42
#define info(format, ... )  grapes_log(LOG_INFO, format, ##__VA_ARGS__ )
43
/** Convenience macro to log LOG_WARN messages */
44
#define warn(format, ... )  grapes_log(LOG_WARN, format, ##__VA_ARGS__ )
45
/** Convenience macro to log LOG_ERROR messages */
46
#define error(format, ... )  grapes_log(LOG_ERROR, format, ##__VA_ARGS__ )
47
/**  Convenience macro to log LOG_CRITICAL messages and crash the program */
48
#define fatal(format, ... ) {  grapes_log(LOG_CRITICAL, format, ##__VA_ARGS__ ); exit(-1); }
49

  
50
#ifdef __cplusplus
51
extern "C" {
52
#endif
53

  
54
/** 
55
  Initializes the GRAPES logging facility.
56

  
57
  @param[in] loglevel Only log messages on or above this level
58
  @param[in] filename Write log messages to this file (might be "stderr" or "stdout")
59
  @param[in] mode file open mode ("a" for append or "w" for truncate)
60
*/
61
void grapesInitLog(int loglevel, const char *filename, const char *mode);
62

  
63
/** Closes down GRAPES logging facility. Log messages are discarded after this. */
64
void grapesCloseLog();
65

  
66
/** Low-level interface to the GRAPES logging system. Use the above defined convenience macros instead */
67
void grapesWriteLog(const unsigned char lev, const char *fmt, ... );
68
#ifdef __cplusplus
69
}
70
#endif
71

  
72
#endif
73

  
74

  
include/napa.h
1
#ifndef _NAPA_H
2
#define _NAPA_H
3

  
4
/** @mainpage
5

  
6
   @section intro Introduction
7

  
8
   The NAPA prototype code is the reference implementation for the evolving WineStreamer (aka. PULSE+) API.
9
   The main point is to demonstrate the intended final <b>structure</b> of the implementation, with
10
   omitting as much details as possible. Thus, the pre-prototype contains C language bindings for
11
   most of the datatypes, API calls etc. without the actual implementation, or with a <i>stub</i>
12
   implementation only for internal testing and to demonstrate the intended structure.
13

  
14
   Thus, most of the information found in this documentation is intended for NAPA developers.
15

  
16
   @section structure Code Structure
17

  
18
   Each module (listed below) is separated into a sub-directory within the source tree.
19
   The public interfaces (APIs) are located in the <i>include/</i> sub-directory in the 
20
   correspondingly named .h file (e.g. ml.h for the Messaging Layer which resides in sub-directory <i>ml/</i>
21
   Module subdirectories are as follows:
22
	- ml/ - <b>Messaging Layer</b> - ml.h
23
	- mon/ - <b>Monitoring Layer</b> - mon.h
24
	- rep/ - <b>Repository</b> - repoclient.h
25
	- som/ - <b>Scheduler and Overlay Manager</b> - som.h
26
	- ul/ - <b>User</b> (interface) <b>Layer</b> - ul.h
27

  
28
   @section deps Dependencies
29

  
30
   The pre-prototype code uses a number of external open-source libraries.
31
   Most importantly, the <A HREF="http://monkey.org/~provos/libevent/">libevent</A> framework 
32
   is used to implement the reactive architecture, which was chosen as the 
33
   model of computation for some of the NAPA libraries.
34
   Additionally, further open-source libraries are used to perform common tasks
35
   such as config file parsing and logging.
36
   
37
   Included libraries are:
38
	- <A HREF="http://monkey.org/~provos/libevent/">libevent</A>: event loop library to implement 
39
	the reactive architecture
40
	- <A HREF="http://www.nongnu.org/confuse/">libconfuse</A>: configuration file parsing library
41
	- <A HREF="http://sourceforge.net/projects/dclog/">dclog</A>: log message writer library
42

  
43
   @section copyright Copyright and related issues
44

  
45
   This code is has been released to the public.
46
*/
47

  
48

  
49
/** @file napa.h
50
 *
51
 * Common definitions for the NAPA framework reference implementation, to be included by all 
52
 * applications using these libraries.
53
 *
54
 * This header file contains basic, system-wide definitions (such as PeerID) which are necessary
55
 * for different modules to interact.
56
 * 
57
 * Libraries and system-wide dependencies are included from this file, for example standard C
58
 * header files for common types (e.g. <i>bool</i> or <i>byte<i>
59
 *
60
 */
61

  
62
#include <sys/types.h>
63
#include <stdbool.h>
64
#include <stdlib.h>
65
#ifdef WIN32
66
#include <winsock2.h>
67
#endif
68

  
69
#ifndef byte
70
/** 8-bit unsigned type */
71
typedef u_char byte;
72
#endif
73

  
74
/** General-purpose opaque handle type */
75
typedef void *HANDLE;
76

  
77
/** Opaque network-wide PeerID */
78
typedef char PeerID[64];
79

  
80
/** eventbase pointer for the libevent2 framework */
81
extern struct event_base *eventbase;
82

  
83
#ifdef __cplusplus
84
extern "C" {
85
#endif
86

  
87
/** Function to initialize the framework.
88
 *
89
 * This function has to be called first, before any other NAPA-BASELIBS-provided function.
90
 
91
   @param event2_base libevent2 base structure, provided by the external application
92
*/
93
void napaInit(void *event2_base);
94

  
95
/** Function to yield control (sleep) 
96
*/
97
void napaYield();
98

  
99
/**
100
  Register a function to be called periodically.
101

  
102
  Use this function for scheduling periodic activity. 
103
  The callback function supports one extra argument besides its own handle.
104

  
105
  @param[in] start time of first exection, in timeval units from now. NULL (or timeval {0,0}) means "now" or "asap". 
106
  @param[in] frequency invocation frequency .
107
  @param[in] cb callback function to be called periodically.
108
  @param[in] cbarg argument for the callback function.
109
  @return handle to the function or NULL on error.
110
  @see napaStopPeriodic
111
*/
112
HANDLE napaSchedulePeriodic(const struct timeval *start, double frequency, void(*cb)(HANDLE handle, void *arg), void *cbarg);
113

  
114
/**
115
  Stop periodically calling the callback registered to the handle.
116

  
117
  @param h handle to the callback.
118
  @see napaStartPeriodic
119
*/
120
void napaStopPeriodic(HANDLE h);
121

  
122

  
123
/** Convenience function to print a timeval */
124
const char *timeval2str(const struct timeval *ts);
125

  
126
#ifdef __cplusplus
127
}
128
#endif
129

  
130
#endif
include/napa_log.h
1
#ifndef _NAPA_LOG_H
2
#define _NAPA_LOG_H
3

  
4
/** Logging facilities for NAPA 
5

  
6
 * @file napa_log.h
7
 * @brief This module provides convenient logging functions for other NAPA modules
8
 *
9
 */
10

  
11
#include	<stdlib.h>
12

  
13
/* These log levels should match dclog's internal definition */
14
#define DCLOG_ALARM   0 //!< alarms
15
#define DCLOG_ERROR   1 //!< error messages
16
#define DCLOG_WARNING 2 //!< warnings
17
#define DCLOG_INFO    3 //!< information messages
18
#define DCLOG_DEBUG   4 //!< debugging messages
19
#define DCLOG_PROFILE 5 //!< profiling messages
20

  
21
/** log level for CRITICAL messages */
22
#define LOG_CRITICAL    DCLOG_ALARM
23
/** log level for ERROR messages */
24
#define LOG_ERROR       DCLOG_ERROR
25
/** log level for WARNING messages */
26
#define LOG_WARN        DCLOG_WARNING
27
/** log level for INFO messages */
28
#define LOG_INFO        DCLOG_INFO
29
/** log level for DEBUG messages */
30
#define LOG_DEBUG       DCLOG_DEBUG
31
/** log level for PROFILE messages */
32
#define LOG_PROFILE     DCLOG_PROFILE
33

  
34
/** general-purpose, module-aware log facility, to be used with a log priority */
35
#define napa_log(priority, format, ... ) napaWriteLog(priority,  format " [%s,%d]\n",  ##__VA_ARGS__ , __FILE__, __LINE__ )
36
/** Convenience macro to log TODOs */
37
#define todo(format, ...) napa_log(LOG_WARN, "[TODO] " format " file: %s, line %d",  ##__VA_ARGS__ )
38

  
39
/** Convenience macro to log LOG_DEBUG messages */
40
#define debug(format, ... ) napa_log(LOG_DEBUG, format, ##__VA_ARGS__ )
41
/** Convenience macro to log LOG_INFO messages */
42
#define info(format, ... )  napa_log(LOG_INFO, format, ##__VA_ARGS__ )
43
/** Convenience macro to log LOG_WARN messages */
44
#define warn(format, ... )  napa_log(LOG_WARN, format, ##__VA_ARGS__ )
45
/** Convenience macro to log LOG_ERROR messages */
46
#define error(format, ... )  napa_log(LOG_ERROR, format, ##__VA_ARGS__ )
47
/**  Convenience macro to log LOG_CRITICAL messages and crash the program */
48
#define fatal(format, ... ) {  napa_log(LOG_CRITICAL, format, ##__VA_ARGS__ ); exit(-1); }
49

  
50
#ifdef __cplusplus
51
extern "C" {
52
#endif
53

  
54
/** 
55
  Initializes the NAPA logging facility.
56

  
57
  @param[in] loglevel Only log messages on or above this level
58
  @param[in] filename Write log messages to this file (might be "stderr" or "stdout")
59
  @param[in] mode file open mode ("a" for append or "w" for truncate)
60
*/
61
void napaInitLog(int loglevel, const char *filename, const char *mode);
62

  
63
/** Closes down NAPA logging facility. Log messages are discarded after this. */
64
void napaCloseLog();
65

  
66
/** Low-level interface to the NAPA logging system. Use the above defined convenience macros instead */
67
void napaWriteLog(const unsigned char lev, const char *fmt, ... );
68
#ifdef __cplusplus
69
}
70
#endif
71

  
72
#endif
73

  
74

  
include/neighborlist.h
17 17
 * 
18 18
 */
19 19

  
20
#include	"grapes.h"
20
#include	"napa.h"
21 21

  
22 22
/** A NeighborListEntry holds information for Peers in the NeighborList */
23 23
typedef struct {
include/repoclient.h
12 12
 * Overall considerations:
13 13
	-# In the prototype, the Repository operates as a cental network resource (server). However, peers
14 14
may execute several repoclient instances, and connect to several Repository servers at the same time.
15
and has its own executable program, to be run independent of other GRAPES processes. 
15
and has its own executable program, to be run independent of other NAPA processes. 
16 16
	-# The repository controller uses an internal network protocol for querying and publishing (inserting) measurement records, and this API defines the client side of this protocol.
17 17
	-# The following kinds of queries are supported:
18 18
		-# Metadata query: list of available (or implemented/supported) 
......
72 72
		in the same format what is used for the Publish call.  Missing (NULL-valued) fields are omitted.
73 73
*/
74 74

  
75
#include	"grapes.h"
75
#include	"napa.h"
76 76
#include	"mon.h"
77 77

  
78 78
/** Constraints are used in GetPeer and CountPeer functions to specify matching criteria for numeric-value MeasurementRecords */
include/ul.h
3 3

  
4 4
/** @file ul.h
5 5
 * 
6
 * @brief GRAPES User Layer Interface 
6
 * @brief User Layer Interface 
7 7
 * 
8
 * The User Layer API describes how a GRAPES peer interacts with the user.
8
 * The User Layer API describes how a peer interacts with the user.
9 9
 * There are two major operation modes:
10 10
 *	- player: displays the received video stream, and provides basic 
11 11
 *		controls (e.g. start/stop, channel switch etc.)
......
19 19
 * These operations are referred to as <i>chunkization</i>/<i>de-chunkization</i>.
20 20
 * 
21 21
 * In order to provide maximum flexibility, these processes are loosely coupled 
22
 * to the core GRAPES via network pipes. For simplicity, in the reference 
23
 * implementation we propose the HTTP protocol for (de)chunkizer-GRAPES core
22
 * to the core via network pipes. For simplicity, in the reference 
23
 * implementation we propose the HTTP protocol for (de)chunkizer-core
24 24
 * interaction.
25 25
 *
26 26
 * This interface is conceptually clean, easy to integrate with other programs, 
27 27
 * and straightforward to implement.
28 28
 *
29
 * As a princile to start with, the GRAPES application handles chunks on its external interfaces. 
29
 * As a princile to start with, the application handles chunks on its external interfaces. 
30 30
 * At the ingestion side, it receives chunks sent by a <i>sequencer</i> in approximately correct timing. 
31
 * At the receiver/player nodes, GRAPES+ should issue chunks in correct sequence, 
31
 * At the receiver/player nodes, the application should issue chunks in correct sequence, 
32 32
 * and (if possible) again with a roughly correct timing. 
33 33
 * As a simple approach, each receiver/player client may request a delay 
34
 * when it connects to GRAPES (e.g. 5 secs), and it receives the replay of 
34
 * when it connects to the application (e.g. 5 secs), and it receives the replay of 
35 35
 * ingestion events offset by this delay.
36 36
 * 
37 37
 * This approach also decouples the `network' and `multimedia' aspects of the software: 
38
 * the player and ingestor are not linked with the GRAPES application and has maximum flexibility 
38
 * the player and ingestor are not linked with the application and has maximum flexibility 
39 39
 * (e.g. with codec legal and technology aspects).
40 40

  
41 41
 * `Roughly correct timing'  means that the sending time for chunks are synchronized 
42 42
 * (to the media time they contain) with an accuracy of about or less than one chunk period. 
43
 * This way, within GRAPES, new chunks may directly enter the ChunkBuffer (replacing the oldest one), 
43
 * This way, within the application, new chunks may directly enter the ChunkBuffer (replacing the oldest one), 
44 44
 * and the dechunkizers will also have to buffer only a small number of (1-3) chunks. 
45 45
 * 
46 46
 * For low-level interface, we propose using HTTP POST operations: HTTP is a well-known protocol 
......
49 49
 * HTTP interfaces are also easy to test.
50 50
 * 
51 51
 * The application may support  multiple simultaneous clients (players with different delays, analyzers, etc.) 
52
 * on the receiver side. The service offered for this registration by GRAPES is the same HTTP 
52
 * on the receiver side. The service offered for this registration by the application is the same HTTP 
53 53
 * service used by the chunkizer to send new chunks.
54 54
 *
55 55
 * <b> Source (ingestor) Protocol Description</b>
......
58 58
 * from the ingestor. The format is a follows:<br>
59 59
 * <tt>http://<addr>:<port>/<path-id>/<chunk-number>?timestamp=<date></tt><br>
60 60
 * accompanied by the binary chunk in the POST message
61
 * The chunk data is opaque for GRAPES and is delivered unchanged.
61
 * The chunk data is opaque for the application and is delivered unchanged.
62 62
 *
63 63
 * <b> Player (client) Protocol Description: Control Interface</b>
64 64
 * 
65
 * The GRAPES core module implements a HTTP listener to receive registrations
65
 * An application module implements a HTTP listener to receive registrations
66 66
 * from clients (e.g. Display/GUI or analyzer modules). 
67 67
 * Registrations are encoded as HTTP GET requests as follows:
68 68
 * <tt>http://<hostname>:<port>/register-receptor?url=<url>&channel=<channel>&delay=<delay>&validity=<validity></tt><br>
69 69
 * Parameters are:
70
 *	- <hostname> and <port> are startup parameters for GRAPES
70
 *	- <hostname> and <port> are startup parameters for the application
71 71
 *	- <url> the URL where posts should be sent (URL encoded). MANDATORY.
72 72
 *	- <channel> channel identifier
73 73
 * 	- <delay> the delay, expressed in seconds, fractional values are supported. Delay defaults to 5 seconds.
74 74
 * 	- <validity> TImeout for this registration: if there is no additional registration 
75
 *	within <validity> seconds, GRAPES will stop posting chunks.  Default is 300 seconds.
75
 *	within <validity> seconds, the application will stop posting chunks.  Default is 300 seconds.
76 76
 * 
77 77
 * Then, each registered client module is supposed to implement a HTTP listener on the specified URL  
78
 * where GRAPES will send chunks to. Sending is implemented as a HTTP POST using the source (ingestor) protocol
78
 * where the application will send chunks to. Sending is implemented as a HTTP POST using the source (ingestor) protocol
79 79
 * above.
80 80
 * The client-registration HTTP service above can be easily extended with optional commands implementing GUI
81 81
 * controls.
......
88 88
 * 
89 89
 */
90 90

  
91
#include	"grapes.h"
91
#include	"napa.h"
92 92

  
93 93
/**
94 94
  Initialize source functionality within a peer's User Layer.
......
110 110
/**
111 111
  Initialize a `player' (dechunkizer) functionality  within a peer's User Layer..
112 112

  
113
  @param[in] reg_url register-receptor URL where GRAPES listens
113
  @param[in] reg_url register-receptor URL where the application listens
114 114
  @return a handle for the initized peer UL or NULL on error
115 115
*/
116 116
HANDLE initULPeer(const char *reg_url);
monl/measure_dispatcher.cpp
21 21
#include "measure_manager.h"
22 22
#include "errors.h"
23 23
#include "ctrl_msg.h"
24
#include "grapes_log.h"
24
#include "napa_log.h"
25 25

  
26 26

  
27 27
#ifndef WIN32
monl/measure_manager.h
26 26
#include "measure_plugin.h"
27 27
#include "measure_dispatcher.h"
28 28

  
29
#include "grapes_log.h"
29
#include "napa_log.h"
30 30

  
31 31

  
32 32
#define MAX_NUM_MEASURES_INSTANTIATED 1000000
monl/mon_measure.cpp
20 20
#include "measure_dispatcher.h"
21 21
#include "measure_manager.h"
22 22
#include "mon_event.h"
23
#include	"grapes_log.h"
23
#include	"napa_log.h"
24 24

  
25 25
MonMeasure::MonMeasure(class MeasurePlugin *mp, MeasurementCapabilities mc, class MeasureDispatcher *ptrDisp) {
26 26
	rx_cnt = 0;
monl/mon_measure.h
31 31
#include "result_buffer.h"
32 32
#include "ml.h"
33 33

  
34
#include "grapes_log.h"
34
#include "napa_log.h"
35 35

  
36 36
#include <fstream>
37 37

  
monl/monl.cpp
18 18
 ***********************************************************************/
19 19

  
20 20
#define LOG_MODULE "[monl] "
21
#include	"grapes_log.h"
21
#include	"napa_log.h"
22 22
#include "ml.h"
23 23
#include "mon.h"
24 24
#include "measure_manager.h"
monl/plugins/capprobe_measure.cpp
18 18
 ***************************************************************************/
19 19

  
20 20
#include "capprobe_measure.h"
21
#include "grapes_log.h"
21
#include "napa_log.h"
22 22
#include <sys/time.h>
23 23
#include <math.h>
24 24
#include <string>
monl/plugins/clockdrift_measure.cpp
18 18
 ***********************************************************************/
19 19

  
20 20
#include "clockdrift_measure.h"
21
#include "grapes_log.h"
21
#include "napa_log.h"
22 22
#include <math.h>
23 23

  
24 24

  
monl/plugins/corrected_delay_measure.cpp
19 19

  
20 20
#include "corrected_delay_measure.h"
21 21
#include "clockdrift_measure.h"
22
#include "grapes_log.h"
22
#include "napa_log.h"
23 23
#include <math.h>
24 24

  
25 25
CorrecteddelayMeasure::CorrecteddelayMeasure(class MeasurePlugin *m, MeasurementCapabilities mc, class MeasureDispatcher *md): MonMeasure(m,mc,md) {
monl/plugins/forecaster_measure.cpp
17 17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA 
18 18
 ***********************************************************************/
19 19
#include "forecaster_measure.h"
20
#include "grapes_log.h"
20
#include "napa_log.h"
21 21
#include <sys/time.h>
22 22
#include <limits.h>
23 23

  
monl/plugins/loss_burst_measure.cpp
18 18
 ***********************************************************************/
19 19

  
20 20
#include "loss_burst_measure.h"
21
#include "grapes_log.h"
21
#include "napa_log.h"
22 22

  
23 23
LossBurstMeasure::LossBurstMeasure(class MeasurePlugin *m, MeasurementCapabilities mc, class MeasureDispatcher *md): MonMeasure(m,mc,md) {
24 24
}
monl/plugins/loss_measure.cpp
18 18
 ***********************************************************************/
19 19

  
20 20
#include "loss_measure.h"
21
#include "grapes_log.h"
21
#include "napa_log.h"
22 22

  
23 23
LossMeasure::LossMeasure(class MeasurePlugin *m, MeasurementCapabilities mc, class MeasureDispatcher *md): MonMeasure(m,mc,md) {
24 24
	mSeqWin = NULL;
monl/result_buffer.cpp
19 19

  
20 20
#include "result_buffer.h"
21 21
#include "errors.h"
22
#include	"grapes_log.h"
22
#include	"napa_log.h"
23 23
#include "repoclient.h"
24 24

  
25 25
#include "mon_event.h"
monl/result_buffer.h
28 28
#include "ml.h"
29 29
#include "mon.h"
30 30

  
31
#include "grapes_log.h"
31
#include "napa_log.h"
32 32

  
33 33
class ResultBuffer {
34 34
private:
rep/repoclient_impl.h
19 19
#include        <event2/http.h>
20 20
#include        <event2/http_struct.h>
21 21
 
22
#include	<grapes.h>
23
#include	<grapes_log.h>
22
#include	<napa.h>
23
#include	<napa_log.h>
24 24
#include	<mon.h>		// for MeasurementRecord
25 25

  
26 26
#include	<repoclient.h>
tests/Broadcaster/ml.c
198 198
		recv_localsocketID_cb, eventbase);
199 199

  
200 200
	while (!messaging_ready) {
201
		grapesYield();
201
		napaYield();
202 202
	}
203 203
	mlRegisterRecvDataCb(recv_data_from_peer_cb, MSG_TYPE_CHUNK);
204 204
	mlRegisterRecvDataCb(recv_keepalive_from_peer_cb, MSG_TYPE_ML_KEEPALIVE);
tests/Broadcaster/peer.c
70 70

  
71 71
	// Initialize logging
72 72
	if (log_level == -1) log_level = cfg_getint(log_config, "level");
73
	grapesInitLog(log_level, cfg_getstr(log_config, "logfile"),
73
	napaInitLog(log_level, cfg_getstr(log_config, "logfile"),
74 74
			cfg_getstr(log_config, "filemode"));
75
	grapesInit(event_base_new());
75
	napaInit(event_base_new());
76 76

  
77 77
	// Check config file
78 78
	int fd = open(argv[argc - 1], 0);
tests/Broadcaster/peer.h
22 22
#include	<event2/http_struct.h>
23 23
#include	<confuse.h>
24 24
 
25
#include	<grapes.h>
26
#include	<grapes_log.h>
25
#include	<napa.h>
26
#include	<napa_log.h>
27 27
#include	<ml.h>
28 28
#include	<mon.h>
29 29
#include	<chunk.h>
tests/Broadcaster/som.c
174 174
	int publishPeerIDPeriod =  cfg_getint(som_config,
175 175
			"publishPeerIDPeriod");
176 176
	if (publishPeerIDPeriod) 
177
		grapesSchedulePeriodic(NULL, 1.0/(float)publishPeerIDPeriod,
177
		napaSchedulePeriodic(NULL, 1.0/(float)publishPeerIDPeriod,
178 178
				publish_PeerID, NULL);
179 179

  
180 180
	/* If we are passive, we need to figure out who is the server, and send
tests/Broadcaster/source.c
59 59
			fatal("Unable to start the HTTP receiver to http://%s:%d", 
60 60
					addr, port);
61 61
	} else fatal("Unable to parse stream specification %s", stream);
62
	grapesSchedulePeriodic(NULL, 1/60.0, periodicPublishSrcLag, NULL);
62
	napaSchedulePeriodic(NULL, 1/60.0, periodicPublishSrcLag, NULL);
63 63
}
64 64

  
65 65
struct source_stream {
......
196 196
		src->buffers[src->num_buffers] = malloc(MAX_PACKET_SIZE);
197 197
	src->atts_size = 0;
198 198

  
199
	grapesSchedulePeriodic(NULL, 1.0/chunk_duration, read_stream, src);
199
	napaSchedulePeriodic(NULL, 1.0/chunk_duration, read_stream, src);
200 200
}
201 201

  
202 202

  
tests/MLTest/MLTest.c
4 4
#include <math.h>
5 5

  
6 6
#include "ml.h"
7
#include "grapes_log.h"
8
#include "grapes.h"
7
#include "napa_log.h"
8
#include "napa.h"
9 9
#include "transmissionHandler.h"
10 10

  
11 11
int peerID;
......
244 244

  
245 245
	numOfMsg = inputRate / ((msgLen/1349 + 1)*23 + msgLen)*timeInterval;	
246 246

  
247
	//Init grapes: log facility and libevent
248
	grapesInit(event_base_new());
247
	//Init napa: log facility and libevent
248
	napaInit(event_base_new());
249 249

  
250 250
	// Initialize logging
251
	grapesInitLog(verbosity, NULL, NULL);
251
	napaInitLog(verbosity, NULL, NULL);
252 252

  
253 253
	//initRateLimiter(eventbase);
254 254

  
tests/MonTest/MonTest.c
25 25

  
26 26
#include "ml.h"
27 27
#include "mon.h"
28
#include "grapes_log.h"
29
#include "grapes.h"
28
#include "napa_log.h"
29
#include "napa.h"
30 30
#include "repoclient.h"
31 31

  
32 32
int active = 0; // active or passive?
......
267 267

  
268 268
	printf("Running conf:\nIP: %s\nSTUN: %s\nREPO: %s\nACTIVE: %s\nVERBOSITY: %d\n", bind_ip ? bind_ip:"auto", stun_server, repository, active ? "active" : "passive", verbosity);
269 269

  
270
	//Init grapes: log facility and libevent
271
	grapesInit(event_base_new());
270
	//Init napa: log facility and libevent
271
	napaInit(event_base_new());
272 272

  
273 273
	// Initialize logging
274
	grapesInitLog(verbosity, NULL, NULL);
274
	napaInitLog(verbosity, NULL, NULL);
275 275

  
276 276
	//Init monitoring layer
277 277
	monInit(eventbase, NULL);
tests/MonTestDist/MonTestDist.c
6 6

  
7 7
#include "ml.h"
8 8
#include "mon.h"
9
#include "grapes_log.h"
10
#include "grapes.h"
9
#include "napa_log.h"
10
#include "napa.h"
11 11
#include "repoclient.h"
12 12

  
13 13
#define SOCKETID_PUBLISH_NAME "SocketId"
......
412 412

  
413 413
	printf("Running conf:\nIP:\t\t%s\nSTUN:\t\t%s\nREPO:\t\t%s\nVERBOSITY:\t%d\nPORT:\t\t%d\nCYCLE:\t\t%ds\nCHANNEL:\t%s\nPAUSE:\t\t%dms\n", bind_ip ? bind_ip:"auto", stun_server, repository, verbosity, port, cycle, channel, avg_pause);
414 414

  
415
	//Init grapes: log facility and libevent
416
	grapesInit(event_base_new());
415
	//Init napa: log facility and libevent
416
	napaInit(event_base_new());
417 417

  
418 418
	// Initialize logging
419
	grapesInitLog(verbosity, NULL, NULL);
419
	napaInitLog(verbosity, NULL, NULL);
420 420

  
421 421
	//Init monitoring layer
422 422
	monInit(eventbase, NULL);
tests/RepoClient/RepoClient.c
8 8
#include        <event2/http.h>
9 9
#include        <event2/http_struct.h>
10 10

  
11
#include	<grapes.h>
12
#include	<grapes_log.h>
11
#include	<napa.h>
12
#include	<napa_log.h>
13 13
#include	<repoclient.h>
14 14
#include	<ml.h>
15 15

  
......
144 144
	}
145 145
	/* Initialize libevent and logging */
146 146
	eventbase = event_base_new();
147
	grapesInitLog(LOG_DEBUG, NULL, NULL);
147
	napaInitLog(LOG_DEBUG, NULL, NULL);
148 148
	repInit("");
149 149

  
150 150
	/* Parse config file and init repoclient with the "repository" cfg section */
......
160 160
	if (!ntests) fatal("No tests specified, exiting");
161 161

  
162 162
	struct timeval t = { 1, 0 };
163
	grapesSchedulePeriodic(&t, 1.0/5.0, do_tests, NULL);
163
	napaSchedulePeriodic(&t, 1.0/5.0, do_tests, NULL);
164 164
	do_tests(NULL, NULL);
165 165

  
166 166
	repClose(repoclient);
tests/log/logtest.c
1 1
/*
2
 * Log test and demo application for the logging facilities of the GRAPES framework.
2
 * Log test and demo application for the logging facilities of the NAPA framework.
3 3
 *
4
 * There are 2 ways of calling grapes_log:
5
 * 	- grapes_log(SEVERITY, format, args...)
4
 * There are 2 ways of calling napa_log:
5
 * 	- napa_log(SEVERITY, format, args...)
6 6
 *	- or use one of the convenience macros like debug(format, args...) or info(format, args...) as shown below.
7 7
 *
8 8
 */
9 9

  
10
#include	<grapes_log.h>		/* You must include grapes_log.h in order to use grapes logging */
10
#include	<napa_log.h>		/* You must include napa_log.h in order to use napa logging */
11 11

  
12 12
#include	<math.h>		/* This one is just for fun */
13 13

  
14 14
int main(int argc, char *argv) {
15 15

  
16
	grapes_log(LOG_INFO, "You won't see this as logging is not initialized");
16
	napa_log(LOG_INFO, "You won't see this as logging is not initialized");
17 17

  
18 18
	/* Initialize logging */
19
	grapesInitLog(-1, NULL, NULL);
19
	napaInitLog(-1, NULL, NULL);
20 20

  
21
	grapes_log(LOG_WARN,"Warning! Here I come!");
21
	napa_log(LOG_WARN,"Warning! Here I come!");
22 22

  
23
	grapes_log(LOG_INFO,"Hey! This is my %dst %s message", 1, "INFO");
23
	napa_log(LOG_INFO,"Hey! This is my %dst %s message", 1, "INFO");
24 24
	info("And here comes the %dnd, just much simpler", 2);
25 25

  
26 26
	error("And this is an error message");	
27 27

  
28
	grapesCloseLog();
28
	napaCloseLog();
29 29

  
30 30
	info("Invisible again, as logging is closed");
31 31

  
32
	grapesInitLog(-1, NULL, NULL);
32
	napaInitLog(-1, NULL, NULL);
33 33

  
34 34
	debug("Next, I'm going to fatally die...");
35 35

  
tests/neighborlist/neighborlist.c
8 8
#include        <event2/http.h>
9 9
#include        <event2/http_struct.h>
10 10

  
11
#include	<grapes.h>
12
#include	<grapes_log.h>
11
#include	<napa.h>
12
#include	<napa_log.h>
13 13
#include	<repoclient.h>
14 14
#include	<neighborlist.h>
15 15

  
......
54 54
	}
55 55
	/* Initialize libevent and logging */
56 56
	eventbase = event_base_new();
57
	grapesInitLog(-1, NULL, NULL);
57
	napaInitLog(-1, NULL, NULL);
58 58
	repInit("");
59 59

  
60 60
	/* Parse config file and init repoclient with the "repository" cfg section */
......
72 72
		cfg_getint(neighborlist_cfg, "update_period"), NULL, NULL, NULL);
73 73

  
74 74
	struct timeval begin = { 5, 0 };
75
	grapesSchedulePeriodic(&begin, 1.0/10.0, periodic_query, neighborlist);
75
	napaSchedulePeriodic(&begin, 1.0/10.0, periodic_query, neighborlist);
76 76

  
77 77

  
78 78
	event_base_loop(eventbase, 0);
tests/nvtest1/nvtest1.c
274 274
						evhttp_send_reply(req,305,"REQUEST PROCESSING FAILED",NULL);
275 275
						goto finally;
276 276
					}
277
					evbuffer_add_printf(req->output_buffer,"<html><head><title>GRAPES - Registration</title></head>"
277
					evbuffer_add_printf(req->output_buffer,"<html><head><title>NAPA - Registration</title></head>"
278 278
						"<body><h3>Successfully registered to %s (delay: %f)</h3></body></html>", url, delay);
279 279
				}
280 280
				else {
281 281
					int fd = open(REGFORM_FILE_NAME,O_RDONLY);
282 282
					if(fd > 0) evbuffer_add_file(req->output_buffer, fd, 0, 10000);
283
					else evbuffer_add_printf(req->output_buffer,"<html><head><title>GRAPES - Error</title></head>"
283
					else evbuffer_add_printf(req->output_buffer,"<html><head><title>NAPA - Error</title></head>"
284 284
						"<body><h3>Error!! Cannot load file %s</h3></body></html>", REGFORM_FILE_NAME);
285 285
				}
286 286
				evhttp_send_reply(req,200,"OK",NULL);
tests/nvtest2/nvtest2.c
182 182
Peer *peer_init(const char *configfile) {
183 183
	peer = calloc(sizeof(Peer), 1);
184 184

  
185
	// Init grapes: log facility and libevent
186
	grapesInit(event_base_new());
187
	info("GRAPES initialized.");
185
	// Init napa: log facility and libevent
186
	napaInit(event_base_new());
187
	info("NAPA initialized.");
188 188

  
189 189
	// Parse config file */
190 190
	cfg_t *main_config = cfg_init(cfg_main, CFGF_NONE);
......
209 209

  
210 210
	// Initialize connection opener loop for requested connections
211 211
	struct timeval begin = { 10, 0 };
212
	grapesSchedulePeriodic(&begin, 1.0/(double)peer->nblist_update_period, check_conn_reqs, NULL);
212
	napaSchedulePeriodic(&begin, 1.0/(double)peer->nblist_update_period, check_conn_reqs, NULL);
213 213

  
214 214
	// Initialize stream source and destination
215 215
	if (!dummymode) {
......
228 228
	verbosity = cfg_getint(mon_config, "level");
229 229

  
230 230
	// Initialize logging
231
	grapesInitLog(verbosity, NULL, NULL);
231
	napaInitLog(verbosity, NULL, NULL);
232 232
	info("Logging initialized with verbosity: %d", verbosity);
233 233

  
234 234
	// Init monitoring layer
......
252 252
	peer->neighborlist = neighborlist_init(peer->repository, peer->nblist_desired_size, peer->nblist_update_period, peer->channel, NULL, NULL);
253 253

  
254 254
	struct timeval begin = { 5, 0 };
255
	grapesSchedulePeriodic(&begin, 1.0/(double)peer->nblist_update_period, periodic_nblst_query, peer->neighborlist);
255
	napaSchedulePeriodic(&begin, 1.0/(double)peer->nblist_update_period, periodic_nblst_query, peer->neighborlist);
256 256
}
257 257

  
258 258
// Initialize messaging layer
......
283 283
		receive_local_socketID_cb, (void*)eventbase);
284 284

  
285 285
	while (!messaging_ready) {
286
		grapesYield();
286
		napaYield();
287 287
	}
288 288
	info("ML has been initialized, with local addess: %s", peer->LocalID);
289 289
}
......
673 673
	src->chunk_duration = chunk_duration;
674 674
	src->chunkid = 0;
675 675

  
676
	grapesSchedulePeriodic(NULL, 1.0/chunk_duration, read_stream, src);
676
	napaSchedulePeriodic(NULL, 1.0/chunk_duration, read_stream, src);
677 677
}
678 678

  
679 679
// Get the list of requested connections' list from the repository
......
743 743
		dummymode = 1;
744 744
	}
745 745

  
746
	// Initialize the GRAPES infrastructure
746
	// Initialize the NAPA infrastructure
747 747
	peer = peer_init(argv[1]);
748 748

  
749 749
	// Start everything
tests/nvtest2/nvtest2.h
20 20
#include <event2/http_struct.h>
21 21
#include <confuse.h>
22 22
 
23
#include <grapes.h>
24
#include <grapes_log.h>
23
#include <napa.h>
24
#include <napa_log.h>
25 25
#include <ml.h>
26 26
#include <mon.h>		
27 27
#include <repoclient.h>
tests/peer/chunk.h
14 14
#include <event2/buffer.h>
15 15
#include <sys/time.h>
16 16

  
17
#include "grapes.h"
17
#include "napa.h"
18 18

  
19 19

  
20 20
struct chunk {
tests/peer/init.c
56 56
Peer *peer_init(const char *configfile) {
57 57
	peer = calloc(sizeof(Peer),1);
58 58

  
59
	grapesInit(event_base_new());
59
	napaInit(event_base_new());
60 60

  
61 61
	cfg_t *main_config = cfg_init(cfg_main, CFGF_NONE);
62 62
	if(cfg_parse(main_config, configfile) == CFG_PARSE_ERROR)
......
103 103
		recv_localsocketID_cb, eventbase);
104 104

  
105 105
	while (!messaging_ready) {
106
		grapesYield();
106
		napaYield();
107 107
        }
108 108
	info("ML has been initialized, local addess is %s", LocalPeerID);
109 109
}
tests/peer/nvtest1.c
1 1
/*
2 2
 */
3
#include "grapes.h"
4
#include "grapes_log.h"
3
#include "napa.h"
4
#include "napa_log.h"
5 5
#include "chunk.h"
6 6
#include "ml.h"
7 7

  
tests/peer/peer.c
1 1
/*
2
 * GRAPES test peer implementation
2
 * NAPA test peer implementation
3 3
 */
4 4

  
5 5
#include	"peer.h"
......
44 44
		exit(-1);
45 45
	}
46 46

  
47
        grapesInitLog(LOG_INFO, NULL, NULL);		/* Initialize logging */
48
	peer = peer_init(argv[1]);	/* Initialize the GRAPES infrastructure */
47
        napaInitLog(LOG_INFO, NULL, NULL);		/* Initialize logging */
48
	peer = peer_init(argv[1]);	/* Initialize the NAPA infrastructure */
49 49

  
50 50
	info("Initialization done");
51 51

  
tests/peer/peer.h
20 20
#include        <event2/http_struct.h>
21 21
#include        <confuse.h>
22 22
 
23
#include	<grapes.h>
24
#include	<grapes_log.h>
23
#include	<napa.h>
24
#include	<napa_log.h>
25 25
#include	<ml.h>
26 26
#include	<mon.h>		
27 27
#include	<repoclient.h>
tests/peer/ul/source.c
65 65
	src->bev = (struct bufferevent *)bufferevent_socket_new((struct event_base *)eventbase, udpSocket, 0);
66 66
	bufferevent_enable(src->bev, EV_READ);
67 67
	src->chunk_duration = chunk_duration;
68
	grapesSchedulePeriodic(NULL, 1.0/chunk_duration, read_stream, src);
68
	napaSchedulePeriodic(NULL, 1.0/chunk_duration, read_stream, src);
69 69
}
70 70

  
71 71

  

Also available in: Unified diff