[0b990d] | 1 | //
|
---|
| 2 | // messproc.cc
|
---|
| 3 | //
|
---|
| 4 | // Copyright (C) 1996 Limit Point Systems, Inc.
|
---|
| 5 | //
|
---|
| 6 | // Author: Curtis Janssen <cljanss@limitpt.com>
|
---|
| 7 | // Maintainer: LPS
|
---|
| 8 | //
|
---|
| 9 | // This file is part of the SC Toolkit.
|
---|
| 10 | //
|
---|
| 11 | // The SC Toolkit is free software; you can redistribute it and/or modify
|
---|
| 12 | // it under the terms of the GNU Library General Public License as published by
|
---|
| 13 | // the Free Software Foundation; either version 2, or (at your option)
|
---|
| 14 | // any later version.
|
---|
| 15 | //
|
---|
| 16 | // The SC Toolkit is distributed in the hope that it will be useful,
|
---|
| 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 19 | // GNU Library General Public License for more details.
|
---|
| 20 | //
|
---|
| 21 | // You should have received a copy of the GNU Library General Public License
|
---|
| 22 | // along with the SC Toolkit; see the file COPYING.LIB. If not, write to
|
---|
| 23 | // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 24 | //
|
---|
| 25 | // The U.S. Government is granted a limited license as per AL 91-7.
|
---|
| 26 | //
|
---|
| 27 |
|
---|
| 28 | #include <util/misc/formio.h>
|
---|
| 29 | #include <util/group/message.h>
|
---|
| 30 |
|
---|
| 31 | using namespace sc;
|
---|
| 32 |
|
---|
| 33 | static ClassDesc ProcMessageGrp_cd(
|
---|
| 34 | typeid(ProcMessageGrp),"ProcMessageGrp",1,"public MessageGrp",
|
---|
| 35 | 0, create<ProcMessageGrp>, 0);
|
---|
| 36 |
|
---|
| 37 | ProcMessageGrp::ProcMessageGrp(const Ref<KeyVal>& keyval):
|
---|
| 38 | MessageGrp(keyval)
|
---|
| 39 | {
|
---|
| 40 | sync_messages=0;
|
---|
| 41 | type_messages=0;
|
---|
| 42 | initialize(0,1);
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | ProcMessageGrp::ProcMessageGrp()
|
---|
| 46 | {
|
---|
| 47 | sync_messages=0;
|
---|
| 48 | type_messages=0;
|
---|
| 49 | initialize(0,1);
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | ProcMessageGrp::~ProcMessageGrp()
|
---|
| 53 | {
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | Ref<MessageGrp> ProcMessageGrp::clone(void)
|
---|
| 57 | {
|
---|
| 58 | Ref<MessageGrp> pmg = new ProcMessageGrp;
|
---|
| 59 | return pmg;
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | void ProcMessageGrp::sendit(message_t *& messages, int dest, int msgtype, const void* buf,
|
---|
| 63 | int bytes)
|
---|
| 64 | {
|
---|
| 65 | message_t *msg;
|
---|
| 66 | message_t *I;
|
---|
| 67 |
|
---|
| 68 | if (dest != 0) {
|
---|
| 69 | ExEnv::errn() << scprintf("messproc.cc:sendit: can only send to 0\n");
|
---|
| 70 | abort();
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | msg = (message_t *) malloc(sizeof(message_t));
|
---|
| 74 | if (msg) msg->buf = (char *) malloc(bytes);
|
---|
| 75 | if (!msg || !msg->buf) {
|
---|
| 76 | ExEnv::errn() << scprintf("messproc.cc:sendit: allocation failed\n");
|
---|
| 77 | abort();
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | // Put msg at the end of the linked list, because of some bad
|
---|
| 81 | // assumptions made by the mpscf program and libraries.
|
---|
| 82 | msg->p = 0;
|
---|
| 83 | if (!messages) {
|
---|
| 84 | messages = msg;
|
---|
| 85 | }
|
---|
| 86 | else {
|
---|
| 87 | for (I=messages; I->p != 0; I=I->p);
|
---|
| 88 | I->p = msg;
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | memcpy(msg->buf,buf,bytes);
|
---|
| 92 | msg->type = msgtype;
|
---|
| 93 | msg->size = bytes;
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | void ProcMessageGrp::recvit(message_t *& messages, int source, int type, void* buf,
|
---|
| 97 | int bytes, int& last_size, int& last_type)
|
---|
| 98 | {
|
---|
| 99 | message_t *i;
|
---|
| 100 | message_t *last;
|
---|
| 101 |
|
---|
| 102 | last = 0;
|
---|
| 103 | for (i=messages; i!=0; i = i->p) {
|
---|
| 104 | if (i->type == type || type == -1) {
|
---|
| 105 | if (i->size > bytes) {
|
---|
| 106 | ExEnv::errn() << scprintf(
|
---|
| 107 | "messproc.cc:recvit: message buffer isn't big enough\n");
|
---|
| 108 | abort();
|
---|
| 109 | }
|
---|
| 110 | memcpy(buf,i->buf,i->size);
|
---|
| 111 |
|
---|
| 112 | // Remove the message from the list.
|
---|
| 113 | if (last) {
|
---|
| 114 | last->p = i->p;
|
---|
| 115 | }
|
---|
| 116 | else {
|
---|
| 117 | messages = messages->p;
|
---|
| 118 | }
|
---|
| 119 | free(i->buf);
|
---|
| 120 | free(i);
|
---|
| 121 |
|
---|
| 122 | return;
|
---|
| 123 | }
|
---|
| 124 | last = i;
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 | ExEnv::errn() << scprintf(
|
---|
| 128 | "messproc.cc:recvit: tried to receive something that isn't there\n");
|
---|
| 129 | ExEnv::errn() << scprintf("messproc:recvit: tried %d bytes of type %d, ",bytes,type);
|
---|
| 130 | abort();
|
---|
| 131 | }
|
---|
| 132 |
|
---|
| 133 | void
|
---|
| 134 | ProcMessageGrp::raw_send(int target, const void* data, int nbyte)
|
---|
| 135 | {
|
---|
| 136 | sendit(sync_messages, target, -1, data, nbyte);
|
---|
| 137 | }
|
---|
| 138 |
|
---|
| 139 | void
|
---|
| 140 | ProcMessageGrp::raw_sendt(int target, int type, const void* data, int nbyte)
|
---|
| 141 | {
|
---|
| 142 | sendit(type_messages, target, type, data, nbyte);
|
---|
| 143 | }
|
---|
| 144 |
|
---|
| 145 | void
|
---|
| 146 | ProcMessageGrp::raw_recv(int sender, void* data, int nbyte)
|
---|
| 147 | {
|
---|
| 148 | int last_size, last_type;
|
---|
| 149 | recvit(sync_messages, sender, -1, data, nbyte, last_size, last_type);
|
---|
| 150 | }
|
---|
| 151 |
|
---|
| 152 | void
|
---|
| 153 | ProcMessageGrp::raw_recvt(int type, void* data, int nbyte)
|
---|
| 154 | {
|
---|
| 155 | int last_size, last_type;
|
---|
| 156 | recvit(type_messages, -1, type, data, nbyte, last_size, last_type);
|
---|
| 157 | }
|
---|
| 158 |
|
---|
| 159 | void
|
---|
| 160 | ProcMessageGrp::raw_bcast(void* data, int nbyte, int from)
|
---|
| 161 | {
|
---|
| 162 | }
|
---|
| 163 |
|
---|
| 164 | int
|
---|
| 165 | ProcMessageGrp::probet(int type)
|
---|
| 166 | {
|
---|
| 167 | message_t *i;
|
---|
| 168 |
|
---|
| 169 | for (i=type_messages; i!=0; i = i->p) {
|
---|
| 170 | if (i->type == type || type == -1) {
|
---|
| 171 | return 1;
|
---|
| 172 | }
|
---|
| 173 | }
|
---|
| 174 |
|
---|
| 175 | return 0;
|
---|
| 176 | }
|
---|
| 177 |
|
---|
| 178 | void
|
---|
| 179 | ProcMessageGrp::sync()
|
---|
| 180 | {
|
---|
| 181 | }
|
---|
| 182 |
|
---|
| 183 | /////////////////////////////////////////////////////////////////////////////
|
---|
| 184 |
|
---|
| 185 | // Local Variables:
|
---|
| 186 | // mode: c++
|
---|
| 187 | // c-file-style: "CLJ"
|
---|
| 188 | // End:
|
---|