1  /*
   2   * \brief  Parent interface
   3   * \author Norman Feske
   4   * \date   2006-05-10
   5   */

   6  
   7  /*
   8   * Copyright (C) 2006-2010 Genode Labs GmbH
   9   *
  10   * This file is part of the Genode OS framework, which is distributed
  11   * under the terms of the GNU General Public License version 2.
  12   */

  13  
  14  #ifndef _INCLUDE__PARENT__PARENT_H_
  15  #define _INCLUDE__PARENT__PARENT_H_
  16  
  17  #include <base/exception.h>
  18  #include <session/capability.h>
  19  #include <root/capability.h>
  20  
  21  namespace Genode {
  22  
  23     class Parent
  24     {
  25        public:
  26  
  27           enum { MSGBUF_SIZE = 256 };
  28  
  29  
  30           /*********************
  31            ** Exception types **
  32            *********************/

  33  
  34           class Exception      public ::Genode::Exception { };
  35           class Service_denied public Exception { };
  36           class Quota_exceeded public Exception { };
  37           class Unavailable    public Exception { };

  38  
  39        protected:
  40  
  41           enum Opcode { EXIT, ANNOUNCE, SESSION, TRANSFER_QUOTA, CLOSE };

  42  
  43        public:
  44  
  45           virtual ~Parent() { }
  46  
  47           /**
  48            * Tell parent to exit the program
  49            */

  50           virtual void exit(int exit_value) = 0;

  51  
  52           /**
  53            * Announce service to the parent
  54            */

  55           virtual int announce(const char *service_name,
  56                                Root_capability service_root)
 = 0;

  57  
  58           /**
  59            * Create session to a service
  60            *
  61            * \param service_name     name of the requested interface
  62            * \param args             session constructor arguments
  63            *
  64            * \throw Service_denied   parent denies session request
  65            * \throw Quota_exceeded   our own quota does not suffice for
  66            *                         the creation of the new session
  67            *
  68            * \return                 capability to new session
  69            *
  70            * By convention, an argument value for `ram_quota` must be
  71            * specified in `args`. The specified amount of RAM will be
  72            * donated to the session-providing service.
  73            */

  74           virtual Session_capability session(const char *service_name,
  75                                              const char *args)
 = 0;

  76  
  77           /**
  78            * Transfer our quota to the server that provides the specified session
  79            *
  80            * \param to_session      recipient session
  81            * \param amount          description of the amount of quota to transfer
  82            *
  83            * \throw Quota_exceeded  quota could not be transferred
  84            *
  85            * The `amount` argument has the same principle format as the `args`
  86            * argument of the `session` function.
  87            * The error case indicates that there is not enough unused quota on
  88            * the source side.
  89            */

  90           virtual void transfer_quota(Session_capability to_session,
  91                                       const char *amount)
 = 0;

  92  
  93           /**
  94            * Close session
  95            */

  96           virtual void close(Session_capability session) = 0;

  97     }
;

  98  }

  99  
 100  #endif /* _INCLUDE__PARENT__PARENT_H_ */