]> rtime.felk.cvut.cz Git - frescor/frsh.git/commitdiff
Added frsh_init(), frsh_negotiate_contract() and some fixes
authorMichal Sojka <sojkam1@fel.cvut.cz>
Wed, 22 Oct 2008 11:08:28 +0000 (13:08 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Wed, 22 Oct 2008 11:08:28 +0000 (13:08 +0200)
fres/sa/fres_sa_scenario.c
fres/sa/fres_sa_scenario.h
frsh_api/Makefile.omk
frsh_api/frsh_contract.c
frsh_api/frsh_core.c [new file with mode: 0644]
frsh_api/frsh_forb.h [new file with mode: 0644]
frsh_api/frsh_opaque_types.h
resources/dummy/Makefile.omk
resources/dummy/frm_dummy.c

index f418e59d3518325edc86c7308c91e888c41b30bc..9d79f5d677ff88b434830186261dc68fc8d996a4 100644 (file)
@@ -50,6 +50,15 @@ err:
 }
 
 
+GAVL_CUST_NODE_INT_DEC(fres_sa_scenario_contract /* cust_prefix */,
+                      struct fres_sa_scenario   /* cust_root_t */,
+                      struct fres_sa_contract   /* cust_item_t */,
+                      fres_contract_id_t        /* cust_key_t */,
+                      contracts                 /* cust_root_node */,
+                      node                      /* cust_item_node */,
+                      contract->id              /* cust_item_key */,
+                      fres_contract_id_cmp      /* cust_cmp_fnc */)
+
 GAVL_CUST_NODE_INT_IMP(fres_sa_scenario_contract /* cust_prefix */,
                       struct fres_sa_scenario   /* cust_root_t */,
                       struct fres_sa_contract   /* cust_item_t */,
@@ -126,14 +135,19 @@ err:
 }
 
 int fres_sa_scenario_del_contract(struct fres_sa_scenario *scenario,
-                                 fres_contract_id_t *id)
+                                 struct fres_sa_contract *c)
 {
-       struct fres_sa_contract *c;
-       c = fres_sa_scenario_contract_find(scenario, id);
-       if (c) {
+       if (scenario && c) {
                scenario->num_contracts--;
                fres_sa_scenario_contract_delete(scenario, c);
                return 1;
        }
        return 0;
 }
+
+struct fres_sa_contract *
+fres_sa_scenario_find_contract(struct fres_sa_scenario *scenario,
+                              fres_contract_id_t *id)
+{
+       return fres_sa_scenario_contract_find(scenario, id);
+}
index 70521312bc1609a9f1306cec892541e731aa2100..950a0e3c63c9bfd11c65ec201da3cf9794980da5 100644 (file)
@@ -27,16 +27,6 @@ struct fres_sa_scenario {
        void *priv;
 };
 
-
-GAVL_CUST_NODE_INT_DEC(fres_sa_scenario_contract /* cust_prefix */,
-                      struct fres_sa_scenario   /* cust_root_t */,
-                      struct fres_sa_contract   /* cust_item_t */,
-                      fres_contract_id_t        /* cust_key_t */,
-                      contracts                 /* cust_root_node */,
-                      node                      /* cust_item_node */,
-                      contract->id              /* cust_item_key */,
-                      fres_contract_id_cmp      /* cust_cmp_fnc */)
-
 struct fres_sa_contract *
 fres_sa_contract_new(void);
 
@@ -56,7 +46,12 @@ fres_sa_scenario_duplicate(struct fres_sa_scenario *scenario);
 
 int fres_sa_scenario_add_contract(struct fres_sa_scenario *scenario,
                                  struct fres_contract *contract);
-                                 
 
+int fres_sa_scenario_del_contract(struct fres_sa_scenario *scenario,
+                                 struct fres_sa_contract *contract);
+                                 
+struct fres_sa_contract *
+fres_sa_scenario_find_contract(struct fres_sa_scenario *scenario,
+                              fres_contract_id_t *id);
 
 #endif
index aa6b550274eafdb83cf8a513265ff3c4ac65f417..2977527f6fecfafe1d1f288df1b36a2e05280049 100644 (file)
@@ -1,5 +1,5 @@
 shared_LIBRARIES = frsh
-frsh_SOURCES = frsh_contract.c frsh_distributed.c
+frsh_SOURCES = frsh_contract.c frsh_distributed.c frsh_core.c
 include_HEADERS = frsh_opaque_types.h
 
 lib_LOADLIBES+= fna
index 45dfb5a600f240f1b3c8c1da6bde7067e801db04..4624404dd583eb61451b5c036bce2ffa1c29b713 100644 (file)
@@ -12,6 +12,8 @@
 #include <frsh_error.h>
 #include <fres_blocks.h>
 #include <string.h>
+#include <fcb.h>
+#include "frsh_forb.h"
 
 /**********************************/
 /* -----===== FRSH API =====----- */
@@ -134,3 +136,18 @@ int frsh_contract_set_timing_reqs
        }
        return 0;
 }
