ram_fs: use server skeleton library

Related to #944.
This commit is contained in:
Christian Helmuth 2013-11-08 16:32:32 +01:00 committed by Norman Feske
parent 76cd788479
commit 1bbd54c9b7
2 changed files with 51 additions and 45 deletions

View File

@ -14,10 +14,9 @@
/* Genode includes */ /* Genode includes */
#include <file_system_session/rpc_object.h> #include <file_system_session/rpc_object.h>
#include <root/component.h> #include <root/component.h>
#include <cap_session/connection.h>
#include <base/sleep.h>
#include <os/attached_rom_dataspace.h> #include <os/attached_rom_dataspace.h>
#include <os/config.h> #include <os/config.h>
#include <os/server.h>
#include <os/session_policy.h> #include <os/session_policy.h>
#include <util/xml_node.h> #include <util/xml_node.h>
@ -36,11 +35,12 @@ namespace File_system {
{ {
private: private:
Server::Entrypoint &_ep;
Directory &_root; Directory &_root;
Node_handle_registry _handle_registry; Node_handle_registry _handle_registry;
bool _writable; bool _writable;
Signal_dispatcher<Session_component> _process_packet_dispatcher; Signal_rpc_member<Session_component> _process_packet_dispatcher;
/****************************** /******************************
@ -147,22 +147,23 @@ namespace File_system {
/** /**
* Constructor * Constructor
*/ */
Session_component(size_t tx_buf_size, Rpc_entrypoint &ep, Session_component(size_t tx_buf_size, Server::Entrypoint &ep,
Signal_receiver &sig_rec,
Directory &root, bool writable) Directory &root, bool writable)
: :
Session_rpc_object(env()->ram_session()->alloc(tx_buf_size), ep), Session_rpc_object(env()->ram_session()->alloc(tx_buf_size), ep.rpc_ep()),
_ep(ep),
_root(root), _root(root),
_writable(writable), _writable(writable),
_process_packet_dispatcher(sig_rec, *this, _process_packet_dispatcher(*this, &Session_component::_process_packets)
&Session_component::_process_packets)
{ {
/* /*
* Register '_process_packets' dispatch function as signal * Register '_process_packets' dispatch function as signal
* handler for packet-avail and ready-to-ack signals. * handler for packet-avail and ready-to-ack signals.
*/ */
_tx.sigh_packet_avail(_process_packet_dispatcher); Signal_context_capability sigh(_ep.manage(_process_packet_dispatcher));
_tx.sigh_ready_to_ack(_process_packet_dispatcher);
_tx.sigh_packet_avail(sigh);
_tx.sigh_ready_to_ack(sigh);
} }
/** /**
@ -170,6 +171,7 @@ namespace File_system {
*/ */
~Session_component() ~Session_component()
{ {
_ep.dissolve(_process_packet_dispatcher);
Dataspace_capability ds = tx_sink()->dataspace(); Dataspace_capability ds = tx_sink()->dataspace();
env()->ram_session()->free(static_cap_cast<Ram_dataspace>(ds)); env()->ram_session()->free(static_cap_cast<Ram_dataspace>(ds));
} }
@ -416,9 +418,8 @@ namespace File_system {
{ {
private: private:
Rpc_entrypoint &_channel_ep; Server::Entrypoint &_ep;
Signal_receiver &_sig_rec; Directory &_root_dir;
Directory &_root_dir;
protected: protected:
@ -497,8 +498,7 @@ namespace File_system {
throw Root::Quota_exceeded(); throw Root::Quota_exceeded();
} }
return new (md_alloc()) return new (md_alloc())
Session_component(tx_buf_size, _channel_ep, _sig_rec, Session_component(tx_buf_size, _ep, *session_root_dir, writeable);
*session_root_dir, writeable);
} }
public: public:
@ -506,19 +506,20 @@ namespace File_system {
/** /**
* Constructor * Constructor
* *
* \param session_ep session entrypoint * \param ep entrypoint
* \param sig_rec signal receiver used for handling the * \param md_alloc meta-data allocator
* data-flow signals of packet streams * \param root_dir root-directory handle (anchor for fs)
* \param md_alloc meta-data allocator
*/ */
Root(Rpc_entrypoint &session_ep, Allocator &md_alloc, Root(Server::Entrypoint &ep, Allocator &md_alloc, Directory &root_dir)
Signal_receiver &sig_rec, Directory &root_dir)
: :
Root_component<Session_component>(&session_ep, &md_alloc), Root_component<Session_component>(&ep.rpc_ep(), &md_alloc),
_channel_ep(session_ep), _sig_rec(sig_rec), _root_dir(root_dir) _ep(ep),
_root_dir(root_dir)
{ } { }
}; };
};
struct Main;
}
/** /**
@ -620,31 +621,36 @@ static void preload_content(Genode::Allocator &alloc,
} }
int main(int, char **) struct File_system::Main
{ {
using namespace File_system; Server::Entrypoint &ep;
enum { STACK_SIZE = 8192 }; Directory root_dir = { "" };
static Cap_connection cap;
static Rpc_entrypoint ep(&cap, STACK_SIZE, "ram_fs_ep");
static Sliced_heap sliced_heap(env()->ram_session(), env()->rm_session());
static Signal_receiver sig_rec;
static Directory root_dir("");
/* preload RAM file system with content as declared in the config */ /*
try { * Initialize root interface
Xml_node content = config()->xml_node().sub_node("content"); */
preload_content(*env()->heap(), content, root_dir); } Sliced_heap sliced_heap = { env()->ram_session(), env()->rm_session() };
catch (Xml_node::Nonexistent_sub_node) { }
static File_system::Root root(ep, sliced_heap, sig_rec, root_dir); Root fs_root = { ep, sliced_heap, root_dir };
env()->parent()->announce(ep.manage(&root)); Main(Server::Entrypoint &ep) : ep(ep)
{
/* preload RAM file system with content as declared in the config */
try {
Xml_node content = config()->xml_node().sub_node("content");
preload_content(*env()->heap(), content, root_dir); }
catch (Xml_node::Nonexistent_sub_node) { }
for (;;) { env()->parent()->announce(ep.manage(fs_root));
Signal s = sig_rec.wait_for_signal();
static_cast<Signal_dispatcher_base *>(s.context())->dispatch(s.num());
} }
};
return 0;
} /**********************
** Server framework **
**********************/
char const * Server::name() { return "ram_fs_ep"; }
Genode::size_t Server::stack_size() { return 2048 * sizeof(long); }
void Server::construct(Server::Entrypoint &ep) { static File_system::Main inst(ep); }

View File

@ -1,4 +1,4 @@
TARGET = ram_fs TARGET = ram_fs
SRC_CC = main.cc SRC_CC = main.cc
LIBS = base config LIBS = base config server
INC_DIR += $(PRG_DIR) INC_DIR += $(PRG_DIR)