NewMadeleine

Documentation

nm_madico_launcher.h
Go to the documentation of this file.
1/*
2 * NewMadeleine
3 * Copyright (C) 2006-2024 (see AUTHORS file)
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or (at
8 * your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 */
15
20#ifndef NM_MADICO_LAUNCHER_H
21#define NM_MADICO_LAUNCHER_H
22
23#include <Padico/Topology.h>
24#include <Padico/NetSelector.h>
25
26static nm_drv_vect_t nm_madico_launcher_default_selector(const char*url, void*_arg)
27{
28 struct nm_launcher_gates_s*p_gates = _arg;
29 const int size = p_gates->size;
30 int i = 0;
31 while(i < size)
32 {
33 if((p_gates->p_gates[i].p_url != NULL) && (strcmp(p_gates->p_gates[i].p_url, url) == 0))
34 {
35 nm_drv_vect_t p_drvs = nm_drv_vect_copy(&p_gates->p_gates[i].drvs);
36 return p_drvs;
37 }
38 i++;
39 }
40 return NULL;
41}
42
43
46static inline void nm_launcher_gates_populate_ns(struct nm_launcher_gates_s*p_gates, padico_topo_node_t*p_peers)
47{
48 const char*nmad_driver = padico_getenv("NMAD_DRIVER");
49 if(!nmad_driver)
50 {
51 struct nm_component_hashtable_s loaded_components;
52 nm_component_hashtable_init(&loaded_components);
53 int i;
54 for(i = 0; i < p_gates->size; i++)
55 {
56 nm_drv_vect_init(&p_gates->p_gates[i].drvs);
57 const puk_component_t component_1 =
58 padico_ns_serial_selector(p_peers[i], "trk_small", puk_iface_NewMad_minidriver());
59 const puk_component_t component_2 =
60 padico_ns_serial_selector(p_peers[i], "trk_large", puk_iface_NewMad_minidriver());
61 assert(component_1 != NULL);
62 assert(component_2 != NULL);
63
64 nm_drv_t p_drv1 = nm_component_hashtable_lookup(&loaded_components, component_1);
65 if(p_drv1 == NULL)
66 {
67 p_drv1 = nm_launcher_add_driver(component_1, nm_trk_small);
68 nm_component_hashtable_insert(&loaded_components, component_1, p_drv1);
69 }
70 nm_drv_vect_push_back(&p_gates->p_gates[i].drvs, p_drv1);
71 nm_drv_t p_drv2 = nm_component_hashtable_lookup(&loaded_components, component_2);
72 if(p_drv2 == NULL)
73 {
74 p_drv2 = nm_launcher_add_driver(component_2, nm_trk_large);
75 nm_component_hashtable_insert(&loaded_components, component_2, p_drv2);
76 }
77 nm_drv_vect_push_back(&p_gates->p_gates[i].drvs, p_drv2);
78 }
80 nm_component_hashtable_destroy(&loaded_components);
81 }
82}
83
84
85#endif /* NM_MADICO_LAUNCHER_H */
nm_drv_t nm_launcher_add_driver(puk_component_t component, nm_trk_kind_t kind)
Add a driver to the session.
void nm_launcher_set_selector(nm_launcher_selector_t selector, void *_arg)
Declare the selector to use to establish connections.
static void nm_launcher_gates_populate_ns(struct nm_launcher_gates_s *p_gates, padico_topo_node_t *p_peers)
use PadicoTM NetSelector to populate gates with driver.
static nm_drv_vect_t nm_madico_launcher_default_selector(const char *url, void *_arg)
nm_len_t size
size of the onsided data (not incuding target-side completion)
@ nm_trk_small
small packets with headers & parsing
Definition: nm_types.h:94
@ nm_trk_large
large packets with rdv, no header
Definition: nm_types.h:95
Driver.
Definition: nm_drv.h:29
struct nm_drv_vect_s drvs
Definition: nm_launcher.h:57
a set of gates to manage connection establishment by launcher
Definition: nm_launcher.h:62
struct nm_launcher_gate_s * p_gates
Definition: nm_launcher.h:65