"Fossies" - the Fresh Open Source Software Archive

Member "Pansophica-src-1.3/BAF/endo/baf_ipc/baf_ipc.c" (1 Feb 2008, 3669 Bytes) of package /linux/www/old/Pansophica-src-1.3-1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "baf_ipc.c" see the Fossies "Dox" file reference documentation.

    1 /******************************************************************************
    2 
    3  Pansophica, An intelligent, virtual-reality, web search agent
    4  Copyright (C) MMVIII, NeuralVR Technologies Ltd.
    5 
    6  This program is free software: you can redistribute it and/or modify
    7  it under the terms of the GNU General Public License as published by
    8  the Free Software Foundation, either version 3 of the License, or
    9  (at your option) any later version.
   10 
   11  This program is distributed in the hope that it will be useful,
   12  but WITHOUT ANY WARRANTY; without even the implied warranty of
   13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   14  GNU General Public License for more details.
   15 
   16  You should have received a copy of the GNU General Public License
   17  along with this program.  If not, see http://www.gnu.org/licenses/.
   18 
   19  MODULE: baf_ipc.c
   20  $Id: baf_ipc.c,v 1.11 2008/02/01 18:03:33 dean Exp $
   21  
   22  SYNOPSIS
   23  API replacement for sysv IPC
   24 
   25  HISTORY
   26  $Log: baf_ipc.c,v $
   27  Revision 1.11  2008/02/01 18:03:33  dean
   28  first GPL version, mac ready
   29 
   30  Revision 1.10  2005/02/04 04:58:22  dean
   31  everything for cygwin build
   32 
   33  Revision 1.9  2003/11/16 21:38:13  dean
   34  compiling, not linking
   35 
   36  Revision 1.8  2003/11/13 20:17:24  dean
   37  removal of generic macros in favour of 'baf_' prefixed macros
   38 
   39  Revision 1.7  2003/11/10 18:00:53  dean
   40  running with new MPI
   41 
   42  Revision 1.6  2003/11/10 06:00:24  dean
   43  a bit closer
   44 
   45  Revision 1.5  2003/11/07 22:32:00  dean
   46  building and linking with new mpi
   47 
   48  Revision 1.4  2003/11/07 21:07:14  dean
   49  added the qs to the build
   50 
   51  Revision 1.3  2003/11/07 05:09:42  dean
   52  incremental qs work
   53 
   54  Revision 1.2  2003/11/06 23:43:12  dean
   55  incremental work
   56 
   57  Revision 1.1  2003/11/06 23:21:49  dean
   58  sysv ipc compatibility layer start
   59 
   60 
   61 
   62 ******************************************************************************/
   63 
   64 #include <stdio.h>
   65 #include <string.h>
   66 #include "util_mem.h"
   67 #include "util_debug.h"
   68 #include "util_qs.h"
   69 #include "baf_ipc.h"
   70 
   71 UTIL_QS_REF g_baf_ipc_qs = NULL;
   72 
   73 /* : all messages are of this form, this is clumsy but akin to posix MPI  */
   74 typedef struct {
   75   long mtype;
   76   void *data;
   77 } BAF_IPC_MSG_BUF;
   78 
   79 int baf_ipc_msgget( int key, int flag )
   80 {
   81   int retval = -1;
   82 
   83   if ( g_baf_ipc_qs == NULL ) {
   84     /* : this should be guarded by critical section if multi-thread create */
   85     BAF_CATCH( util_qs_create( &g_baf_ipc_qs ) ) {
   86       MSG(PUBLIC,"%s\n","can't create q's");
   87       return -1;
   88     }
   89   }
   90   
   91   BAF_CATCH( util_qs_take( g_baf_ipc_qs, &retval ) ) {
   92     MSG(PUBLIC,"%s\n","can't get queue");
   93     return -1;
   94   }
   95 
   96   return retval;
   97 }
   98 
   99 int baf_ipc_msgsnd( int msgqid, void *msgp, size_t msgsz, int msgflag )
  100 {
  101   BAF_IPC_MSG_BUF *msgbuf = (BAF_IPC_MSG_BUF *)msgp;
  102 
  103   BAF_CATCH( util_qs_push( g_baf_ipc_qs, msgqid, (int)(msgbuf->mtype), msgbuf->data, (int)msgsz ) ) {
  104     BAF_THROW_MSG("can't msgsnd");
  105   }
  106 
  107   return 0;
  108 }
  109 
  110 size_t baf_ipc_msgrcv( int msgqid, void *msgp, size_t msgsz, long msgtype, int msgflag )
  111 {
  112   BAF_IPC_MSG_BUF *msgbuf = (BAF_IPC_MSG_BUF *)msgp;
  113   void *obuf = NULL;
  114   int otype = 0;
  115   int osize = 0;
  116 
  117   BAF_CATCH( util_qs_pop( g_baf_ipc_qs, msgqid, (int)msgtype, &otype, &obuf, &osize ) ) {
  118     /* likely an empty queue */
  119     return -1;
  120   }
  121 
  122   msgbuf->mtype = otype;
  123   msgbuf->data = obuf;
  124 
  125   return 0;
  126 }
  127 
  128 int baf_ipc_msgctl( int msgqid, int cmd, void *buf )
  129 {
  130   if ( g_baf_ipc_qs == NULL ) return 0;
  131 
  132   BAF_CATCH( util_qs_give( g_baf_ipc_qs, msgqid ) ) {
  133     BAF_THROW_MSG("can't give queue");
  134   }
  135   
  136   /* this should be guarded with critical section if multi-thread cleanup */
  137   BAF_CATCH( util_qs_check_count_and_destroy( &g_baf_ipc_qs ) ) {
  138     BAF_THROW_MSG("can't check and destroy queues");
  139   }
  140 
  141   return 0;
  142 }