+
+int frsh_contract_negotiate
+  (const frsh_contract_t *contract,
+   frsh_vres_id_t        *vres)
+{
+       struct forb_env env;
+       int ret;
+       ret = fres_contract_broker_negotiate_contract(global.fcb,
+                                                     *contract,
+                                                     vres, &env);
+       if (forb_exception_occured(&env)) {
+               ret = FRSH_ERR_INTERNAL_ERROR;
+       }
+       return ret;
+}
diff --git a/frsh_api/frsh_core.c b/frsh_api/frsh_core.c
new file mode 100644 (file)
index 0000000..6616576
--- /dev/null
@@ -0,0 +1,21 @@
+#include <frsh_core.h>
+#include <fcb.h>
+#include <forb.h>
+#include "frsh_forb.h"
+
+struct frsh_forb global;
+
+int frsh_init()
+{
+       global.orb = forb_init(NULL, NULL, "frsh");
+       if (!global.orb) {
+               if (errno) return errno;
+               else return -1;
+       }
+
+       global.fcb = forb_resolve_reference(global.orb,
+                                           fres_contract_broker_reg_name);
+       if (!global.fcb) return FRSH_ERR_NOT_INITIALIZED;
+
+       return 0;
+}
diff --git a/frsh_api/frsh_forb.h b/frsh_api/frsh_forb.h
new file mode 100644 (file)
index 0000000..e54cdfa
--- /dev/null
@@ -0,0 +1,12 @@
+#ifndef FRSH_FORB_H
+#define FRSH_FORB_H
+
+struct frsh_forb {
+       forb_orb orb;
+       fres_contract_broker fcb;
+};
+
+extern struct frsh_forb global;
+
+
+#endif
index 53e7ce5a4f9048eebf7ca32c7517827d5ebeeafd..6d18323df4bb5822415b72411cd7c4d6baf55b08 100644 (file)
 // FRSH(FRescor ScHeduler), pronounced "fresh"
 //==============================================
 
-#ifdef FRSH_CORE_TYPES_H_
-#define frsh_vres_id_t frsh_vres_id_t_old
-#endif
-
 // Implementation dependent definitions
 #ifndef _FRSH_OPAQUE_TYPES_H_
 #define _FRSH_OPAQUE_TYPES_H_
 
 #include <fres_contract_type.h>
 #include <frsh_cpp_macros.h>
+#include <fres_contract_idl.h>
 
 FRSH_CPP_BEGIN_DECLS
 
