Statistics
| Branch: | Revision:

chunker-player / event_http / receivers_registry.c @ 59c85ad1

History | View | Annotate | Download (1.67 KB)

1
/**
2
 * @file receiver_registry.c
3
 *
4
 * A registry of external applications willing to receive chunks.
5
 *
6
 * Based on a static array of information about registered applications.
7
 *
8
 * Napa-Wine project 2009-2010
9
 * @author: Giuseppe Tropea <giuseppe.tropea@lightcomm.it>
10
 */
11

    
12
#include "chunk_external_interface.h"
13
#include "ul_commons.h"
14

    
15
int ulRegisterApplication(char *address, int *port, char* path, int *pos) {
16
  //the following hopefully initializes all alements of the array with the same values...
17
  static ApplicationInfo apps[UL_MAX_EXTERNAL_APPLICATIONS] = {
18
    {"", 0, "", 0} //address, port, path, status
19
  };
20

    
21
  if(*pos >= UL_MAX_EXTERNAL_APPLICATIONS) {
22
    error("Registering application index > MAX error");
23
    return UL_RETURN_FAIL;
24
  }
25
  if(address[0] == '\0' && *port == 0 && path[0] == '\0') { //caller wants to retrieve status of application
26
    //give back the values of the application at position pos
27
    sprintf(address, "%s", apps[*pos].address);
28
    *port = apps[*pos].port;
29
    sprintf(path, "%s", apps[*pos].path);
30
    //debug("Somebody asked for the status of application at %s:%d%s, position %d", address, *port, path, *pos);
31
    return UL_RETURN_OK;
32
  }
33
  else { //register an application at the first free position
34
    //FIND A FREE INDEX
35
    int free_index = 1; //just to try, skipping position zero...
36
    //REGISTER BY FILLING INFO
37
    sprintf(apps[free_index].address, "%s", address);
38
    apps[free_index].port = *port;
39
    sprintf(apps[free_index].path, "%s", path);
40
    //give back the registered info
41
    *pos = free_index;
42
    info("Somebody registered an external application at %s:%d%s, position %d", address, *port, path, *pos);
43

    
44
    return UL_RETURN_OK;
45
  }
46
}