Implementation

The following page will show what has been our implementation of this pattern by providing the documentation of the APIs created.

Share

The Share class is the beating heart of the pattern of the same name, the raison d’etre of the same and spokesperson for the current of thought that characterized the project in its entirety: elegance is everything. The class has the list of services that a device proudly makes available to all, and offers features to add or remove others. But the main responsibility of this class is to perform the discovery function, a symbol of an endless adventure, an adventure that begins in the search for the services that best lend themselves to the arduous and meticulous work that the calling service requires.

The function uses the MDNS protocol to first calculate the ip address of each device on the network, then subsequently examine the table of services available from the same.

Note

In computer networking, the multicast DNS (mDNS) protocol resolves hostnames to IP addresses within small networks that do not include a local name server. It is a zero-configuration service, using essentially the same programming interfaces, packet formats and operating semantics as the unicast Domain Name System (DNS). Although Stuart Cheshire designed mDNS as a stand-alone protocol, it can work in concert with standard DNS servers.

The discovery function is called by call, a function that finds an origin but perhaps does not find an end, a very long path that only the best services can undertake to the end. And so it is that from these services the transfer of knowledge takes place between the calling device and the called device, a knowledge obtained in a transversal, unorthodox way, based on the code and not on the network. The caller does not get knowledge directly, if he has to conquer it by executing the code that was provided to him by the caller.

Share doesn’t give you fish, but it can help you fish. Elegance is everything.

class Share
new()

The constructor of the object Share

Returns

The new Share just created with the table of available services

Return type

Share

attach(s)

This method inserts a service into the table of available services

Parameters

s (Service) – The service to add

detach(s)

This method removes a service from the table of available services

Parameters

s (Service) – The service to remove

is_present(s, t)

This method search a service from the services table and returns true if it finds an occurrence

Parameters
  • s (Service) – The service to search

  • t (table) – The table on which doing the search

Returns

True if the service is present, false otherwise

Return type

boolean

discovery(macro_mib)
Parameters

macro_mib (any) –

find(macro_mib)

Internal function that retrieve the set of services with the corresponding prefix

Parameters

macro_mib (str) – The prefix of the mib to search

Returns

The set of corresponding services

Return type

table

open_udp_socket(ip, macro_mib, result)

Internal function used to establish a remote connection with udp socket

Parameters
  • ip (str) – The ip of the remote device

  • macro_mib (str) – MIB of the service owned by the remote service

  • result (table) – The table used to save all results

Service

The Service class represents any functionality made available by the device that owns it.

The responsibility of this class, in addition to providing the result of the computation with the parameters requested by the caller through the daemon function, is to establish a safe and reliable communication protocol with the same.

Each Service has a personal MIB which makes it unique in the environment in which it operates.

class Service
new(i, f, d, p, ...)

The constructor of the object Service

Parameters
  • i (str) – The MIB of the current Service

  • f (str) – The function wrapped in a string that allows the communication with the inner protcol

  • d (function) – The defined daemon that share data with the function of the same Service

  • p (function) – The pre-condition necessary to checking

  • vararg (any) – The set of features

Returns

The new Service just created or nil in case of any issues

Return type

Service

Feature

The Feature class represents the entity that contains the complete set of services that perform the same function.

In fact, this class has a MIB that identifies a macro category within its environment. Each Feature has a feature called post which checks the postconditions of each result received.

The responsibility of this class is also to identify the list of desired services that share the same network through the call function.

class Feature
new(i, p)

The constructor of the object Feature

Parameters
  • i (str) – The MIB of the current Feature

  • p (function) – The post-condition necessary to checking

Returns

The new Feature just created or nil in case of any issues

Return type

Feature

call(...)

A stub that searches, verifies, executes and produces the results related to a remote service

Parameters

vararg (any) – The parameters that are called are a regular expression and the parameters on which to perform the operation

Returns

Produces a boolean indicating whether the operation is successful and a table with the values ​​produced by the requested service

Return type

table or boolean