home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cset21v1.zip / IBMCPP / IBMCLASS / IDDECCNV.HPP < prev    next >
C/C++ Source or Header  |  1993-10-22  |  27KB  |  450 lines

  1. #ifndef _IDDECCNV_
  2. #define _IDDECCNV_
  3. /*******************************************************************************
  4. * FILE NAME: iddeccnv.hpp                                                      *
  5. *                                                                              *
  6. * DESCRIPTION:                                                                 *
  7. *   Declaration of the class(es):                                              *
  8. *     IDDEClientConversation - Defines a client DDE conversation.              *
  9. *                                                                              *
  10. *   NOTE:  IDDEActiveServer, IDDEActiveServerSet and IDDEClientHotLinkSet      *
  11. *          are defined in iddecset.hpp.                                        *
  12. *                                                                              *
  13. * COPYRIGHT:                                                                   *
  14. *   Licensed Materials - Property of IBM                                       *
  15. *   (C) Copyright IBM Corporation 1992, 1993                                   *
  16. *   All Rights Reserved                                                        *
  17. *   US Government Users Restricted Rights - Use, duplication, or disclosure    *
  18. *   restricted by GSA ADP Schedule Contract with IBM Corp.                     *
  19. *                                                                              *
  20. *******************************************************************************/
  21. #ifndef _ISTRING_
  22.   #include <istring.hpp>
  23. #endif
  24. #ifndef _IHANDLE_
  25.   #include <ihandle.hpp>
  26. #endif
  27. #ifndef _IHANDLER_
  28.   #include <ihandler.hpp>
  29. #endif
  30. #ifndef _IDDEEVT_
  31.   #include <iddeevt.hpp>
  32. #endif
  33.  
  34. /*----------------------------------------------------------------------------*/
  35. /* Align classes on four byte boundary.                                       */
  36. /*----------------------------------------------------------------------------*/
  37. #pragma pack(4)
  38.  
  39. // Forward declarations for other classes:
  40. class IObjectWindow;
  41. class IDDEClosedConversationSet;
  42. class IDDETransactionQueue;
  43. class IDDEActiveServerSet;
  44. class IDDEClientHotLinkSet;
  45. class IDDEFormatSet;
  46. class IThread;
  47.  
  48. class IDDEClientConversation : protected IHandler {
  49. typedef IHandler
  50.   Inherited;
  51. /*******************************************************************************
  52. * The IDDEClientConversation class adds dynamic data exchange (DDE) client     *
  53. * function to an application.                                                  *
  54. *                                                                              *
  55. * An instance of this class is created for each conversation an application    *
  56. * initiates with a server.  When a conversation with a server ends, the        *
  57. * IDDEClientConversation instance can initiate another conversation with that  *
  58. * server or any other server.  An instance of this class can find all topics   *
  59. * supported by all DDE server applications on the system.  All window, shared  *
  60. * memory, and atom table processing is managed by the class.                   *
  61. *                                                                              *
  62. * This class uses a window to communicate.  Therefore, window message          *
  63. * processing must occur.  This means that ICurrentThread::processMsgs must     *
  64. * be invoked.  There are several ways for this to occur.  Normally, this is    *
  65. * accomplished by invoking IApplication::current().run().                      *
  66. *                                                                              *
  67. * NOTE: Applications using this class must be compiled with the multithreaded  *
  68. *       library.                                                               *
  69. *                                                                              *
  70. * Example:                                                                     *
  71. *                                                                              *
  72. * This example creates an IDDEClientConversation subclass instance as          *
  73. * required to provide an implementation for the 'data()' callback function.    *
  74. *                                                                              *
  75. *   class MyConversation : public IDDEClientConversation {                     *
  76. *   public:                                                                    *
  77. *   virtual Boolean                                                            *
  78. *     data ( IDDEDataEvent& event )                                            *
  79. *     {                                                                        *
  80. *        IString item = event.item();                                          *
  81. *        IString format = event.format();                                      *
  82. *        Boolean bVal = validate(item, format);    // some function to         *
  83. *        if (bVal)                                 // ensure this is the       *
  84. *        {                                         // data we requested        *
  85. *           IString myData = event.data();                                     *
  86. *             //  do something with the requested data!                        *
  87. *           return true;                                                       *
  88. *        }                                                                     *
  89. *        return false;        // return false if data is not what              *
  90. *     }                       // was expected...                               *
  91. *   };  // MyConversation                                                      *
  92. *                                                                              *
  93. *   MyConversation* myConversation = new MYConversation();                     *
  94. *   if ( begin("Quote Server",          // requested application               *
  95. *              "Famous Quotes") )      // requested topic                      *
  96. *       myConversation->requestData("Albert Einstein");    // requested item   *
  97. *                                                                              *
  98. *******************************************************************************/
  99. public:
  100. /*------------------------ Constructors and Destructor -------------------------
  101. | There are two ways to construct instances of this class.  Both constructors  |
  102. | have an optional Boolean argument, useEventThread.  This argument is         |
  103. | optional, but also highly recommended if the application must do any         |
  104. | extensive processing, or intends to interact with the end user during any of |
  105. | the callback functions.  Specifying true allows IDDEClientConversation to    |
  106. | create a secondary thread to process incoming events. This prevents problems |
  107. | with window message processing since the thread is created without a message |
  108. | queue. If false is specified, no secondary thread will be created and care   |
  109. | must be taken to return promptly from all callback functions.                |
  110. |                                                                              |
  111. |  Default constructor   - This constructor initializes the instance, but does |
  112. |                          not start a conversation.                           |
  113. |                                                                              |
  114. |  Alternate constructor - This constructor takes the following arguments and  |
  115. |                          attempts to begin a conversation with the requested |
  116. |                          server application on the requested topic:          |
  117. |                            - The name of the server application with which   |
  118. |                              a conversation is desired.                      |
  119. |                            - The name of the topic about which a             |
  120. |                              conversation is desired.                        |
  121. ------------------------------------------------------------------------------*/
  122.   IDDEClientConversation  ( Boolean useEventThread = true );
  123.   IDDEClientConversation  ( const char* applicationName,
  124.                             const char* topicName,
  125.                             Boolean     useEventThread = true );
  126.  
  127. virtual
  128.   ~IDDEClientConversation ( );
  129.  
  130. /*------------------------- Initiation/Termination -----------------------------
  131. | Use the following functions to begin and end conversations:                  |
  132. |                                                                              |
  133. |   begin - Attempts to initiate a conversation with the requested server      |
  134. |           application on the requested topic.  The primary version of this   |
  135. |           overloaded function takes the name of the requested application    |
  136. |           and topic as input and returns true if the conversation is         |
  137. |           successfully begun; otherwise, it returns false.  The version      |
  138. |           that takes a server handle is provided along with the              |
  139. |           clientHandle function to allow an instance of this class to        |
  140. |           converse with a server without engaging in the normal conversation |
  141. |           initialization.                                                    |
  142. |   end   - Ends the current conversation.                                     |
  143. ------------------------------------------------------------------------------*/
  144. virtual Boolean
  145.   begin ( const char* applicationName,
  146.           const char* topicName );
  147.  
  148. virtual IDDEClientConversation
  149.  &begin ( const IWindowHandle& serverHandle ),
  150.  &end   ( );
  151.  
  152. /*------------------------------- Transactions ---------------------------------
  153. | Use the following functions to initiate transactions with the server.  Most  |
  154. | of the functions take a format string that identifies the format in which    |
  155. | the data is rendered.  The default is "#1" which specifies text format.      |
  156. | Formats are standardized by various vendors, who describe them in their      |
  157. | operating system or application documentation.                               |
  158. |                                                                              |
  159. |   requestData     - Requests the value of the item rendered in the specified |
  160. |                     format from the server.                                  |
  161. |   pokeData        - Requests the server to set the specified item to the     |
  162. |                     value of the data provided.                              |
  163. |   beginHotLink    - Requests the server to send a notification every time    |
  164. |                     the value of the item changes. If the sendData argument  |
  165. |                     is true, the data is sent with the notification in the   |
  166. |                     requested format. If the pacing argument is true, the    |
  167. |                     server is asked to wait for an acknowledgement from the  |
  168. |                     client before sending a subsequent notification.         |
  169. |   endHotLink      - Requests the server to end a hot link on the specified   |
  170. |                     item and format.                                         |
  171. |   endHotLinks     - Requests the server to end one or more hot links.  If    |
  172. |                     the item argument is specified, the server is requested  |
  173. |                     to end all hot links on the item in all formats. If no   |
  174. |                     arguments are provided, the server is requested to       |
  175. |                     end all hot links on all items in all formats.           |
  176. |   executeCommands - Requests the server to execute one or more commands.     |
  177. ------------------------------------------------------------------------------*/
  178. virtual IDDEClientConversation
  179.  &requestData     ( const char*   item,
  180.                     const char*   format = "#1" ),
  181.  &pokeData        ( const char*   item,
  182.                     const void*   data,
  183.                     unsigned long dataLength,
  184.                     const char*   format = "#1" ),
  185.  &beginHotLink    ( const char*   item,
  186.                     const char*   format = "#1",
  187.                     Boolean       sendData = true,
  188.                     Boolean       pacing = false ),
  189.  &endHotLink      ( const char*   item,
  190.                     const char*   format = "#1" ),
  191.  &endHotLinks     ( const char*   item = 0),
  192.  &executeCommands ( const void*   commands,
  193.                     unsigned long commandLength );
  194.  
  195. /*-------------------------------- Callbacks -----------------------------------
  196. | The following functions are called to provide information to the             |
  197. | application whenever the server sends information to the client conversation.|
  198. | To obtain information provided by any of the following functions, provide a  |
  199. | specialized implementation in the subclass.  All of the functions except for |
  200. | data have default behaviors, which is pure virtual and requires this         |
  201. | class to be subclassed.  If true is specified for the useEventThread         |
  202. | argument of the IDDEClientConversation constructor, all of these callbacks   |
  203. | will be invoked on a secondary thread:                                       |
  204. |                                                                              |
  205. |   data                - Provides data sent from the server.  The data can be |
  206. |                         from an active hot link or as the result of the      |
  207. |                         requestData function being invoked.  If the server   |
  208. |                         has requested an acknowledgement, the                |
  209. |                         IDDEClientConversation instance will use the return  |
  210. |                         value from this function to determine if it should   |
  211. |                         send a positive or negative acknowledgement.  If the |
  212. |                         data is for a valid item and in the correct format,  |
  213. |                         the function should return true; otherwise, false    |
  214. |                         should be returned.  This function is pure virtual   |
  215. |                         and must be overridden.                              |
  216. |   hotLinkInform       - Notifies the client that the value of an item in the |
  217. |                         server for which the client has a hot link has       |
  218. |                         changed.  If the server has requested an             |
  219. |                         acknowledgement, the IDDEClientConversation instance |
  220. |                         will use the return value from this function to      |
  221. |                         determine if it should send a positive or negative   |
  222. |                         acknowledgement.  If the client has an active hot    |
  223. |                         link for this item and has requested that only       |
  224. |                         notifications be sent, the function should return    |
  225. |                         true; otherwise, false should be returned.  The      |
  226. |                         default behavior is to return true.                  |
  227. |   acknowledged        - Provides generic acknowledgment from the server to   |
  228. |                         a client initiated transaction.  A positive          |
  229. |                         acknowledgement can be sent in response to a         |
  230. |                         beginHotLink or endHotLink function.  A negative     |
  231. |                         acknowledgement can be sent in response to the       |
  232. |                         same two functions, as well as to a requestData      |
  233. |                         function.                                            |
  234. |   executeAcknowledged - Returns positive or negative acknowledgement from    |
  235. |                         the server as the result of the executeCommands      |
  236. |                         function being invoked.                              |
  237. |   pokeAcknowledged    - Returns positive or negative acknowledgement from    |
  238. |                         the server as the result of the pokeData function    |
  239. |                         being invoked.                                       |
  240. |   conversationEnded   - Notifies the client that the conversation is ending  |
  241. |                         or ended.  The conversation end can be initiated by  |
  242. |                         either the client or the server, and can also be     |
  243. |                         caused by an error condition in the                  |
  244. |                         IDDEClientConversation.                              |
  245. ------------------------------------------------------------------------------*/
  246. virtual Boolean
  247.   data           ( IDDEDataEvent&          event) = 0,
  248.   hotLinkInform  ( IDDEClientHotLinkEvent& event);
  249.  
  250. virtual void
  251.   acknowledged        ( IDDEClientAcknowledgeEvent&  event ),
  252.   executeAcknowledged ( IDDEAcknowledgeExecuteEvent& event ),
  253.   pokeAcknowledged    ( IDDEAcknowledgePokeEvent&    event ),
  254.   conversationEnded   ( IDDEClientEndEvent&          event );
  255.  
  256. /*------------------------------- Accessors ------------------------------------
  257. | Use the following functions to get the accessible attributes                 |
  258. | of instances of this class:                                                  |
  259. |                                                                              |
  260. |   application                 - Returns the name of the server application   |
  261. |                                 with which the client is conversing.         |
  262. |   topic                       - Returns the name of the topic about which    |
  263. |                                 the client is conversing.                    |
  264. |   isCaseSensitive             - Returns true if the server has indicated it  |
  265. |                                 enforces case sensitivity.                   |
  266. |   inConversation              - Returns true if the client is currently in   |
  267. |                                 conversation with a server; otherwise, it    |
  268. |                                 returns false.                               |
  269. |   hotLinks                    - Adds all item and format pairs for which     |
  270. |                                 hot links have been established to the       |
  271. |                                 IDDEClientHotLinkSet passed in.              |
  272. |                                 NOTE: Include the iddecset.hpp header file   |
  273. |                                       when you use this function.            |
  274. |   hotLinkCount                - Returns a count of the number of hot links.  |
  275. |   outstandingTransactionCount - Returns the number of transactions initiated |
  276. |                                 by the client to which the server has not    |
  277. |                                 responded.                                   |
  278. |   clientHandle                - Returns the window handle of the client      |
  279. |                                 conversation.  This is provided, along with  |
  280. |                                 the begin function, to allow an instance of  |
  281. |                                 this class to converse with a server without |
  282. |                                 engaging in the normal conversation          |
  283. |                                 initialization.                              |
  284. ------------------------------------------------------------------------------*/
  285. IString
  286.   application ( ) const,
  287.   topic       ( ) const;
  288.  
  289. Boolean
  290.   isCaseSensitive ( ) const,
  291.   inConversation  ( ) const;
  292.  
  293. IDDEClientConversation
  294.  &hotLinks ( IDDEClientHotLinkSet& hotLinkSet );
  295.  
  296. unsigned long
  297.   hotLinkCount                ( ) const,
  298.   outstandingTransactionCount ( ) const;
  299.  
  300. IWindowHandle
  301.   clientHandle ( ) const;
  302.  
  303. /*-------------------------------- Broadcasts ----------------------------------
  304. | Use the following functions to get information from active DDE servers about |
  305. | topics they support:                                                         |
  306. |                                                                              |
  307. | NOTE: Include the iddecset.hpp header file when you use these functions.     |
  308. |                                                                              |
  309. |   supportedTopics        - Adds IDDEActiveServer instances that represent    |
  310. |                            topics supported by DDE server applications to    |
  311. |                            the IDDEActiveServerSet passed in as the first    |
  312. |                            argument. If the applicationName argument is      |
  313. |                            specified, only the topics supported by that      |
  314. |                            application are added to the set. The default is  |
  315. |                            to add all topics supported by all server         |
  316. |                            applications.                                     |
  317. |   supportingApplications - Adds IDDEActiveServer instances that represent    |
  318. |                            DDE server applications that support the          |
  319. |                            specified topic to the IDDEActiveServerSet passed |
  320. |                            in as the first argument.                         |
  321. |-----------------------------------------------------------------------------*/
  322. virtual IDDEClientConversation
  323.  &supportedTopics        ( IDDEActiveServerSet& activeServerSet,
  324.                            const char* applicationName = 0 ),
  325.  &supportingApplications ( IDDEActiveServerSet& activeServerSet,
  326.                            const char* topicName );
  327.  
  328. protected:
  329. /*-------------------------------- Overrides -----------------------------------
  330. | This class overrides the following inherited function, typically there is no |
  331. | need for a subclass to override this function:                               |
  332. |                                                                              |
  333. |   dispatchHandlerEvent - Overridden to allow the processing of DDE-specific  |
  334. |                          messages that are sent to the client conversation.  |
  335. ------------------------------------------------------------------------------*/
  336. virtual Boolean
  337.   dispatchHandlerEvent ( IEvent& event );
  338.  
  339. /*--------------------- Implementation Handler Functions -----------------------
  340. | The following functions are called by the 'dispatchHandlerEvent' function to |
  341. | process DDE-specific messages that are sent to the client conversation.      |
  342. | Typically there is no need to override these functions:                      |
  343. |                                                                              |
  344. |   handleAck         - Handles acknowledgements from server applications.     |
  345. |   handleData        - Handles data sent from server applications.            |
  346. |   handleInitiateAck - Handles acknowledgements from server applications to   |
  347. |                       begin requests.                                        |
  348. |   handleTerminate   - Handles endConversation requests from server           |
  349. |                       applications.                                          |
  350. ------------------------------------------------------------------------------*/
  351. virtual void
  352.   handleAck         ( const IEvent& ackEvent ),
  353.   handleData        ( const IEvent& dataEvent ),
  354.   handleInitiateAck ( const IEvent& initiateAckEvent ),
  355.   handleTerminate   ( const IEvent& terminateEvent );
  356.  
  357. /*------------------ Miscellaneous Implementation Functions --------------------
  358. | The following functions perform specialized tasks that deal with instance    |
  359. | data.  Typically there is no need to override these functions:               |
  360. |                                                                              |
  361. |   endAllHotLinks  - Called by the endHotLinks function to update hot link    |
  362. |                     instance data when one or more hot links are ending.     |
  363. |                     The first version of this overloaded function is called  |
  364. |                     when all hot links on an item are ending. The other      |
  365. |                     version, which takes no arguments, is used when all hot  |
  366. |                     links are ending.                                        |
  367. |   findTransaction - Called by any of the handle functions, such as           |
  368. |                     handleAck and handleData, when it is suspected that      |
  369. |                     the server is not sending acknowledgements when it       |
  370. |                     should. If this function determines that the suspicion   |
  371. |                     is correct, it will simulate acknowledgements for the    |
  372. |                     transactions that are waiting for these                  |
  373. |                     acknowledgements.                                        |
  374. ------------------------------------------------------------------------------*/
  375. virtual void
  376.   endAllHotLinks ( const char* item ),
  377.   endAllHotLinks ( );
  378.  
  379. virtual Boolean
  380.   findTransaction ( const IEvent& event,
  381.                     Boolean       removeMatch = false );
  382.  
  383. private:
  384. /*--------------------------------- Private ----------------------------------*/
  385.   IDDEClientConversation  ( const IDDEClientConversation& rhs);
  386. IDDEClientConversation&
  387.   operator=(const IDDEClientConversation& rhs);
  388. IWindowHandle
  389.   serverHandle ( ) const;
  390. IDDEClientHotLinkSet
  391.  &hotLinksForUpdate ( ) const;
  392. IDDEClosedConversationSet
  393.  &closedConversations ( ) const;
  394. IDDETransactionQueue
  395.  &transactions ( ) const;
  396. IDDEFormatSet
  397.  &formats ( ) const;
  398. unsigned long
  399.   queueHandle ( ) const;
  400. void
  401.   dispatchEventFromQueue ( );
  402. void
  403.  *buildDDEStruct ( const char*    itemName,
  404.                    const char*    dataFormat,
  405.                    unsigned short status,
  406.                    const void*    xferData,
  407.                    unsigned long  dataLength );
  408.  
  409. unsigned long
  410.  ulClQHandle;
  411. IThread
  412.  *pThreadCl;
  413. IWindowHandle
  414.   wndhClServer,
  415.   wndhClClient;
  416. IObjectWindow
  417.  *pwndClClient;
  418. Boolean
  419.   fClBrdcstInPrgrs,
  420.   fClHdrActive,
  421.   fClPostMsgFail,
  422.   fClCaseSensitive;
  423. IString
  424.   strClTopic,
  425.   strClApplication;
  426. IDDEActiveServerSet
  427.  *pActServSetCl;
  428. IDDEClosedConversationSet
  429.  *pClsdConvSetCl;
  430. IDDEClientHotLinkSet
  431.  *pHLSetCl;
  432. IDDETransactionQueue
  433.  *pTransQCl;
  434. IDDEFormatSet
  435.  *pFormatSetCl;
  436.  
  437. }; // IDDEClientConversation
  438.  
  439. /*----------------------------------------------------------------------------*/
  440. /* Resume compiler default packing.                                           */
  441. /*----------------------------------------------------------------------------*/
  442. #pragma pack()
  443.  
  444. /*--------------------------------- Inlines ----------------------------------*/
  445. #ifndef I_NO_INLINES
  446.   #include <iddeccnv.inl>
  447. #endif
  448.  
  449. #endif /* _IDDECCNV_ */
  450.