/*
 * Copyright (c) 2012-2015 LAAS/CNRS
 * All rights reserved.
 *
 * Permission to use, copy, modify, and distribute this software for any purpose
 * with or without   fee is hereby granted, provided   that the above  copyright
 * notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
 * REGARD TO THIS  SOFTWARE INCLUDING ALL  IMPLIED WARRANTIES OF MERCHANTABILITY
 * AND FITNESS. IN NO EVENT SHALL THE AUTHOR  BE LIABLE FOR ANY SPECIAL, DIRECT,
 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR  ANY DAMAGES WHATSOEVER RESULTING  FROM
 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
 * OTHER TORTIOUS ACTION,   ARISING OUT OF OR IN    CONNECTION WITH THE USE   OR
 * PERFORMANCE OF THIS SOFTWARE.
 *
 *                                             Anthony Mallet on Thu May 24 2012
 */

interface genom {
  /* standard exceptions */

  exception incompatible_digest {
    struct client_digest { string<32> version; string<32> date; } client;
    struct server_digest { string<32> version; string<32> date; } server;
  };
  throw incompatible_digest;

  exception bad_transition { string<128> from, to; };
  throw bad_transition;

  exception interrupted { string<128> by; };
  throw interrupted;

  exception serialization, too_many_activities, disallowed;
  throw serialization, too_many_activities, disallowed;

  exception no_such_inport, no_such_outport, port_io;
  exception no_such_remote, no_such_service, remote_io;
  exception no_such_activity;

  exception mwerr { string<256> what; };
  throw mwerr;


  /* standard "state" port */
  module state {
    struct stats {
      float last, max, avg;
    };

    struct rusage {
      unsigned long cycles;
      stats timings;
      stats load;
    };

    struct activity {
      unsigned long id;
      string<64> name;
    };

    struct task {
      string<64> name;
      rusage rusage;
      sequence<activity> activity;
    };

    struct component {
      sequence<task> task;

      string<33> digest;
      string<31> date;
      string<32> version;
    };
  };

  port out state::component genom_state;


  /* standard services */

  function abort_activity(in unsigned long activity =	: "Activity id") {
    doc "Abort an activity";

    codel genom_abort_activity_codel(local in activity);

    throw no_such_activity;
  };

  function
  connect_port(in string<128> local =	:"Local input port",
               in string<128> remote =	:"Output port to connect to")
  {
    doc "Connect two ports";
    codel genom_connect_port_codel(local in local, local in remote);

    throw no_such_inport, no_such_outport, port_io;
  };

  function
  connect_service(in string<128> local =	:"Local service name",
                  in string<128> remote =	:"Remote service name")
  {
    doc "Connect to a remote service";
    codel genom_connect_remote_codel(local in local, local in remote);

    throw no_such_remote, no_such_service, remote_io;
  };

  function
  kill()
  {
    doc "Terminate all activities and quit";
    codel genom_kill_codel();
    interrupt all;
  };
};

#pragma provides genom
