Files
FileProcessor/file_processor/lib/file_processor.ex
2025-12-05 16:57:52 -05:00

89 lines
1.9 KiB
Elixir

defmodule FileProcessor do
@moduledoc """
Documentation for `FileProcessor`.
"""
use GenServer
# Client
@server FileProcessor.Server
def start_link(initial_values) do
GenServer.start_link(__MODULE__, initial_values, name: @server)
end
def put_file({filename, contents}) do
GenServer.call(@server, {:put_file, filename, contents})
end
def get_files() do
GenServer.call(@server, :get_files)
end
def delete_file(filename) do
GenServer.call(@server, {:delete_file, filename})
end
def put_rfp({filename, contents}) do
GenServer.call(@server, {:put_rfp, filename, contents})
end
def get_rfp() do
GenServer.call(@server, :get_rfp)
end
def delete_rfp(filename) do
GenServer.call(@server, {:delete_rfp, filename})
end
def process_files() do
GenServer.call(@server, :process_files)
end
# Server
alias FileProcessor.Impl
@impl true
def init(initial_values) do
Impl.do_init()
{:ok, initial_values}
end
@impl true
def handle_call({:put_file, {filename, file}}, _from, current_state) do
{:reply, Impl.put_file(filename, file), current_state}
end
@impl true
def handle_call(:get_files, _from, current_state) do
{:reply, Impl.get_files(), current_state}
end
@impl true
def handle_call({:delete_file, filename}, _from, current_state) do
{:reply, Impl.delete_file(filename), current_state}
end
@impl true
def handle_call({:put_rfp, {filename, file}}, _from, current_state) do
{:reply, Impl.put_rfp(filename, file), current_state}
end
@impl true
def handle_call(:get_rfp, _from, current_state) do
{:reply, Impl.get_rfp(), current_state}
end
@impl true
def handle_call({:delete_rfp, filename}, _from, current_state) do
{:reply, Impl.delete_rfp(filename), current_state}
end
@impl true
def handle_call(:process_files, _from, current_state) do
{:reply, Impl.process_files(), current_state}
end
end