00001 // 00002 // actmsg.h 00003 // 00004 // based on: memamsg.h 00005 // 00006 // Copyright (C) 1996 Limit Point Systems, Inc. 00007 // 00008 // Author: Curtis Janssen <cljanss@limitpt.com> 00009 // Maintainer: LPS 00010 // 00011 // This file is part of the SC Toolkit. 00012 // 00013 // The SC Toolkit is free software; you can redistribute it and/or modify 00014 // it under the terms of the GNU Library General Public License as published by 00015 // the Free Software Foundation; either version 2, or (at your option) 00016 // any later version. 00017 // 00018 // The SC Toolkit is distributed in the hope that it will be useful, 00019 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00020 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00021 // GNU Library General Public License for more details. 00022 // 00023 // You should have received a copy of the GNU Library General Public License 00024 // along with the SC Toolkit; see the file COPYING.LIB. If not, write to 00025 // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 00026 // 00027 // The U.S. Government is granted a limited license as per AL 91-7. 00028 // 00029 00030 #ifdef __GNUC__ 00031 #pragma interface 00032 #endif 00033 00034 #ifndef _util_group_actmsg_h 00035 #define _util_group_actmsg_h 00036 00037 #include <iostream> 00038 00039 #include <util/group/thread.h> 00040 #include <util/group/memmsg.h> 00041 #include <util/group/mstate.h> 00042 00043 namespace sc { 00044 00045 class ActiveMessageGrp; 00046 00050 class ActiveMessage: virtual public SavableState { 00051 public: 00052 ActiveMessage() {} 00053 ActiveMessage(StateIn &s): SavableState(s) {} 00054 void save_data_state(StateOut &) {} 00057 virtual void run(int sender, int type, ActiveMessageGrp *context) = 0; 00058 }; 00059 00062 class ActiveMessageEcho: public ActiveMessage { 00063 int i_; 00064 public: 00065 ActiveMessageEcho(StateIn &); 00066 ActiveMessageEcho(int i): i_(i) {} 00067 void save_data_state(StateOut &); 00068 void run(int sender, int type, ActiveMessageGrp *context); 00069 }; 00070 00073 class ActiveMessageThread: public Thread { 00074 private: 00075 ActiveMessageGrp *context_; 00076 Ref<StateRecv> in_; 00077 unsigned int nreq_recd_; 00078 public: 00079 ActiveMessageThread(const Ref<StateRecv> &, 00080 ActiveMessageGrp *context); 00081 void run(); 00082 int run_one(); 00083 unsigned int nreq_recd() { return nreq_recd_; } 00084 void set_nreq_recd(unsigned int val) { nreq_recd_ = val; } 00085 }; 00086 00091 class ActiveMessageGrp : public DescribedClass { 00092 protected: 00093 int active_; 00094 unsigned int *nreq_sent_; 00095 ActiveMessageThread **thread_; 00096 00097 int statesend_type_; 00098 00099 Ref<MessageGrp> msg_; 00100 Ref<ThreadGrp> thr_; 00101 00102 void init(const Ref<MessageGrp>& msg, 00103 const Ref<ThreadGrp>& thr); 00104 00105 public: 00107 ActiveMessageGrp(const Ref<MessageGrp>& msg, const Ref<ThreadGrp>& thr); 00109 ActiveMessageGrp(const Ref<KeyVal>&); 00110 ~ActiveMessageGrp(); 00111 00114 Ref<StateSend> get_statesend(); 00115 00119 void send(int node, 00120 const Ref<StateSend> &, 00121 const Ref<ActiveMessage> &); 00122 00125 void activate(); 00129 void deactivate(); 00131 void sync(); 00132 00134 Ref<MessageGrp> messagegrp() { return msg_; } 00135 00137 int n() const { return msg_->n(); } 00139 int me() const { return msg_->me(); } 00140 }; 00141 00142 } 00143 00144 #endif 00145 00146 // Local Variables: 00147 // mode: c++ 00148 // c-file-style: "CLJ" 00149 // End: