1 #include <../../nrnconf.h> 14 #if defined(HAVE_SSTREAM) // the standard ... 36 bool todo_less_than(
const WorkItem*)
const;
40 bool operator() (
const char* s1,
const char* s2)
const {
41 return strcmp(s1, s2) < 0;
46 bool operator() (
int i,
int j)
const {
52 bool operator() (
const WorkItem* w1,
const WorkItem* w2)
const {
53 return w1->todo_less_than(w2);
57 static char* newstr(
const char*
s) {
58 char* s1 =
new char[strlen(s) + 1];
66 printf(
"WorkItem %d\n",
id);
74 WorkItem::~WorkItem() {
81 bool WorkItem::todo_less_than(
const WorkItem* w)
const {
82 WorkItem* w1 = (WorkItem*)
this;
83 WorkItem* w2 = (WorkItem*)w;
84 while (w1->parent_ != w2->parent_) {
85 if (w1->id_ < w2->id_) {
92 printf(
"todo_less_than %d < %d return %d\n", this->
id_, w->id_, w1->id_ < w2->id_);
94 return w1->id_ < w2->id_;
97 class MessageList :
public std::multimap <const char*, const MessageValue*, ltstr>{};
99 class ReadyList :
public std::set<WorkItem*, ltWorkItem>{};
100 class ResultList:
public std::multimap<int, const WorkItem*, ltint>{};
108 hoc_execerror(
"BBSLocalServer not working",
"Compiled without STL");
139 for (mi = first_; mi; mi =
next) {
179 m->
u.
pd =
new double[
n];
180 for (i=0; i <
n; ++
i) {
189 m->
u.
s =
new char[strlen(str)+1];
197 m->
u.
s =
new char[
n];
199 memcpy(m->
u.
s, bytes, n);
204 if (!unpack_ || unpack_->type_ !=
INT) {
208 unpack_ = unpack_->next_;
213 if (!unpack_ || unpack_->type_ !=
DOUBLE) {
217 unpack_ = unpack_->next_;
223 if (!unpack_ || unpack_->type_ !=
VECTOR) {
226 for (i = 0; i <
n; ++
i) {
227 d[
i] = unpack_->u.pd[
i];
229 unpack_ = unpack_->next_;
234 if (!unpack_ || unpack_->type_ !=
STRING) {
237 strcpy(s, unpack_->u.s);
238 unpack_ = unpack_->next_;
243 if (!unpack_ || unpack_->type_ !=
PICKLE) {
247 memcpy(s, unpack_->u.s, *n);
248 unpack_ = unpack_->next_;
253 #if defined(HAVE_STL) 263 #if defined(HAVE_STL) 267 printf(
"~BBSLocalServer not deleting everything\n");
275 #if defined(HAVE_STL) 276 MessageList::iterator m = messages_->find(key);
277 if (m != messages_->end()) {
279 char*
s = (
char*)((*m).first);
283 printf(
"srvr_look_take |%s|\n", key);
288 printf(
"fail srvr_look_take |%s|\n", key);
297 #if defined(HAVE_STL) 298 MessageList::iterator m = messages_->find(key);
299 if (m != messages_->end()) {
303 printf(
"srvr_look true |%s|\n", key);
310 printf(
"srvr_look false |%s|\n", key);
319 #if defined(HAVE_STL) 320 MessageList::iterator m = messages_->insert(
321 std::pair<const char* const, const MessageValue*>(newstr(key),val)
325 printf(
"srvr_post |%s|\n", key);
333 #if defined(HAVE_STL) 334 WorkItem* w =
new WorkItem(next_id_++, val);
335 WorkList::iterator
p = work_->find(parentid);
336 if (p != work_->end()) {
337 w->parent_ = (WorkItem*)((*p).second);
339 work_->insert(std::pair<const int, const WorkItem*>(w->id_, w));
342 printf(
"srvr_post_todo id=%d pid=%d\n", w->id_, parentid);
350 #if defined(HAVE_STL) 351 WorkList::iterator
i = work_->find(
id);
352 WorkItem* w = (WorkItem*)((*i).second);
356 results_->insert(std::pair<const int, const WorkItem*>(w->parent_ ? w->parent_->id_ : 0, w));
358 printf(
"srvr_post_done id=%d pid=%d\n",
id, w->parent_ ? w->parent_->id_ : 0);
364 #if defined(HAVE_STL) 365 ReadyList::iterator
i = todo_->begin();
366 if (i != todo_->end()) {
371 printf(
"srvr look_take_todo %d\n", w->id_);
377 printf(
"srvr look_take_todo failed\n");
388 #if defined(HAVE_STL) 389 ResultList::iterator
i = results_->find(pid);
390 if (i != results_->end()) {
391 WorkItem* w = (WorkItem*)((*i).second);
396 WorkList::iterator
j = work_->find(
id);
399 printf(
"srvr look_take_result %d for parent %d\n", w->id_, pid);
405 printf(
"srvr look_take_result failed for parent %d\n", pid);
int look_take_result(int pid, MessageValue **)
int look_take_todo(MessageValue **)
void post_todo(int parentid, MessageValue *)
virtual ~BBSLocalServer()
static double map(void *v)
void hoc_execerror(const char *, const char *)
int const size_t const size_t n
bool look(const char *key, MessageValue **)
bool look_take(const char *key, MessageValue **)
void post_result(int id, MessageValue *)
int pkpickle(const char *, size_t)
void post(const char *key, MessageValue *)
int upkpickle(char *, size_t *)
int upkvec(int, double *)