home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / samples / som / somd / cpp / event / eventcom.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-01-24  |  5.8 KB  |  158 lines

  1. //
  2. //   COMPONENT_NAME: somx
  3. //
  4. //   ORIGINS: 27
  5. //
  6. //
  7. //   10H9767, 10H9769  (C) COPYRIGHT International Business Machines Corp. 1992,1994
  8. //   All Rights Reserved
  9. //   Licensed Materials - Property of IBM
  10. //   US Government Users Restricted Rights - Use, duplication or
  11. //   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  12. //
  13.  
  14.  
  15. /* %Z% %I% %W% %G% %U% [%H% %T%] */
  16. /*
  17.  *
  18.  * DISCLAIMER OF WARRANTIES.
  19.  * The following [enclosed] code is sample code created by IBM
  20.  * Corporation. This sample code is not part of any standard or IBM
  21.  * product and is provided to you solely for the purpose of assisting
  22.  * you in the development of your applications.  The code is provided
  23.  * "AS IS". IBM MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT
  24.  * NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  25.  * FOR A PARTICULAR PURPOSE, REGARDING THE FUNCTION OR PERFORMANCE OF
  26.  * THIS CODE.  IBM shall not be liable for any damages arising out of
  27.  * your use of the sample code, even if they have been advised of the
  28.  * possibility of such damages.
  29.  *
  30.  * DISTRIBUTION.
  31.  * This sample code can be freely distributed, copied, altered, and
  32.  * incorporated into other software, provided that it bears the above
  33.  * Copyright notice and DISCLAIMER intact.
  34.  */
  35.  
  36.  
  37. #include <stdlib.h>
  38. #include <stdio.h>
  39. #include <string.h>
  40.  
  41. #define SOM_Module_eventcom_Source
  42. #include <somd.xh>
  43. #include "eventcom.xih"
  44.  
  45. boolean   has_event = FALSE;
  46. any       event_data = {NULL, (void *)0};
  47.  
  48. SOM_Scope void  SOMLINK EventComm_EventConnectiondisconnect(EventComm_EventConnection *somSelf, Environment *ev)
  49. {
  50.     /* EventComm_EventConnectionData *somThis = EventComm_EventConnectionGetData(somSelf); */
  51.  
  52.     EventComm_EventConnectionMethodDebug("EventComm_EventConnection","EventComm_EventConnectiondisconnect");
  53.  
  54.     somSelf->somFree();
  55. }
  56.  
  57.  
  58. SOM_Scope void  SOMLINK EventComm_Consumerpush(EventComm_Consumer *somSelf, Environment *ev, any *ev_data)
  59. {
  60. /*    EventComm_ConsumerData *somThis = EventComm_ConsumerGetData(somSelf); */
  61.     Disconnected   *discon;
  62.  
  63.     EventComm_ConsumerMethodDebug("EventComm_Consumer","EventComm_Consumerpush");
  64.  
  65.     /*
  66.      * Check to see whether the consumer_element struct containing "EventConnection"
  67.      * interface exists for this Supplier
  68.      */
  69.  
  70.     if (somSelf->_get_ev_con(ev) != (EventComm_EventConnection *)0) {
  71.         TypeCode_free(event_data._type, ev);
  72.         has_event = TRUE;
  73.         event_data._type = ev_data->_type;
  74.         event_data._value = ev_data->_value;
  75.     }
  76.     else { /* invoke exception handling  */
  77.         discon = (Disconnected *)SOMMalloc(sizeof(Disconnected));
  78.         discon->ErrCode = 9999;
  79.         strcpy(discon->Reason, "Not connected to the event channel\n");
  80.         somSetException(ev, USER_EXCEPTION, ex_Disconnected, (void *)discon);
  81.     }
  82. }
  83.  
  84. SOM_Scope void  SOMLINK EventComm_Consumerdisconnect(EventComm_Consumer *somSelf, Environment *ev)
  85. {
  86. /*    EventComm_ConsumerData *somThis = EventComm_ConsumerGetData(somSelf); */
  87.     Disconnected   *discon;
  88.     EventComm_EventConnection  *evcon;
  89.  
  90.     EventComm_ConsumerMethodDebug("EventComm_Consumer","EventComm_Consumerdisconnect");
  91.     evcon = somSelf->_get_ev_con(ev);
  92.     if (evcon != (EventComm_EventConnection *) 0) {
  93.         evcon->disconnect(ev);
  94.         somSelf->_set_ev_con(ev, (EventComm_EventConnection *)0);
  95.     }
  96.     else {
  97.         discon = (Disconnected *)SOMMalloc(sizeof(Disconnected));
  98.         discon->ErrCode = 9999;
  99.         strcpy(discon->Reason, "Not connected to the event channel\n");
  100.         somSetException(ev, USER_EXCEPTION, ex_Disconnected, (void *)discon);
  101.     }
  102. }
  103.  
  104.  
  105. SOM_Scope boolean SOMLINK EventComm_Suppliertry_pull(EventComm_Supplier *somSelf,
  106.                                                    Environment *ev,
  107.                                                    any* event)
  108. {
  109. /*    EventComm_SupplierData *somThis = EventComm_SupplierGetData(somSelf); */
  110.     Disconnected   *discon;
  111.     boolean        have_event = FALSE;
  112.     EventComm_SupplierMethodDebug("EventComm_Supplier","EventComm_Suppliertry_pull");
  113.  
  114.     /*
  115.      * Check to see whether the supplier_element struct containing "EventConnection"
  116.      * interface exists for this Consumer
  117.      */
  118.     if (somSelf->_get_ev_con(ev) != (EventComm_EventConnection *)0) {
  119.             if (has_event) {
  120.                 have_event = TRUE;
  121.                 has_event = FALSE;
  122.             }
  123.             else
  124.                 if (event_data._type == NULL) {
  125.                     event_data._type = TC_long;
  126.                     event_data._value = (long *) 0;
  127.                 }
  128.         }
  129.     else { /* eventconnection missing; invoke exception handling  */
  130.         discon = (Disconnected *)SOMMalloc(sizeof(Disconnected));
  131.         discon->ErrCode = 9999;
  132.         strcpy(discon->Reason, "Not connected to the event channel\n");
  133.         somSetException(ev, USER_EXCEPTION, ex_Disconnected, (void *)discon);
  134.     }
  135.     *event = event_data;
  136.     return (have_event);
  137. }
  138.  
  139. SOM_Scope void  SOMLINK EventComm_Supplierdisconnect(EventComm_Supplier *somSelf, Environment *ev)
  140. {
  141. /*    EventComm_SupplierData *somThis = EventComm_SupplierGetData(somSelf); */
  142.     Disconnected   *discon;
  143.     EventComm_EventConnection  *evcon;
  144.  
  145.     EventComm_SupplierMethodDebug("EventComm_Supplier","EventComm_Supplierdisconnect");
  146.     evcon = somSelf->_get_ev_con(ev);
  147.     if (evcon != (EventComm_EventConnection *)0) {
  148.         evcon->disconnect(ev);
  149.         somSelf->_set_ev_con(ev, (EventComm_EventConnection *)0);
  150.     }
  151.     else {
  152.         discon = (Disconnected *)SOMMalloc(sizeof(Disconnected));
  153.         discon->ErrCode = 9999;
  154.         strcpy(discon->Reason, "Not connected to the event channel\n");
  155.         somSetException(ev, USER_EXCEPTION, ex_Disconnected, (void *)discon);
  156.     }
  157. }
  158.