/* ----   copyright note ----------------------------------------------------

     Copyright (c) 1997 by
     blaxxun interactive, Munich, Germany
     All rights reserved

     This software is furnished under a license  and may be  used and  copied
     only in  accordance of the  terms of such license and with the inclusion
     of the above  copyright note.  This software or any  other copies therof
     may not be provided or otherwise made available to any other person.  No
     title to and ownership of the software is hereby transferred.

     The information in this software is subject to change without notice and
     should not be construed as a commitment by blaxxun interactive.

   ----   copyright note ------------------------------------------------- */

/* ----   file information  -------------------------------------------------

   =DocStart= Module hbapi.h

   Subsystem:  blaxxun Agent
   Component:  Agent SDK

   Purpose:    This file defines the interface to the Agent SDK

   =DocEnd=

   Module:     hbapi.h

   Author:     Robert Schoeller

   Revison:    $Revision: 1.14 $

   Date:       7. Jun. 1999

   ----   file information  --------------------------------------------------*/

#ifndef _HBAPI_H
#define _HBAPI_H


//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
//             Include files and macros                                                  
//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/


#if ! defined(_CYSOCKET_H)
    typedef long  CSHandle_t;
#endif 


#if defined(BXI_DLLEXPORT)
    #define BXI_EXPORT __declspec(dllexport)

#else
    #define BXI_EXPORT 

#endif


#if defined(WIN32)  
   #if defined( HBAPI_EXPORTDLL )
       #define CSB_EXPORT __declspec( dllexport )

   #else
       #define CSB_EXPORT __declspec( dllimport )

   #endif

#else
  #define CSB_EXPORT 

#endif




//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
//  
//             Global Functions
//  
//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
void hbInitAPISession();




//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
//  
//             Class Definitions
//
//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/

//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
//             Client Context Abstract class
// Derive from this class and implement your own client context structures
// These can then be used to store client-specific data and store the context 
// to clients/avatars. 
//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/

class hbClientContext
{
   public:
           BXI_EXPORT virtual ~hbClientContext() {};
};


//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
//             Event Context class
// An valid object of this class can only be obtained by hbApi::getEventContext(); 
//
// These Event Context objects are to save the current event context for 
// asynchronous processing of events.
// Obtain the current event context by hbApi::getEventContext(),  save the pointer
// to this context and do your action processing in seperate threads. After the
// processing is done, the function 
//         hbEventContext::apiEvent( const char * pattern, const char * data )
// issues an [ApiEvent] event to the script interpreter by replacing the 
// Eventdata of the original event by "data".
//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/

class hbEventContext
{

   private: 
           friend class hbAPI;
                             // 
                             // internal context data
                             // 
           void *            _data;    

                             // 
           hbEventContext(); // private constructor
                             // 
   public:
           BXI_EXPORT hbEventContext( const hbEventContext &c ); 

           BXI_EXPORT virtual ~hbEventContext();
           BXI_EXPORT void apiEvent( const char *pattern, const char *data) const ;
};




//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
//            The API interface class
// Derive from this class and implement your own interfaces and functions.
//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/


class hbAPI
{
   private: 
                            // 
                            // list of registered functions, format is
                            // internal
                            // 
           void *           _funcList;    
       
                            // 
                            // name of session the API instance is running in
                            // 
           char *           _sessionName;   

                            // 
                            // Cybersockets handle of the session the API 
                            // instance is running in
                            // 
           CSHandle_t       _sessionHdl;

                            // 
           hbAPI();         // private constructor
                            // 

   protected:

           //
           // protected constructor to be used by derived classes
           //

           BXI_EXPORT hbAPI( CSHandle_t sessionHdl );

           //
           // registers a function which has to be called from within
           // an Agent's script.
           //
           BXI_EXPORT int registerFunc( const char *funcName, char * (hbAPI::*func)(const char *));


   public:
           //
           // destructor 
           // 
           BXI_EXPORT virtual ~hbAPI(); 

           //_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
           // Function only used by Agent interpreter, do not call these.
           //_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/

           // The following two functions are implicitely called by
           // the script interpreter. DO NOT CALL THEM IN YOUR CODE!
           //
           // The call() method. This is the actual bridge from
           // script to C++. It is called implicitely by the script
           // interpreter, do not call it directly. 
           // If a string pointer is returned, this string pointer is used in 
           // script text substitutions (%%Call ....%% expressions).
           // 
           //  Both of these functions are used internally only.
           //
           char * call( const void *f, const void * t );
           void   setLogMode( void *t, void * f, int s );

           //_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
           // End of functions only used by Agent interpreter
           //_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/



           //_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
           // Common utility methods, reimplement this function
           //_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/

           //
           // returns the name of this class, this is for logging purposes.
           // reimplement this, in order to get your class name in the
           // log files.
           //
           BXI_EXPORT virtual const char * className() const ;




           //_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
           // Common utility methods
           //_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/

           //
           // returns the name of the current session
           //
           BXI_EXPORT const char * hbAPI::getSessionName() const ;

           //
           // setting/getting a pointer to your custom context of the 
           // current client
           //
           BXI_EXPORT hbClientContext * getClientContext() const;
           BXI_EXPORT hbClientContext * setClientContext( hbClientContext *ctxt ) const;
           BXI_EXPORT int               hasClientContext() const;

           //
           // getting a pointer to the context of the current event
           //
           BXI_EXPORT hbEventContext * getEventContext() const;

           //
           // use this function for writing logs and traces.
           //
           static BXI_EXPORT void writeLog( const char * fmt, ...);

};


//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
// Type for pointer to class method. Some compilers require you to use this
// type for casting the second parameter to registerFunc();
//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/

typedef char *(hbAPI::*hbFuncType)(const char *);



//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
//      Public function to create derived instances of the class above.
//      This functions just returns an instance of the customer implementation 
//      of the hbAPI class.
//      You MUST implement this function in order to ensure
//      that the derived classes methods are called. See examples.
//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/

CSB_EXPORT hbAPI * createInstance( CSHandle_t sessionHdl, const char *name );

#endif
