]> rtime.felk.cvut.cz Git - frescor/frsh.git/commitdiff
Added FRES error contrants and functions
authorMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 24 Oct 2008 18:37:07 +0000 (20:37 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 24 Oct 2008 18:37:07 +0000 (20:37 +0200)
fres/contract/Makefile.omk
fres/contract/fres_error.c [new file with mode: 0644]
fres/contract/fres_error.h [new file with mode: 0644]
fres/fcb.idl [deleted file]
frsh_api/frsh_core.c
frsh_api/frsh_error.c [new file with mode: 0644]
frsh_api/frsh_opaque_types.h

index d86d16d1e374adf2551f293a282345ae431cbf16..1a8a1908175722b728df03778c4c6bb6c097055a 100644 (file)
@@ -1,6 +1,6 @@
 shared_LIBRARIES = contract
 
-contract_SOURCES = fres_contract.c fres_container.c
+contract_SOURCES = fres_contract.c fres_container.c fres_error.c
 contract_CLIENT_IDL = fres_contract_idl.idl fres_blocks.idl
 
 fres_contract_idl_IDLFLAGS = --include=fres_contract_type.h
@@ -8,7 +8,7 @@ fres_blocks_IDLFLAGS = --include=idl_native.h
 
 include_HEADERS = fres_container.h fres_container_type.h               \
                  fres_contract_type.h fres_container_internal.h        \
-                 idl_native.h fres_contract.h
+                 idl_native.h fres_contract.h fres_error.h
 
 include_GEN_HEADERS = fres_contract_idl.h fres_blocks.h
 
diff --git a/fres/contract/fres_error.c b/fres/contract/fres_error.c
new file mode 100644 (file)
index 0000000..ec46763
--- /dev/null
@@ -0,0 +1,106 @@
+// -----------------------------------------------------------------------
+//  Copyright (C) 2006 - 2008 FRESCOR consortium partners:
+//
+//    Universidad de Cantabria,              SPAIN
+//    University of York,                    UK
+//    Scuola Superiore Sant'Anna,            ITALY
+//    Kaiserslautern University,             GERMANY
+//    Univ. Politécnica  Valencia,           SPAIN
+//    Czech Technical University in Prague,  CZECH REPUBLIC
+//    ENEA                                   SWEDEN
+//    Thales Communication S.A.              FRANCE
+//    Visual Tools S.A.                      SPAIN
+//    Rapita Systems Ltd                     UK
+//    Evidence                               ITALY
+//
+//    See http://www.frescor.org for a link to partners' websites
+//
+//           FRESCOR project (FP6/2005/IST/5-034026) is funded
+//        in part by the European Union Sixth Framework Programme
+//        The European Union is not liable of any use that may be
+//        made of this code.
+//
+//
+//  based on previous work (FSF) done in the FIRST project
+//
+//   Copyright (C) 2005  Mälardalen University, SWEDEN
+//                       Scuola Superiore S.Anna, ITALY
+//                       Universidad de Cantabria, SPAIN
+//                       University of York, UK
+//
+//   FSF API web pages: http://marte.unican.es/fsf/docs
+//                      http://shark.sssup.it/contrib/first/docs/
+//
+//   This file is part of FRSH (FRescor ScHeduler)
+//
+//  FRSH is free software; you can redistribute it and/or modify it
+//  under terms of the GNU General Public License as published by the
+//  Free Software Foundation; either version 2, or (at your option) any
+//  later version.  FRSH is distributed in the hope that it will be
+//  useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+//  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+//  General Public License for more details. You should have received a
+//  copy of the GNU General Public License along with FRSH; see file
+//  COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+//  Cambridge, MA 02139, USA.
+//
+//  As a special exception, including FRSH header files in a file,
+//  instantiating FRSH generics or templates, or linking other files
+//  with FRSH objects to produce an executable application, does not
+//  by itself cause the resulting executable application to be covered
+//  by the GNU General Public License. This exception does not
+//  however invalidate any other reasons why the executable file might be
+//  covered by the GNU Public License.
+// -----------------------------------------------------------------------
+//==============================================
+//  ******** *******    ********  **      **
+//  **///// /**////**  **//////  /**     /**
+//  **      /**   /** /**        /**     /**
+//  ******* /*******  /********* /**********
+//  **////  /**///**  ////////** /**//////**
+//  **      /**  //**        /** /**     /**
+//  **      /**   //** ********  /**     /**
+//  //       //     // ////////   //      // 
+//
+// FRSH(FRescor ScHeduler), pronounced "fresh"
+//==============================================
+
+#include <string.h>
+#include "fres_error.h"
+#include <frsh_error.h>
+
+/**
+ *  fres_strerror()
+ *
+ *  This function converts an error code to an error message that is
+ *  stored in the buffer starting at the location pointed to by
+ *  message. The size of this buffer is specified by the size
+ *  argument. If the error message is longer than size-1, it is
+ *  truncated to that length. Regardless of whether the message is
+ *  truncated or not, a final zero character that marks the end of the
+ *  string is stored in the buffer.  The function fails if the error
+ *  code passed does not correspond to any of the fres error codes.
+ *   [@return:
+ *    FRSH_ERR_BAD_ARGUMENT :  error is not a valid value
+ *   ]
+ **/
+int fres_strerror (int error, char *message, size_t size)
+{
+       char *s = NULL;
+       enum fres_error e = error;
+
+#define MSG(error) case FRES_ERR_##error: s = #error; break
+
+       switch (e) {
+               MSG(FCB_NOT_RUNNING);
+       }
+
+       if (s == NULL) return FRSH_ERR_BAD_ARGUMENT;
+
+       if (message != NULL && size > 0) {
+               strncpy(message, s, size);
+               message[size-1] = '\0';
+       }
+
+       return 0;
+}
diff --git a/fres/contract/fres_error.h b/fres/contract/fres_error.h
new file mode 100644 (file)
index 0000000..e128042
--- /dev/null
@@ -0,0 +1,13 @@
+#ifndef FRES_ERROR_H
+#define FRES_ERROR_H
+
+#define FRES_ERR_BASE_VALUE                      0x02008000
+
+enum fres_error {
+       FRES_ERR_FCB_NOT_RUNNING = FRES_ERR_BASE_VALUE,
+};
+
+int fres_strerror (int error, char *message, size_t size);
+
+
+#endif
diff --git a/fres/fcb.idl b/fres/fcb.idl
deleted file mode 100644 (file)
index 2f65ac2..0000000
+++ /dev/null
@@ -1,111 +0,0 @@
-////////////////////////////////////////////////////////////////////////////
-// ---------------------------------------------------------------------- //
-// Copyright (C) 2006 - 2008 FRESCOR consortium partners:                //
-//                                                                       //
-//   Universidad de Cantabria,              SPAIN                        //
-//   University of York,                    UK                           //
-//   Scuola Superiore Sant'Anna,            ITALY                        //
-//   Kaiserslautern University,             GERMANY                      //
-//   Univ. Politécnica  Valencia,           SPAIN                       //
-//   Czech Technical University in Prague,  CZECH REPUBLIC               //
-//   ENEA                                   SWEDEN                       //
-//   Thales Communication S.A.              FRANCE                       //
-//   Visual Tools S.A.                      SPAIN                        //
-//   Rapita Systems Ltd                     UK                           //
-//   Evidence                               ITALY                        //
-//                                                                       //
-//   See http://www.frescor.org for a link to partners' websites         //
-//                                                                       //
-//          FRESCOR project (FP6/2005/IST/5-034026) is funded            //
-//       in part by the European Union Sixth Framework Programme         //
-//       The European Union is not liable of any use that may be         //
-//       made of this code.                                              //
-//                                                                       //
-//                                                                       //
-// based on previous work (FSF) done in the FIRST project                //
-//                                                                       //
-//  Copyright (C) 2005  Mälardalen University, SWEDEN                   //
-//                      Scuola Superiore S.Anna, ITALY                   //
-//                      Universidad de Cantabria, SPAIN                          //
-//                      University of York, UK                           //
-//                                                                       //
-//  FSF API web pages: http:marte.unican.es/fsf/docs                     //
-//                     http:shark.sssup.it/contrib/first/docs/           //
-//                                                                       //
-//  This file is part of FORB (Frescor Object Request Broker)            //
-//                                                                       //
-// FORB is free software; you can redistribute it and/or modify it       //
-// under terms of the GNU General Public License as published by the     //
-// Free Software Foundation; either version 2, or (at your option) any   //
-// later version.  FORB is distributed in the hope that it will be       //
-// useful, but WITHOUT ANY WARRANTY; without even the implied warranty   //
-// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU   //
-// General Public License for more details. You should have received a   //
-// copy of the GNU General Public License along with FORB; see file      //
-// COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,  //
-// Cambridge, MA 02139, USA.                                             //
-//                                                                       //
-// As a special exception, including FORB header files in a file,        //
-// instantiating FORB generics or templates, or linking other files      //
-// with FORB objects to produce an executable application, does not      //
-// by itself cause the resulting executable application to be covered    //
-// by the GNU General Public License. This exception does not            //
-// however invalidate any other reasons why the executable file might be  //
-// covered by the GNU Public License.                                    //
-////////////////////////////////////////////////////////////////////////////
-
-#ifndef _CM_IDL
-#define _CM_IDL
-
-#include "contract/fres_contract_idl.idl"
-#include "contract/fres_blocks.idl"
-#include "frm.idl"
-#include "frs.idl"
-
-module fres {
-       interface contract_broker {
-               const string reg_name = "fcb";
-               /** 
-                * Registers a resource manager with the contract broker
-                * 
-                * @param restype 
-                * @param resid 
-                * @param rm_obj 
-                * 
-                * @return Zero on success, non-zero error code on error.
-                */
-               long register_manager(in frsh_resource_type_t restype,
-                                     in frsh_resource_id_t   resid,
-                                     in resource_manager     rm_obj);
-
-               /** 
-                * Registers a resource scheduler with the contract broker
-                * 
-                * @param restype 
-                * @param resid 
-                * @param rs_obj 
-                * 
-                * @return Zero on success, non-zero error code on error.
-                */
-               long register_scheduler(in frsh_resource_type_t restype,
-                                       in frsh_resource_id_t   resid,
-                                       in resource_scheduler   rs_obj);
-               
-
-               /** 
-                * Tries to negotiate a contract 
-                * 
-                * @param[in] contract Contract to negotiate
-                * 
-                * @param[out] id Global ID of the contract if
-                * negotiation was successful.
-                * 
-                * @return Zero if the contract was successfully
-                * negotiated, non-zero code on error or when
-                * negotiation failed.
-                */
-               long negotiate_contract(in contract::ptr contract, out fres::contract::id_t id);
-       };
-};
-
-#endif
index 661657640f2223b237fc443268d06e9e13f169bb..0fef9f43ff43cc666c339459e5caea402d46901b 100644 (file)
@@ -15,7 +15,8 @@ int frsh_init()
 
        global.fcb = forb_resolve_reference(global.orb,
                                            fres_contract_broker_reg_name);
-       if (!global.fcb) return FRSH_ERR_NOT_INITIALIZED;
+       if (!global.fcb) return FRES_ERR_FCB_NOT_RUNNING;
 
        return 0;
 }
