dimanche 19 avril 2015

How to abstract a network services API in a embedded UNIX system


Vote count:

0




Im working with embedded LINUX system for a router. There is a web GUI for the user to configure options. When user fill a web form this is submitted to a web server function that is responsible of validating the user input, save the configuration in the database and restart some service using C standard library and bash scripts. There is a command line interface too than can be invoked via SSH. This CLI again in his own validates the user input, save the configuration into database and restart some service using bash scripts.


I would like to abstract some business logic into more cohesive layers. For instance I am thinking to use a Abstract Data type for the DHCP Server. ADT interface will expose operations over the conceptual entity (start/stop service, set the IP addresses pool to give to LAN clients) and hides the operations implementation details (the scripts to set up the DHCP Server).


So giving this piece of the ADT for the DHCP Server:



static int enable;
static struct in_addr lan_ip_pool_start;
static struct in_addr lan_ip_pool_end;
static char* opt12_hostname;
.....

int DhcpServerStart ()
{
....
....
}


For the method above, it may update enable variable when it is called, update the database and implement the code to fork and exec the DHCP Server binary and pass it right arguments. But i think i can get more benefits by abstracting more the responsabilities not related.


So I am thinking to abstract the database using a new API, and maybe i can abstract the shell scripts using another API. This way i can migrate database and scripts without changing the implementation of the domain objects:



#include <databaseapi.h>
#include <shellcfg.h>

static int enable;
static struct in_addr lan_ip_pool_start;
static struct in_addr lan_ip_pool_end;
static char* opt12_hostname;
.....

int DHCPServerStart ()
{
database_saveDHCPServerState(1);
shell_DHCPServerStart();
}


I am not happy at all with the method above. I think updating database is not something a DHCP Server as a conceptual object should take care of. At the same time i am not sure if I should abstract the shell scripts to set up the network services or it should be implemented by each ADT representing the business-specific entities.


On the other hand, when the system boots the function that handles system initialization will instance all business entities so I am thinking about to include all the entities in a global 'class'. Maybe this class may expose a interfaces that let the user interfaces to set up a given service, and then this global class should take care about updating the database and start some service using the specific ADT representing the service.



asked 1 min ago







How to abstract a network services API in a embedded UNIX system

Aucun commentaire:

Enregistrer un commentaire