@@ -98,6 +95,8 @@ FRSH_CPP_BEGIN_DECLS
  * @{
  **/
 
+#define FRSH_VRES_ID_T_OPAQUE fres_contract_id_t
+
 /** frsh_contract_parameters_t **/
 #define FRSH_CONTRACT_T_OPAQUE fres_contract_ptr
 
index d126dbf4730200fec672e95ef70e9d0860c12ec3..3f373edb9d47d0484afc21cbef09afb995528fc0 100644 (file)
@@ -2,7 +2,7 @@ bin_PROGRAMS = frm_dummy
 shared_LIBRARIES = frs_dummy
 
 frm_dummy_SOURCES = frm_dummy.c
-frm_dummy_LIBS = frm fres_sa forb contract fosa rt ulut
+frm_dummy_LIBS = frm fres_sa forb contract fosa rt ulut fcb_client
 
 frs_dummy_SOURCES = frs_dummy.c
 frs_dummy_LIBS = frs
index 5aaa31447ad654c27cdb1367cb743753e191d47a..4d75b278ef278996bf61a8b15acbb4ae4e79ab2c 100644 (file)
@@ -5,11 +5,17 @@
 #include <fres_sa_scenario.h>
 #include <stdbool.h>
 #include <fcb.h>
+#include <ul_log.h>
+
+UL_LOG_CUST(ulogd_frm_dummy);
+ul_log_domain_t ulogd_frm_dummy = {UL_LOGL_MSG, "frm_dummy"};
+
 
 bool admission_test(struct fres_sa_scenario *scenario)
 {
        bool schedulable;
 
+       ul_logmsg("Admission test");
        schedulable = scenario->num_contracts <= 3;
                
        return schedulable;
@@ -31,6 +37,8 @@ CORBA_long reserve_contracts(fres_resource_manager obj,
        struct fres_contract *c;
        bool schedulable;
        int i;
+
+       ul_logdeb("reserve_contracts\n");
        
        prospective = fres_sa_scenario_duplicate(frm->running);
        for (i=0; i<contracts->_length; i++) {
@@ -59,6 +67,8 @@ void commit_contracts(fres_resource_manager obj,
        struct fres_sa_contract *c;
        fres_contract_ptr_seq *contracts;
 
+       ul_logdeb("commit_contracts\n");
+
        contracts = forb_malloc(sizeof(*contracts));
        if (!contracts) {
                ev->major = FORB_EX_NO_MEMORY;
@@ -69,7 +79,7 @@ void commit_contracts(fres_resource_manager obj,
        contracts->_maximum = contracts->_length = num;
        
        for (i=0; i < num; i++) {
-               c = fres_sa_scenario_contract_find(frm->running, &ids->_buffer[i]);
+               c = fres_sa_scenario_find_contract(frm->running, &ids->_buffer[i]);
        }
        
        *contract_with_scheduler_data = contracts;
@@ -83,18 +93,20 @@ void cancel_contracts(fres_resource_manager obj,
        int i;
        struct frm_data *frm = object_to_frm(obj);
 
+       ul_logdeb("cancel_contracts\n");
+
        for (i=0; i<ids->_length; i++) {
                struct fres_sa_contract *c;
-               c = fres_sa_scenario_contract_find(frm->running, &ids->_buffer[i]);
+               c = fres_sa_scenario_find_contract(frm->running, &ids->_buffer[i]);
 
                if (c) {
-                       fres_sa_scenario_contract_delete(frm->running, c);
+                       fres_sa_scenario_del_contract(frm->running, c);
                }
        }
 }
 
 
-const struct forb_fres_resource_manager_impl impl = {
+const struct forb_fres_resource_manager_impl dummy_impl = {
        .reserve_contracts = reserve_contracts,
        .commit_contracts  = commit_contracts,
        .cancel_contracts  = cancel_contracts,
@@ -105,6 +117,7 @@ int main(int argc, char *argv[])
        forb_orb orb;
        fres_contract_broker fcb;
        fres_resource_manager frm;
+       struct forb_env env;
 
        struct frm_data dummy_data;
 
@@ -114,9 +127,12 @@ int main(int argc, char *argv[])
        fcb = forb_resolve_reference(orb, fres_contract_broker_reg_name);
        if (!fcb) error(1, 0, "Could not find contract broker");
 
-       frm = forb_fres_resource_manager_new(orb, &impl, &dummy_data);
+       frm = forb_fres_resource_manager_new(orb, &dummy_impl, &dummy_data);
        if (!frm) error(1, errno, "forb_fres_resource_manager_new");
 
+       fres_contract_broker_register_manager(fcb, FRSH_RT_PROCESSOR, 0,
+                                             frm, &env);
+
        forb_execute_object(frm);       
        
        return 0;