summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2018-12-15 19:24:00 +0100
committerNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2018-12-15 19:24:00 +0100
commit446ab802ff886d7456df4ae98859842f70af9910 (patch)
tree90466a76c12806384d4df4b2865b5df15a72a41d /src
parente8134a4e64a215a6f76cf24c52d4f67d3bfdcb71 (diff)
Get debug to okay the src files.
Diffstat (limited to 'src')
-rw-r--r--src/ataxia_admin.erl81
-rw-r--r--src/ataxia_entry.erl2
-rw-r--r--src/ataxia_id.erl1
-rw-r--r--src/ataxia_id_manager.erl2
-rw-r--r--src/ataxia_security.erl12
-rw-r--r--src/ataxia_server.erl41
-rw-r--r--src/ataxia_time.erl29
-rw-r--r--src/ataxic.erl2
-rw-r--r--src/ataxic_sugar.erl22
9 files changed, 148 insertions, 44 deletions
diff --git a/src/ataxia_admin.erl b/src/ataxia_admin.erl
new file mode 100644
index 0000000..c6eb9be
--- /dev/null
+++ b/src/ataxia_admin.erl
@@ -0,0 +1,81 @@
+-module(ataxia_admin).
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+-record
+(
+ db_model,
+ {
+ store_file :: string(),
+ neighbors :: list(node())
+ }
+).
+
+-type type() :: #db_model{}.
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+-export_type([type/0]).
+
+-export
+(
+ [
+ new/2,
+ add_db/2,
+ start/1
+ ]
+).
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+-spec new (string(), list(node())) -> type().
+new (StorageFile, Neighbors) ->
+ #db_model
+ {
+ store_file = StorageFile,
+ neighbors = Neighbors
+ }.
+
+-spec start (type()) -> 'ok'.
+start (Model) ->
+ StorageFile = Model#db_model.store_file,
+ Neighbors = Model#db_model.neighbors,
+
+ ok = application:set_env(mnesia, dir, StorageFile),
+
+ case mnesia:create_schema([node()|Neighbors]) of
+ {error, {Name, {already_exists, Name}}} -> ok;
+ ok -> ok
+ end,
+
+ ok = mnesia:start(),
+
+ ok.
+
+-spec add_db (atom(), type()) -> 'ok'.
+add_db (DBName, Model) ->
+ Neighbors = Model#db_model.neighbors,
+
+ mnesia:create_table
+ (
+ DBName,
+ [
+ {record_name, ataxia_entry:get_record_name()},
+ {attributes, ataxia_entry:get_record_info()},
+ {disc_copies, [node()|Neighbors]},
+ {disc_only_copies, []},
+ {ram_copies, []},
+ {type, ordered_set},
+ {local_content, false}
+ ]
+ ),
+
+ ok.
diff --git a/src/ataxia_entry.erl b/src/ataxia_entry.erl
index 17460d9..a87aa35 100644
--- a/src/ataxia_entry.erl
+++ b/src/ataxia_entry.erl
@@ -68,7 +68,7 @@ new (ID, ReadPermission, WritePermission, Value) ->
id = ID,
read_perm = ReadPermission,
write_perm = WritePermission,
- lock = ataxia_security:unlocked(),
+ lock = ataxia_lock:unlocked(),
val = Value
}.
diff --git a/src/ataxia_id.erl b/src/ataxia_id.erl
index c809b90..6e8a925 100644
--- a/src/ataxia_id.erl
+++ b/src/ataxia_id.erl
@@ -8,6 +8,7 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+-export_type([type/0]).
%%%% Actual Interface
-export
diff --git a/src/ataxia_id_manager.erl b/src/ataxia_id_manager.erl
index 6a8fdc2..813f74c 100644
--- a/src/ataxia_id_manager.erl
+++ b/src/ataxia_id_manager.erl
@@ -60,7 +60,7 @@ new_entry () ->
allocate_id_in_entry (Entry) ->
case Entry#entry.freed_ids of
[] ->
- NewID = next_id(Entry#entry.last_id),
+ NewID = ataxia_id:next(Entry#entry.last_id),
{
Entry#entry{ last_id = NewID },
NewID
diff --git a/src/ataxia_security.erl b/src/ataxia_security.erl
index 7654384..95040f3 100644
--- a/src/ataxia_security.erl
+++ b/src/ataxia_security.erl
@@ -5,7 +5,7 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-type named_user() :: {'user', any()}.
-type user() :: (named_user() | 'admin' | 'any' | 'janitor').
--type permission() :: ordset:ordset(user()).
+-type permission() :: ordsets:ordset(user()).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -26,15 +26,15 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-spec add_access (user(), permission()) -> permission().
add_access (User, Permission) ->
- ordset:add_element(User, Permission).
+ ordsets:add_element(User, Permission).
-spec remove_access (user(), permission()) -> permission().
remove_access (User, Permission) ->
- ordset:del_element(User, Permission).
+ ordsets:del_element(User, Permission).
-spec allow_only (user()) -> permission().
allow_only (User) ->
- ordset:add_element(User, ordset:new()).
+ ordsets:add_element(User, ordsets:new()).
-spec user_from_id (any()) -> user().
user_from_id (ID) -> {user, ID}.
@@ -54,7 +54,7 @@ can_access (Permission, User) ->
admin -> true;
_ ->
(
- ordset:is_element(any, Permission)
- or ordset:is_element(User, Permission)
+ ordsets:is_element(any, Permission)
+ or ordsets:is_element(User, Permission)
)
end.
diff --git a/src/ataxia_server.erl b/src/ataxia_server.erl
index 2d48a30..dccd0db 100644
--- a/src/ataxia_server.erl
+++ b/src/ataxia_server.erl
@@ -12,7 +12,7 @@
[
add_at/5,
add/4,
- reserve/3,
+ reserve/2,
fetch/3,
update/4,
@@ -61,11 +61,11 @@ add_new_item (DB, Item) ->
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-spec add_at
(
+ atom(),
ataxia_id:type(),
ataxia_security:permission(),
ataxia_security:permission(),
- any(),
- atom()
+ any()
)
-> ({'aborted', any()} | 'ok').
add_at (DB, ID, ReadPerm, WritePerm, Value) ->
@@ -80,34 +80,25 @@ add_at (DB, ID, ReadPerm, WritePerm, Value) ->
atom(),
ataxia_security:permission(),
ataxia_security:permission(),
- any())
+ any()
+ )
-> ({'aborted', any()} | {'ok', ataxia_id:type()}).
add (DB, ReadPerm, WritePerm, Value) ->
- ID = db_item_ids_manager:allocate(DB),
+ ID = ataxia_id_manager:allocate(DB),
case add_at(DB, ID, ReadPerm, WritePerm, Value) of
- {atomic, ok} -> {ok, ID};
+ ok -> {ok, ID};
{aborted, Val} -> {aborted, Val}
end.
-spec reserve
(
atom(),
- ataxia_security:user(),
ataxia_id:type()
)
-> ({'aborted', any()} | 'ok').
-reserve (DB, User, ID) ->
- add_at
- (
- DB,
- ID,
- [User],
- [User],
- {
- reserved,
- <<"?">> %% TODO [FUNCTION: db][LOW]: timestamp
- }
- ).
+reserve (DB, ID) ->
+ JanitorPermission = ataxia_security:allow_only(ataxia_security:janitor()),
+ add_at(DB, ID, JanitorPermission, JanitorPermission, reserved).
-spec fetch
(
@@ -115,10 +106,10 @@ reserve (DB, User, ID) ->
ataxia_security:user(),
ataxia_id:type()
)
- -> ({'aborted', any()} | {'ok', any()} | 'not_found').
+ -> ({'aborted', any()} | {'ok', any()}).
fetch (DB, User, ID) ->
case mnesia:transaction(fun mnesia:read/2, [DB, ID]) of
- {atomic, []} -> not_found;
+ {atomic, []} -> {aborted, not_found};
{atomic, [Entry]} ->
true =
(
@@ -126,8 +117,8 @@ fetch (DB, User, ID) ->
and
ataxia_security:can_access
(
- User,
- ataxia_entry:get_read_permission(Entry)
+ ataxia_entry:get_read_permission(Entry),
+ User
)
),
{ok, ataxia_entry:get_value(Entry)};
@@ -141,7 +132,7 @@ fetch (DB, User, ID) ->
ataxia_security:user(),
ataxic:basic()
)
- -> ({'aborted', any()} | {'ok', any(), ataxia_id:type()} | 'not_found').
+ -> ({'aborted', any()} | {'ok', any(), ataxia_id:type()}).
fetch_any (_DB, _User, _Cond) ->
{aborted, unimplemented}.
@@ -151,7 +142,7 @@ fetch_any (_DB, _User, _Cond) ->
ataxia_security:user(),
ataxic:basic()
)
- -> ({'aborted', any()} | {'ok', any(), ataxia_id:type()} | 'not_found').
+ -> ({'aborted', any()} | {'ok', any(), ataxia_id:type()}).
fetch_all (_DB, _User, _Cond) ->
{aborted, unimplemented}.
diff --git a/src/ataxia_time.erl b/src/ataxia_time.erl
new file mode 100644
index 0000000..203f8bd
--- /dev/null
+++ b/src/ataxia_time.erl
@@ -0,0 +1,29 @@
+-module(ataxia_time).
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+-type type() :: none.
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+-export_type([type/0]).
+
+-export([add/2, is_past/1, now/0]).
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+-spec add (type(), type()) -> type().
+add (T0, _T1) -> T0.
+
+-spec is_past (type()) -> boolean().
+is_past (_T0) -> true.
+
+-spec now () -> type().
+now () -> none.
diff --git a/src/ataxic.erl b/src/ataxic.erl
index 35291b0..438cf17 100644
--- a/src/ataxic.erl
+++ b/src/ataxic.erl
@@ -50,7 +50,7 @@
-record(mseq, {ops :: list(meta())}).
--type meta() :: #read_perm{} | #write_perm{} | #value{} | #mseq{}.
+-type meta() :: #read_perm{} | #write_perm{} | #value{} | #lock{} | #mseq{}.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
diff --git a/src/ataxic_sugar.erl b/src/ataxic_sugar.erl
index 17165ac..fac4f5c 100644
--- a/src/ataxic_sugar.erl
+++ b/src/ataxic_sugar.erl
@@ -31,16 +31,18 @@ update_array_cell (IX, OP) ->
ataxic:constant(IX),
ataxic:sequence
(
- ataxic:apply_function
- (
- array,
- get,
- [
- ataxic:constant(IX),
- ataxic:current_value()
- ]
- ),
- OP
+ [
+ ataxic:apply_function
+ (
+ array,
+ get,
+ [
+ ataxic:constant(IX),
+ ataxic:current_value()
+ ]
+ ),
+ OP
+ ]
),
ataxic:current_value()
]