- Main Page
- Namespaces
- Classes
- Files

- Search for |

# recv.cpp

    00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
    00002
    00003 // "recv.cpp"
    00004
    00005 // (c) OPAC Team, LIFL, August 2005
    00006
    00007 /* This library is free software; you can redistribute it and/or
    00008    modify it under the terms of the GNU Lesser General Public
    00009    License as published by the Free Software Foundation; either
    00010    version 2 of the License, or (at your option) any later version.
    00011
    00012    This library is distributed in the hope that it will be useful,
    00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
    00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00015    Lesser General Public License for more details.
    00016
    00017    You should have received a copy of the GNU Lesser General Public
    00018    License along with this library; if not, write to the Free Software
    00019    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
    00020
    00021    Contact: paradiseo-help@lists.gforge.inria.fr
    00022 */
    00023
    00024 #include "comm.h"
    00025 #include "tags.h"
    00026 #include "worker.h"
    00027 #include "scheduler.h"
    00028 #include "mess.h"
    00029 #include "node.h"
    00030 #include "../../core/runner.h"
    00031 #include "../../core/cooperative.h"
    00032 #include "../../core/peo_debug.h"
    00033
    00034 void receiveMessages () {
    00035
    00036   cleanBuffers ();
    00037
    00038   do {
    00039
    00040     if (! atLeastOneActiveThread ()) {
    00041       //      printDebugMessage ("debut wait");
    00042       waitMessage ();
    00043       //printDebugMessage ("fin wait");
    00044     }
    00045
    00046     int src, tag;
    00047
    00048     while (probeMessage (src, tag)) {
    00049
    00050       receiveMessage (src, tag);
    00051       initMessage ();
    00052       /*
    00053       char b [1000];
    00054       sprintf (b, "traitement recv %d\n", tag);
    00055       printDebugMessage (b);
    00056       */
    00057
    00058       switch (tag) {
    00059
    00060       case RUNNER_STOP_TAG:
    00061         unpackTerminationOfRunner ();
    00062         wakeUpCommunicator ();
    00063         break;
    00064
    00065       case COOP_TAG:
    00066         //      printDebugMessage ("reception de message de cooperation");
    00067         COOP_ID coop_id;
    00068         unpack (coop_id);
    00069         getCooperative (coop_id) -> unpack ();
    00070         break;
    00071
    00072       case SCHED_REQUEST_TAG:
    00073         unpackResourceRequest ();
    00074         break;
    00075
    00076       case SCHED_RESULT_TAG:
    00077         {
    00078           /* Unpacking the resource */
    00079           SERVICE_ID serv_id;
    00080           unpack (serv_id);
    00081           Service * serv = getService (serv_id);
    00082           int dest;
    00083           unpack (dest);
    00084           WORKER_ID worker_id;
    00085           unpack (worker_id);
    00086
    00087           /* Going back ... */
    00088           initMessage ();
    00089           pack (worker_id);
    00090           pack (serv_id);
    00091           serv -> packData ();
    00092           serv -> notifySendingData ();
    00093           sendMessage (dest, TASK_DATA_TAG);
    00094           break;
    00095         }
    00096
    00097       case TASK_DATA_TAG:
    00098       {
    00099         WORKER_ID worker_id;
    00100         unpack (worker_id);
    00101         Worker * worker = getWorker (worker_id);
    00102         worker -> setSource (src);
    00103         worker -> unpackData ();
    00104         worker -> wakeUp ();
    00105         break;
    00106       }
    00107
    00108       case TASK_RESULT_TAG:
    00109         {
    00110           SERVICE_ID serv_id;
    00111           unpack (serv_id);
    00112           Service * serv = getService (serv_id);
    00113           serv -> unpackResult ();
    00114           break;
    00115         }
    00116
    00117       case TASK_DONE_TAG:
    00118         unpackTaskDone ();
    00119         break;
    00120
    00121       default:
    00122         ;
    00123       };
    00124     }
    00125
    00126   } while (! atLeastOneActiveThread () && atLeastOneActiveRunner () /*&& ! allResourcesFree ()*/);
    00127 }