]> rtime.felk.cvut.cz Git - frescor/frsh.git/blobdiff - fres/cbroker/fcb.c
forb: executable resources and fcb changed into dynamic libs
[frescor/frsh.git] / fres / cbroker / fcb.c
index bbc8690084eee2c2b26e9283b1b4f93a4adccd96..f931d2eb4573fe4aa0eec574baf91772f455ed1d 100644 (file)
@@ -892,6 +892,16 @@ fcb_remember_schedulable_contracts(struct fcb *fcb,
        return 0;
 }
 
+static int
+reject_transactions(struct fcb_contract *fcb_contracts[], int num)
+{
+       int i;
+       for (i = 0; i < num; i++) {
+               if (fcb_contracts[i]->transaction)
+                       return FRES_ERR_VRES_PART_OF_TRANSACTION;
+       }
+       return 0;
+}
 
 CORBA_long
 negotiate_contracts(fres_contract_broker obj,
@@ -930,6 +940,10 @@ negotiate_contracts(fres_contract_broker obj,
                                    contracts->_buffer, num);
        if (ret)
                goto err_free_fcb_contracts;
+
+       ret = reject_transactions(fcb_contracts, num);
+       if (ret)
+               goto err_free_fcb_contracts;
        ret = check_and_setup_resource(fcb, fcb_contracts, &resource,
                                       &app, num);
        if (ret)
@@ -1257,6 +1271,13 @@ negotiate_transaction(fres_contract_broker _obj,
                fcb_remember_schedulable_contracts(fcb, schedulable_contracts);
                forb_sequence_free(schedulable_contracts, fres_contract_ptr_destroy);
        }
+       /* TODO: After we distinguish between APP and a real
+        * allocator, allocate VRESes (and perform mode change) here.
+        * Only if the resource allocator is not known at this point,
+        * wait with allocation the same way as it is done now. For
+        * this we will need more information about allocators i.e.
+        * its type (centralized, distributed, in app, ...). Too
+        * compilcated ;-( */
 
        ft = fcb_transaction_new(transaction->name);
        if (!ft) {
@@ -1344,6 +1365,11 @@ allocate_transaction_vres(fres_contract_broker _obj,
        fc = tran_contract_indx2item(ft, index);
        if (!fc) GOTO(err, FRSH_ERR_TOO_LARGE);
 
+       /* TODO: If we allow migration of task between resources (due
+        * to spare capacity reallocation), the following check will
+        * need reworking/enhancing. */
+       if (fc->ra) GOTO(err, FRES_ERR_VRES_ALREADY_ALLOCATED);
+
        if (!get_fc_res_key(fc, &key))
                GOTO(err, FRSH_ERR_RESOURCE_ID_INVALID);
        resource = fcb_resource_find(fcb, &key);
@@ -1443,7 +1469,6 @@ void peer_dead_callback(const forb_orb peer_orb, const char *orb_id)
 }
 
 static struct option long_opts[] = {
-    { "daemon",   optional_argument, NULL, 'd' },
     { "loglevel", required_argument, NULL, 'l' },
     { 0, 0, 0, 0}
 };
@@ -1452,7 +1477,6 @@ static void
 usage(void)
 {
        printf("usage: fcb [ options ]\n");
-       printf("  -d, --daemon [pid-file]   go to background after FORB initialization\n");
        printf("  -l, --loglevel <number>|<domain>=<number>,...\n");
 }
 
@@ -1462,9 +1486,8 @@ int print_log_domain(ul_log_domain_t *domain, void *context)
        return 0;
 }
 
-int main(int argc, char *argv[])
+int forb_main(forb_orb orb, int argc, char *argv[])
 {
-       forb_orb orb;
        struct fcb fcb_data;
        fres_contract_broker fcb;
        forb_executor_t executor;
@@ -1481,7 +1504,7 @@ int main(int argc, char *argv[])
        };
        int  opt;
 
-       while ((opt = getopt_long(argc, argv, "d::l:", &long_opts[0], NULL)) != EOF) {
+       while ((opt = getopt_long(argc, argv, "hl:", &long_opts[0], NULL)) != EOF) {
                switch (opt) {
                        case 'l':
                                if (*optarg == '?') {
@@ -1495,10 +1518,6 @@ int main(int argc, char *argv[])
                                                error(1, EINVAL, "Error parsing -l argument at char %d\n", ret);
                                }
                                break;
-                       case 'd':
-                               opt_daemon = true;
-                               opt_pidfile = optarg;
-                               break;
                        case 'h':
                        /*default:*/
                                usage();
@@ -1512,9 +1531,6 @@ int main(int argc, char *argv[])
        if (opt_daemon)
                forb_daemon_prepare(opt_pidfile);
 
-       orb = forb_init(&argc, &argv, &attr);
-       if (!orb) error(1, errno, "FORB initialization failed");
-
 #if CONFIG_FCB_INET && !CONFIG_FORB_PROTO_INET_DEFAULT
        ret = register_inet_port(orb);
        if (ret) error(0, errno, "INET port registration failed");