/******************************************************/
/* Copyright (C) 2008 Arch Rock Corporation           */
/* License Agreement: refer to LICENSE.txt            */
/*                                                    */
/******************************************************/
  
#ifndef _SVCS_H
#define _SVCS_H   1

#include <platform.h>
#include <event.h>

/*! Kernel services. */
enum SystemSvcsEnum{
  /*! Reboot Control. Execute directly. No callback is required.
   * Supported commands: START and STOP.
   */
  REBOOT_CNTL=1,
  /*! CPU Sleep Control. Execute directly. No callback is required.
   * Supported commands: START and STOP. 
   */
  CPUPOWER_CNTL,
  /*! Route Control to configure if the node should be a router or
   *  just a host which does not route traffic from other nodes.
   *  Execute directly. No callback is required.
   *  Supported commands: HOST and ROUTER.
   */
  ROUTESVC_CNTL,
  /*! Software Update control. Not supported.
   *  Potential commands: PROBE_UPDATE, DOWNLOAD_UPDATE, and REPROGRAM.
   */
  SWUPDATE_CNTL,
  CNTL_COUNT,

  /*! \note The following notifications will use the \em subtype field
   *  in event_t. 
  */
  /*! Reboot Notification.  Bind callback handler to kernel when started.
   *  Handler will be fired before node goes to reboot. Stopping the 
   *  service removes the handler binding.
   *  Supported commands: START and STOP.
   */
  REBOOT_NOTIFY,
  /*! Route Changes Notification.  Bind callback handler to kernel 
   *  when started. Handler will be fire whenver route
   *  changes.  The nature of the change is stored in \em flags field 
   *  in event_t with values defined in #RouteFlagsEnum.
   *  Stopping the service removes the handler binding.
   *  Supported commands: START and STOP.
   */
  ROUTESVC_NOTIFY,
  /*! Software Update service.  Not supported.
   *  Supported commands: PROBE_UPDATE, DOWNLOAD_UPDATE, REPROGRAM,
   */
  SWUPDATE_NOTIFY,
  NOTIFY_COUNT,
};

/*! Kernel service commands
 *  
 */
enum SvcCmdsEnum{
  START=10,
  STOP,
};

/*! Router service commands */
enum RouterSvcCmdsEnum{
  HOST=20,
  ROUTER,
};

enum RouteFlagsEnum{
  /*! Node has joined a 6LoWPAN Mesh Network. */
  F_NETWORK_JOINED = 1, 
  /*! Node has is not connected to a 6LoWPAN Mesh Network */
  F_LEFT_NETWORK,
};

/*! Software Update command Enum
*/
enum SwUpdateCmdsEnum{
  DOWNLOAD_UPDATE=50,
  PROBE_UPDATE,
  REPROGRAM,
};
/*! Reboot Service flags in event_t 
 *  on the callback notification.
 */
enum RebootFlagsEnum{
  F_REBOOT_BY_GW=0x1,
  F_REPROGRAM_BY_GW,
};

/*! Invoke kernel services or listen for kernel notifications.
 *
 *  @param[in] svc_enum kernel service enumeration name.
 *                     See #SystemSvcsEnum.
 *  @param[in] cmd commands to invoke the service
 *  @param[in] svc_handler the continuation callback handler
 *             for notification. If NULL is passed here, 
 *             the call will fail unless \em cmd is for control
 *             and does not require notification.
 *  @param[in] resource no requirement here.
 *  @param[in] context user context
 *  \return 0 if succeed or -1 if fail and errno is set appropriately.
 *  \par Errors:
 *    EBUSY if the underlying system is busy
 *  \par
 *    EINVAL if invalid parameters are passed
 *
 *  \section handler Callback Descriptions
 *  \subsection svc_handler svc_handler
 *     @param[in] event type is SVCCNTL in #EventsEnum.
 *                      subtype is set to \em cmd.
 *                      flags field may contain extra information,
 *                       depending on nature of the \em cmd.
 *     @param[in] cbargs return \em resource in svncntl()
 *     @param[in] context return \em context in svncntl()
 *  \return None.
 */
int16_t svccntl(int16_t svc_enum,
		uint16_t cmd,
		void (*svc_handler)(event_t event,
				    void *cbargs,
				    void *context), 
		void * resource,
		void * context);


#endif //_SVCS_H
