-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add IPCP_Manager package, refactor demo
- Loading branch information
1 parent
55e768a
commit 6e1038d
Showing
3 changed files
with
62 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,22 @@ | ||
with Demos; | ||
with Net; | ||
with Ada.Strings.Hash; | ||
with Ada.Strings.Bounded; | ||
with Ada.Containers.Indefinite_Hashed_Maps; | ||
with CDAP; | ||
with EFCP; | ||
with IPCP_Manager; use IPCP_Manager; | ||
|
||
procedure Demo is | ||
|
||
-- Mac address type | ||
use Net; | ||
|
||
procedure Header is | ||
begin | ||
Demos.Put (0, 0, "eRINA_Debug"); | ||
end Header; | ||
|
||
-- Max of 32 IPCs can be registered | ||
MAX_IPC_COUNT : constant Natural := 32; | ||
MAX_IPCP_NAME_LENGTH : constant Natural := 128; | ||
|
||
package IPCP_String is new Ada.Strings.Bounded.Generic_Bounded_Length (MAX_IPCP_NAME_LENGTH); | ||
use IPCP_String; | ||
|
||
function Hash(Name : in Bounded_String) return Ada.Containers.Hash_Type is begin | ||
return Ada.Strings.Hash(To_String (Name)); | ||
end Hash; | ||
|
||
-- Eventually make this the protected object that holds the IPC database | ||
package IPCP_MAC_Map is new Ada.Containers.Indefinite_Hashed_Maps ( | ||
Key_Type => Bounded_String, | ||
Element_Type => Ether_Addr, | ||
Hash => Hash, | ||
Equivalent_Keys => "=" | ||
); | ||
|
||
use IPCP_MAC_Map; | ||
|
||
-- Instantiate IPCP map | ||
IPCP_Map : Map; | ||
|
||
-- Debug only, remove later | ||
Demo_IPCP_Name : constant Bounded_String := To_Bounded_String ("Demo.IPCP"); | ||
Demo_IPCP_Name : constant IPCP_Name.Bounded_String := IPCP_Name.To_Bounded_String ("Demo.IPCP"); | ||
Demo_IPCP_MacAddr : constant Ether_Addr := (others => 16#ff#); | ||
Demo_IPCP : IPCP := IPCP_Manager.Create (Demo_IPCP_Name, Demo_IPCP_MacAddr); | ||
begin | ||
Header; | ||
IPCP_Map.Include (Demo_IPCP_Name, Demo_IPCP_MacAddr); | ||
end Demo; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package body IPCP_Manager is | ||
|
||
function Hash(Name : in Bounded_String) return Ada.Containers.Hash_Type is begin | ||
return Ada.Strings.Hash(To_String (Name)); | ||
end Hash; | ||
|
||
function Create (Name : Bounded_String; MAC_Addr : Net.Ether_Addr) return IPCP is | ||
New_IPCP : IPCP; | ||
begin | ||
New_IPCP.Name := Name; | ||
IPCP_Map.Insert (Name, MAC_Addr); | ||
|
||
return New_IPCP; | ||
end Create; | ||
|
||
end IPCP_Manager; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
with Ada.Strings.Hash; | ||
with Ada.Strings.Bounded; | ||
with Ada.Containers.Indefinite_Hashed_Maps; | ||
with Net; | ||
|
||
package IPCP_Manager is | ||
use type Net.Uint8; | ||
use type Net.Ether_Addr; | ||
|
||
-- Max of 32 IPCs can be registered | ||
MAX_IPC_COUNT : constant Natural := 32; | ||
MAX_IPCP_NAME_LENGTH : constant Natural := 128; | ||
|
||
package IPCP_Name is | ||
new Ada.Strings.Bounded.Generic_Bounded_Length (MAX_IPCP_NAME_LENGTH); | ||
|
||
use IPCP_Name; | ||
|
||
function Hash(Name : in Bounded_String) return Ada.Containers.Hash_Type; | ||
|
||
-- Eventually make this the protected object that holds the IPC database | ||
package IPCP_MAC_Map is new Ada.Containers.Indefinite_Hashed_Maps ( | ||
Key_Type => Bounded_String, | ||
Element_Type => Net.Ether_Addr, | ||
Hash => Hash, | ||
Equivalent_Keys => "=" | ||
); | ||
|
||
-- Instantiate IPCP map | ||
IPCP_Map : IPCP_MAC_Map.Map; | ||
|
||
type Data_Buffer is array(1 .. 128) of Net.Uint8; | ||
|
||
type IPCP is tagged record | ||
Name : Bounded_String; | ||
IO_Buffer : Data_Buffer := (others => 0); | ||
end record; | ||
|
||
function Create (Name : Bounded_String; MAC_Addr : Net.Ether_Addr) return IPCP; | ||
|
||
end IPCP_Manager; |