+
diff --git a/frsh_api/frsh_error.c b/frsh_api/frsh_error.c
new file mode 100644 (file)
index 0000000..6c0072c
--- /dev/null
@@ -0,0 +1,184 @@
+// -----------------------------------------------------------------------
+//  Copyright (C) 2006 - 2008 FRESCOR consortium partners:
+//
+//    Universidad de Cantabria,              SPAIN
+//    University of York,                    UK
+//    Scuola Superiore Sant'Anna,            ITALY
+//    Kaiserslautern University,             GERMANY
+//    Univ. Politécnica  Valencia,           SPAIN
+//    Czech Technical University in Prague,  CZECH REPUBLIC
+//    ENEA                                   SWEDEN
+//    Thales Communication S.A.              FRANCE
+//    Visual Tools S.A.                      SPAIN
+//    Rapita Systems Ltd                     UK
+//    Evidence                               ITALY
+//
+//    See http://www.frescor.org for a link to partners' websites
+//
+//           FRESCOR project (FP6/2005/IST/5-034026) is funded
+//        in part by the European Union Sixth Framework Programme
+//        The European Union is not liable of any use that may be
+//        made of this code.
+//
+//
+//  based on previous work (FSF) done in the FIRST project
+//
+//   Copyright (C) 2005  Mälardalen University, SWEDEN
+//                       Scuola Superiore S.Anna, ITALY
+//                       Universidad de Cantabria, SPAIN
+//                       University of York, UK
+//
+//   FSF API web pages: http://marte.unican.es/fsf/docs
+//                      http://shark.sssup.it/contrib/first/docs/
+//
+//   This file is part of FRSH (FRescor ScHeduler)
+//
+//  FRSH is free software; you can redistribute it and/or modify it
+//  under terms of the GNU General Public License as published by the
+//  Free Software Foundation; either version 2, or (at your option) any
+//  later version.  FRSH is distributed in the hope that it will be
+//  useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+//  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+//  General Public License for more details. You should have received a
+//  copy of the GNU General Public License along with FRSH; see file
+//  COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+//  Cambridge, MA 02139, USA.
+//
+//  As a special exception, including FRSH header files in a file,
+//  instantiating FRSH generics or templates, or linking other files
+//  with FRSH objects to produce an executable application, does not
+//  by itself cause the resulting executable application to be covered
+//  by the GNU General Public License. This exception does not
+//  however invalidate any other reasons why the executable file might be
+//  covered by the GNU Public License.
+// -----------------------------------------------------------------------
+//==============================================
+//  ******** *******    ********  **      **
+//  **///// /**////**  **//////  /**     /**
+//  **      /**   /** /**        /**     /**
+//  ******* /*******  /********* /**********
+//  **////  /**///**  ////////** /**//////**
+//  **      /**  //**        /** /**     /**
+//  **      /**   //** ********  /**     /**
+//  //       //     // ////////   //      // 
+//
+// FRSH(FRescor ScHeduler), pronounced "fresh"
+//==============================================
+
+#include <stdio.h>
+#include <string.h>
+
+#include <frsh.h>
+#include <fres_error.h>
+
+
+////////////////////////////////////////////////////////////////////////
+//           ERROR REPORTING
+////////////////////////////////////////////////////////////////////////
+
+/* Use to debug an error condition */
+/***********************************/
+int global_error_condition = 0;
+
+
+
+/* These variables get initialised in frsh_init() */
+/**************************************************/
+fosa_abs_time_t frsh_trace_init_timespec;
+long frsh_trace_init_timemsec = -1;
+
+
+//error codes to message section
+static const int frsh_strerror_table_size = FRSH_ERR_LAST_VALUE-FRSH_ERR_BASE_VALUE;
+static char * frsh_strerror_table[] = 
+{
+    "TOO_MANY_TASKS                 ",
+    "BAD_ARGUMENT                   ",
+    "INVALID_SYNCH_OBJ_HANDLE       ",
+    "NO_RENEGOTIATION_REQUESTED     ",
+    "CONTRACT_REJECTED              ",
+    "NOT_SCHEDULED_CALLING_THREAD   ",
+    "NOT_BOUND_THREAD               ",
+    "UNKNOWN_SCHEDULED_THREAD       ",
+    "NOT_CONTRACTED_SERVER          ",
+    "NOT_SCHEDULED_THREAD           ",
+    "TOO_MANY_SERVICE_JOBS          ",
+    "TOO_MANY_SYNCH_OBJS            ",
+    "TOO_MANY_SERVERS_IN_SYNCH_OBJ  ",
+    "TOO_MANY_EVENTS_IN_SYNCH_OBJ   ",
+    "INTERNAL_ERROR                 ",
+    "TOO_MANY_SERVERS               ",
+    "INVALID_SCHEDULER_REPLY        ",
+    "TOO_MANY_PENDING_REPLENISHMENTS",
+    "SYSTEM_ALREADY_INITIALIZED     ",
+    "SHARED_OBJ_ALREADY_INITIALIZED ",
+    "SHARED_OBJ_NOT_INITIALIZED     ",
+    "SCHED_POLICY_NOT_COMPATIBLE    ",
+    "SERVER_WORKLOAD_NOT_COMPATIBLE ",
+    "ALREADY_BOUND                  ",
+    "WRONG_NETWORK                  ",
+    "TOO_LARGE                      ",
+    "BUFFER_FULL                    ",
+    "NO_SPACE                       ",
+    "NO_MESSAGES                    ",
+    "MODULE_NOT_SUPPORTED           ",
+    "SYSTEM_NOT_INITIALIZED         ",
+    "TOO_MANY_SHARED_OBJS           ",
+    "CONTRACT_LABEL_ALREADY_EXISTS  ",
+    "BUDGET_EXPIRED                 ",
+    "SHARED_OBJECT_NOT_PROTECTED    ",
+    "NOT_IMPLEMENTED                ",
+    "CONTRACT_TYPE_NOT_COMPATIBLE   ",
+    "CAPACITY_NOT_DECREASING        ",
+    "CONTRACT_LABEL_UNKNOWN         "
+};
+
+
+
+/**
+ *  frsh_strerror()
+ *
+ *  This function converts an error code to an error message that is
+ *  stored in the buffer starting at the location pointed to by
+ *  message. The size of this buffer is specified by the size
+ *  argument. If the error message is longer than size-1, it is
+ *  truncated to that length. Regardless of whether the message is
+ *  truncated or not, a final zero character that marks the end of the
+ *  string is stored in the buffer.  The function fails if the error
+ *  code passed does not correspond to any of the frsh error codes.
+ *   [@return:
+ *    FRSH_ERR_BAD_ARGUMENT :  error is not a valid value
+ *   ]
+ **/
+int frsh_strerror (int error, char *message, size_t size)
+{
+    char *s;
+    int ret;
+
+    ret = fres_strerror(error, message, size);
+    if (ret == 0) return 0;
+    
+    if ((error > FRSH_ERR_LAST_VALUE) ||
+        (error <= FRSH_ERR_BASE_VALUE))
+        return FRSH_ERR_BAD_ARGUMENT;
+  
+    s = frsh_strerror_table[error - FRSH_ERR_BASE_VALUE -1];
+    if ( message != NULL && size > 0) {
+        strncpy(message, s, size);
+        message[size-1] = '\0';
+    }
+    return 0;
+}
+
+/* ------------------------------------------------------------------------------------ */
+void my_frsh_strerror(int error, char *sss)
+{
+    char       s[32];
+    frsh_strerror(error, s, 32);
+    printf("(%x ", error);
+    printf(s);
+    printf(") ");
+    printf(sss);
+}
index 79094ea9999662fe94763f1b4031212f0c7a763a..23c03340785c2e559d402dcb79692c17cd8e61f5 100644 (file)
@@ -73,6 +73,7 @@
 #include <fres_contract_type.h>
 #include <frsh_cpp_macros.h>
 #include <fres_contract_idl.h>
+#include <fres_error.h>
 
 FRSH_CPP_BEGIN_DECLS