Skip to content

Commit

Permalink
Convenience helper for attached ROM dataspaces
Browse files Browse the repository at this point in the history
In the line of the 'Attached_ram_dataspace' and
'Attached_io_mem_dataspace' classes, this new helper simplifies the
access to ROM dataspaces.
  • Loading branch information
nfeske committed Feb 14, 2012
1 parent a6bac95 commit 8495a5f
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions os/include/os/attached_rom_dataspace.h
@@ -0,0 +1,78 @@
/*
* \brief ROM dataspace utility
* \author Norman Feske
* \date 2012-01-09
*/

/*
* Copyright (C) 2012 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2.
*/

#ifndef _INCLUDE__OS__ATTACHED_ROM_DATASPACE_H_
#define _INCLUDE__OS__ATTACHED_ROM_DATASPACE_H_

#include <rom_session/connection.h>
#include <dataspace/client.h>
#include <base/env.h>

namespace Genode {

class Attached_rom_dataspace
{
private:

Rom_connection _rom;
Rom_dataspace_capability _ds;
size_t _size;
void *_local_addr;

public:

/**
* Constructor
*
* \throw Rom_connection::Rom_session_failed
* \throw Rm_session::Attach_failed
*/
Attached_rom_dataspace(char const *name)
:
_rom(name),
_ds(_rom.dataspace()),
_size(Dataspace_client(_ds).size()),
_local_addr(env()->rm_session()->attach(_ds))
{ }

/**
* Destructor
*/
~Attached_rom_dataspace()
{
env()->rm_session()->detach(_local_addr);
}

/**
* Return capability of the used ROM dataspace
*/
Rom_dataspace_capability cap() const { return _ds; }

/**
* Request local address
*
* This is a template to avoid inconvenient casts at
* the caller. A newly allocated ROM dataspace is
* untyped memory anyway.
*/
template <typename T>
T *local_addr() { return static_cast<T *>(_local_addr); }

/**
* Return size
*/
size_t size() const { return _size; }
};
}

#endif /* _INCLUDE__OS__ATTACHED_ROM_DATASPACE_H_ */

0 comments on commit 8495a5f

Please sign in to comment.