Initial import of the CDE 2.1.30 sources from the Open Group.
This commit is contained in:
45
cde/lib/tt/lib/tttk/Imakefile
Normal file
45
cde/lib/tt/lib/tttk/Imakefile
Normal file
@@ -0,0 +1,45 @@
|
||||
XCOMM $XConsortium: Imakefile /main/6 1996/05/07 19:13:02 drk $
|
||||
#define DoNormalLib NormalLibTt
|
||||
#define DoSharedLib SharedLibTt
|
||||
#define DoDebugLib DebugLibTt
|
||||
#define DoProfileLib ProfileLibTt
|
||||
#define LibName tt
|
||||
#define SoRev SOTTREV
|
||||
#define IncSubdir Tt
|
||||
#define LibCreate NO
|
||||
#ifdef TtLargePICTable
|
||||
# define LargePICTable TtLargePICTable
|
||||
#endif
|
||||
|
||||
#define CplusplusSource YES
|
||||
DEPEND_DEFINES = $(CXXDEPENDINCLUDES)
|
||||
|
||||
#include <Threads.tmpl>
|
||||
|
||||
#include "../../tooltalk.tmpl"
|
||||
|
||||
DEFINES =
|
||||
INCLUDES = -I../../lib
|
||||
|
||||
|
||||
/*** NOTE!
|
||||
*** Every time a .o is added below it needs to be added to
|
||||
*** the lib/tt/lib Imakefile in DB_OBJS and SHARED_DB_OBJS
|
||||
***/
|
||||
|
||||
HEADERS = tttk.h
|
||||
|
||||
SRCS = ttdesktop.C ttdtfile.C ttdtprocid.C \
|
||||
ttmedia.C tttk.C tttk2free.C \
|
||||
tttkmessage.C tttkpattern.C tttkutils.C
|
||||
|
||||
OBJS = ttdesktop.o ttdtfile.o ttdtprocid.o \
|
||||
ttmedia.o tttk.o tttk2free.o \
|
||||
tttkmessage.o tttkpattern.o tttkutils.o
|
||||
|
||||
|
||||
#include <Library.tmpl>
|
||||
|
||||
SubdirLibraryRule($(OBJS))
|
||||
|
||||
DependTarget()
|
||||
59
cde/lib/tt/lib/tttk/eclipse.C
Normal file
59
cde/lib/tt/lib/tttk/eclipse.C
Normal file
@@ -0,0 +1,59 @@
|
||||
//%% (c) Copyright 1993, 1994 Hewlett-Packard Company
|
||||
//%% (c) Copyright 1993, 1994 International Business Machines Corp.
|
||||
//%% (c) Copyright 1993, 1994 Sun Microsystems, Inc.
|
||||
//%% (c) Copyright 1993, 1994 Novell, Inc.
|
||||
//%% $XConsortium: eclipse.C /main/3 1995/10/23 10:31:20 rswiston $
|
||||
/*
|
||||
* @(#)eclipse.C 1.3 93/09/07
|
||||
* Copyright 1993 Sun Microsystems, Inc. All rights reserved.
|
||||
*/
|
||||
#include "ttdt.h"
|
||||
#include "ttdtprocid.h"
|
||||
#include "ttdtutils.h"
|
||||
|
||||
TtDtProcIDEclipse::TtDtProcIDEclipse(
|
||||
const char *procID2Install,
|
||||
Tt_status *status
|
||||
)
|
||||
{
|
||||
static const char *here = "TtDtProcIDEclipse::TtDtProcIDEclipse()";
|
||||
|
||||
_occultedProcID = tt_default_procid();
|
||||
*status = tt_ptr_error( _occultedProcID );
|
||||
if (*status != TT_OK) {
|
||||
_occultedProcID = 0;
|
||||
if ((procID2Install == 0) && (*status == TT_ERR_NOMP)) {
|
||||
//
|
||||
// There is no default procid to eclipse. OK.
|
||||
//
|
||||
*status = TT_OK;
|
||||
} else {
|
||||
ttDtPrintStatus( here, "tt_default_procid()", *status);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (procID2Install != 0) {
|
||||
*status = tt_default_procid_set( procID2Install );
|
||||
if (*status != TT_OK) {
|
||||
ttDtPrintStatus( here, "tt_default_procid_set()",
|
||||
*status );
|
||||
tt_free( (caddr_t)_occultedProcID );
|
||||
_occultedProcID = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TtDtProcIDEclipse::~TtDtProcIDEclipse()
|
||||
{
|
||||
static const char *here = "TtDtProcIDEclipse::~TtDtProcIDEclipse()";
|
||||
|
||||
if (_occultedProcID != 0) {
|
||||
Tt_status status = tt_default_procid_set( _occultedProcID );
|
||||
if (status != TT_OK) {
|
||||
ttDtPrintStatus( here, "tt_default_procid_set()",
|
||||
status );
|
||||
}
|
||||
tt_free( (caddr_t)_occultedProcID );
|
||||
_occultedProcID = 0;
|
||||
}
|
||||
}
|
||||
30
cde/lib/tt/lib/tttk/eclipse.h
Normal file
30
cde/lib/tt/lib/tttk/eclipse.h
Normal file
@@ -0,0 +1,30 @@
|
||||
/*%% (c) Copyright 1993, 1994 Hewlett-Packard Company */
|
||||
/*%% (c) Copyright 1993, 1994 International Business Machines Corp. */
|
||||
/*%% (c) Copyright 1993, 1994 Sun Microsystems, Inc. */
|
||||
/*%% (c) Copyright 1993, 1994 Novell, Inc. */
|
||||
/*%% $XConsortium: eclipse.h /main/3 1995/10/23 10:31:27 rswiston $ */
|
||||
/*
|
||||
* @(#)eclipse.h 1.3 93/09/07
|
||||
*/
|
||||
#ifndef ttdtprocid_h
|
||||
#define ttdtprocid_h
|
||||
|
||||
#include "ticccm.h"
|
||||
|
||||
//
|
||||
// An instance of this class will install the given procID as
|
||||
// the new default procID, and will restore the old default
|
||||
// procID when it goes out of scope.
|
||||
//
|
||||
class TtDtProcIDEclipse {
|
||||
public:
|
||||
TtDtProcIDEclipse(
|
||||
const char *procID2Install,
|
||||
Tt_status *status
|
||||
);
|
||||
~TtDtProcIDEclipse();
|
||||
private:
|
||||
const char *_occultedProcID;
|
||||
};
|
||||
|
||||
#endif
|
||||
1800
cde/lib/tt/lib/tttk/ttdesktop.C
Normal file
1800
cde/lib/tt/lib/tttk/ttdesktop.C
Normal file
File diff suppressed because it is too large
Load Diff
372
cde/lib/tt/lib/tttk/ttdesktop.h
Normal file
372
cde/lib/tt/lib/tttk/ttdesktop.h
Normal file
@@ -0,0 +1,372 @@
|
||||
/*%% (c) Copyright 1993, 1994 Hewlett-Packard Company */
|
||||
/*%% (c) Copyright 1993, 1994 International Business Machines Corp. */
|
||||
/*%% (c) Copyright 1993, 1994 Sun Microsystems, Inc. */
|
||||
/*%% (c) Copyright 1993, 1994 Novell, Inc. */
|
||||
/*%% $XConsortium: ttdesktop.h /main/3 1995/10/23 10:31:59 rswiston $ */
|
||||
/*
|
||||
* @(#)ttdesktop.h 1.3 93/09/07
|
||||
*
|
||||
* Copyright 1993 Sun Microsystems, Inc. All rights reserved.
|
||||
*/
|
||||
#ifndef ttdesktop_h
|
||||
#define ttdesktop_h
|
||||
|
||||
#include "tttk/tttk.h"
|
||||
#include "tttk/tttkmessage.h"
|
||||
|
||||
typedef struct {
|
||||
int repliesOutStanding;
|
||||
int width;
|
||||
int height;
|
||||
int xOffset;
|
||||
int yOffset;
|
||||
char *display;
|
||||
} DisplayInfo;
|
||||
|
||||
Tt_pattern _ttDesktopPatternFinish(
|
||||
Tt_pattern pat,
|
||||
Tt_message commission,
|
||||
int register_it
|
||||
);
|
||||
Tt_message _ttDesktopMessageFinish(
|
||||
Tt_message msg,
|
||||
Tt_message commission,
|
||||
int send
|
||||
);
|
||||
Widget _ttdt_realized_widget(
|
||||
void *widget,
|
||||
int mappedWhenManaged_Shell = 1
|
||||
);
|
||||
Tt_message _ttdt_posix_cb(
|
||||
Tt_message msg,
|
||||
Tt_pattern pat,
|
||||
void *clientCB,
|
||||
void *clientData
|
||||
);
|
||||
Tt_message _ttdt_contract_cb(
|
||||
Tt_message msg,
|
||||
Tt_pattern pat,
|
||||
void *clientCB,
|
||||
void *clientData
|
||||
);
|
||||
Tt_pattern _ttdt_pat(
|
||||
Tttk_op op,
|
||||
_TtDtMessageCB internalCB,
|
||||
Tt_category category,
|
||||
Tt_message commission,
|
||||
void *clientCB,
|
||||
void *clientdata,
|
||||
int register_it
|
||||
);
|
||||
|
||||
Tt_message _ttdt_do_GSet_Geometry(
|
||||
Tt_message msg,
|
||||
void *widget,
|
||||
Tt_message ,
|
||||
int *width,
|
||||
int *height,
|
||||
int *xOffset,
|
||||
int *yOffset
|
||||
);
|
||||
Tt_message _ttdt_do_wm_state(
|
||||
Tt_message msg,
|
||||
void *widget,
|
||||
Tt_message ,
|
||||
int *iconified_or_mapped
|
||||
);
|
||||
Tt_message _ttdt_do_Set_XInfo(
|
||||
Tt_message msg,
|
||||
void *widget,
|
||||
Tt_message ,
|
||||
char *display,
|
||||
int visual,
|
||||
int depth
|
||||
);
|
||||
Tt_message _ttdt_do_Get_XInfo(
|
||||
Tt_message msg,
|
||||
void *widget,
|
||||
Tt_message ,
|
||||
char **display,
|
||||
int *visual,
|
||||
int *depth
|
||||
);
|
||||
Tt_message _ttdt_do_RaiseLower(
|
||||
Tt_message msg,
|
||||
void *widget,
|
||||
Tt_message
|
||||
);
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* Desktop: POSIX
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
Tt_message ttdt_Started(
|
||||
Tt_message context,
|
||||
const char *toolName,
|
||||
const char *vendor,
|
||||
const char *version,
|
||||
int send_and_destroy
|
||||
);
|
||||
Tt_message ttdt_Stopped(
|
||||
Tt_message context,
|
||||
const char *toolName,
|
||||
const char *vendor,
|
||||
const char *version,
|
||||
int send_and_destroy
|
||||
);
|
||||
Tt_message ttdt_Status(
|
||||
Tt_message context,
|
||||
Tt_message commission,
|
||||
const char *status,
|
||||
const char *toolName,
|
||||
const char *vendor,
|
||||
const char *version,
|
||||
int send_and_destroy
|
||||
);
|
||||
|
||||
/*
|
||||
* Get_Locale
|
||||
*/
|
||||
typedef Tt_message (*Ttdt_Get_Locale_msg_cb)(
|
||||
Tt_message msg,
|
||||
void *clientdata,
|
||||
const char **categories,
|
||||
const char **locales
|
||||
);
|
||||
Tt_message ttdt_Get_Locale(
|
||||
const char *handler,
|
||||
Tt_message commission,
|
||||
Ttdt_Get_Locale_msg_cb callback,
|
||||
void *clientdata,
|
||||
const char **categories,
|
||||
int send
|
||||
);
|
||||
/*
|
||||
* Get_Situation
|
||||
*/
|
||||
typedef Tt_message (*Ttdt_Get_Situation_msg_cb)(
|
||||
Tt_message msg,
|
||||
void *clientdata,
|
||||
char *cwd
|
||||
);
|
||||
Tt_message ttdt_Get_Situation(
|
||||
const char *handler,
|
||||
Tt_message commission,
|
||||
Ttdt_Get_Situation_msg_cb callback,
|
||||
void *clientdata,
|
||||
int send
|
||||
);
|
||||
/*
|
||||
* Quit
|
||||
*/
|
||||
typedef Tt_message (*Ttdt_Quit_cb)(
|
||||
Tt_message msg,
|
||||
void *clientdata,
|
||||
Tt_message commission,
|
||||
int silent,
|
||||
int force
|
||||
);
|
||||
Tt_pattern ttdt_Quit_pat(
|
||||
Tt_category category,
|
||||
Tt_message commission,
|
||||
Ttdt_Quit_cb callback,
|
||||
void *clientdata,
|
||||
int register_it
|
||||
);
|
||||
/*
|
||||
* Pause
|
||||
*/
|
||||
Tt_pattern ttdt_Pause_pat(
|
||||
Tt_category category,
|
||||
Tt_message commission,
|
||||
Ttdt_contract_cb callback,
|
||||
void *clientdata,
|
||||
int register_it
|
||||
);
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* Desktop: X11
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
/*
|
||||
* Get_Geometry
|
||||
*/
|
||||
typedef Tt_message (*Ttdt_Geometry_in_cb)(
|
||||
Tt_message msg,
|
||||
void *clientdata,
|
||||
Tt_message commission,
|
||||
int width,
|
||||
int height,
|
||||
int xoffset,
|
||||
int yoffset
|
||||
);
|
||||
typedef Tt_message (*Ttdt_Geometry_out_cb)(
|
||||
Tt_message msg,
|
||||
void *clientdata,
|
||||
Tt_message commission,
|
||||
int *width,
|
||||
int *height,
|
||||
int *xoffset,
|
||||
int *yoffset
|
||||
);
|
||||
Tt_message ttdt_Get_Geometry(
|
||||
const char *handler,
|
||||
Tt_message commission,
|
||||
Ttdt_Geometry_in_cb callback,
|
||||
void *clientdata,
|
||||
int send
|
||||
);
|
||||
Tt_pattern ttdt_Get_Geometry_pat(
|
||||
Tt_category category,
|
||||
Tt_message commission,
|
||||
Ttdt_Geometry_out_cb callback,
|
||||
void *clientdata,
|
||||
int register_it
|
||||
);
|
||||
/*
|
||||
* Set_Geometry
|
||||
*/
|
||||
Tt_message ttdt_Set_Geometry(
|
||||
const char *handler,
|
||||
Tt_message commission,
|
||||
Tt_class req_or_edict,
|
||||
Ttdt_Geometry_in_cb callback,
|
||||
void *clientdata,
|
||||
int width,
|
||||
int height,
|
||||
int xoffset,
|
||||
int yoffset,
|
||||
int send
|
||||
);
|
||||
Tt_pattern ttdt_Set_Geometry_pat(
|
||||
Tt_category category,
|
||||
Tt_message commission,
|
||||
Ttdt_Geometry_out_cb callback,
|
||||
void *clientdata,
|
||||
int register_it
|
||||
);
|
||||
/*
|
||||
* Get_Iconified
|
||||
*/
|
||||
typedef Tt_message (*Ttdt_Iconified_in_cb)(
|
||||
Tt_message msg,
|
||||
void *clientdata,
|
||||
Tt_message commission,
|
||||
int iconified
|
||||
);
|
||||
typedef Tt_message (*Ttdt_Iconified_out_cb)(
|
||||
Tt_message msg,
|
||||
void *clientdata,
|
||||
Tt_message commission,
|
||||
int *iconified
|
||||
);
|
||||
Tt_message ttdt_Get_Iconified(
|
||||
const char *handler,
|
||||
Tt_message commission,
|
||||
Ttdt_Iconified_in_cb callback,
|
||||
void *clientdata,
|
||||
int send
|
||||
);
|
||||
Tt_pattern ttdt_Get_Iconified_pat(
|
||||
Tt_category category,
|
||||
Tt_message commission,
|
||||
Ttdt_Iconified_out_cb callback,
|
||||
void *clientdata,
|
||||
int register_it
|
||||
);
|
||||
/*
|
||||
* Set_Iconified
|
||||
*/
|
||||
Tt_message ttdt_Set_Iconified(
|
||||
const char *handler,
|
||||
Tt_message commission,
|
||||
Tt_class req_or_edict,
|
||||
Ttdt_Iconified_in_cb callback,
|
||||
void *clientdata,
|
||||
int iconified,
|
||||
int send
|
||||
);
|
||||
Tt_pattern ttdt_Set_Iconified_pat(
|
||||
Tt_category category,
|
||||
Tt_message commission,
|
||||
Ttdt_Iconified_out_cb callback,
|
||||
void *clientdata,
|
||||
int register_it
|
||||
);
|
||||
/*
|
||||
* Get_XInfo
|
||||
*/
|
||||
typedef Tt_message (*Ttdt_XInfo_in_cb)(
|
||||
Tt_message msg,
|
||||
void *clientdata,
|
||||
Tt_message commission,
|
||||
char *display,
|
||||
int visual,
|
||||
int depth
|
||||
);
|
||||
typedef Tt_message (*Ttdt_XInfo_out_cb)(
|
||||
Tt_message msg,
|
||||
void *clientdata,
|
||||
Tt_message commission,
|
||||
char **display,
|
||||
int *visual,
|
||||
int *depth
|
||||
);
|
||||
Tt_message ttdt_Get_XInfo(
|
||||
const char *handler,
|
||||
Tt_message commission,
|
||||
Ttdt_XInfo_in_cb callback,
|
||||
void *clientdata,
|
||||
int send
|
||||
);
|
||||
Tt_pattern ttdt_Get_XInfo_pat(
|
||||
Tt_category category,
|
||||
Tt_message commission,
|
||||
Ttdt_XInfo_out_cb callback,
|
||||
void *clientdata,
|
||||
int register_it
|
||||
);
|
||||
/*
|
||||
* Set_XInfo
|
||||
*/
|
||||
Tt_message ttdt_Set_XInfo(
|
||||
const char *handler,
|
||||
Tt_message commission,
|
||||
Tt_class req_or_edict,
|
||||
Ttdt_XInfo_in_cb callback,
|
||||
void *clientdata,
|
||||
const char *display,
|
||||
int visual,
|
||||
int depth,
|
||||
int send
|
||||
);
|
||||
Tt_pattern ttdt_Set_XInfo_pat(
|
||||
Tt_category category,
|
||||
Tt_message commission,
|
||||
Ttdt_XInfo_in_cb callback,
|
||||
void *clientdata,
|
||||
int register_it
|
||||
);
|
||||
/*
|
||||
* Raise
|
||||
*/
|
||||
Tt_message ttdt_Raise(
|
||||
const char *handler,
|
||||
Tt_message commission,
|
||||
Tt_class req_or_edict,
|
||||
Ttdt_contract_cb callback,
|
||||
void *clientdata,
|
||||
int send
|
||||
);
|
||||
Tt_pattern ttdt_Raise_pat(
|
||||
Tt_category category,
|
||||
Tt_message commission,
|
||||
Ttdt_contract_cb callback,
|
||||
void *clientdata,
|
||||
int register_it
|
||||
);
|
||||
#endif
|
||||
507
cde/lib/tt/lib/tttk/ttdtfile.C
Normal file
507
cde/lib/tt/lib/tttk/ttdtfile.C
Normal file
@@ -0,0 +1,507 @@
|
||||
//%% (c) Copyright 1993, 1994 Hewlett-Packard Company
|
||||
//%% (c) Copyright 1993, 1994 International Business Machines Corp.
|
||||
//%% (c) Copyright 1993, 1994 Sun Microsystems, Inc.
|
||||
//%% (c) Copyright 1993, 1994 Novell, Inc.
|
||||
//%% $XConsortium: ttdtfile.C /main/3 1995/10/23 10:32:19 rswiston $
|
||||
/*
|
||||
* @(#)ttdtfile.C 1.3 93/09/07
|
||||
*
|
||||
* Copyright 1993 Sun Microsystems, Inc. All rights reserved.
|
||||
*/
|
||||
#include <unistd.h>
|
||||
#include "api/c/tt_c.h"
|
||||
#include "api/c/api_api.h"
|
||||
#include "tttk/tttk.h"
|
||||
#include "tttk/tttkpattern.h"
|
||||
#include "tttk/tttkmessage.h"
|
||||
#include "tttk/tttk2free.h"
|
||||
#include "tttk/tttkutils.h"
|
||||
|
||||
typedef struct {
|
||||
Tt_scope theScope;
|
||||
const char *pathname;
|
||||
Ttdt_file_cb cb;
|
||||
void *clientData;
|
||||
} TtDtFileJoinInfo;
|
||||
|
||||
//
|
||||
// Parse file message and pass it to user callback
|
||||
//
|
||||
static Tt_message
|
||||
_ttDtFileCB(
|
||||
Tt_message msg,
|
||||
Tt_pattern , // Not needed
|
||||
void *clientCB,
|
||||
void *clientData
|
||||
)
|
||||
{
|
||||
if (clientCB == 0) {
|
||||
return msg;
|
||||
}
|
||||
_TttkItem2Free fuse = msg;
|
||||
char *file = tt_message_file( msg );
|
||||
Tt_status status = tt_ptr_error( file );
|
||||
if (status != TT_OK) {
|
||||
return (Tt_message)tt_error_pointer( status );
|
||||
}
|
||||
char *opname = tt_message_op( msg );
|
||||
status = tt_ptr_error( opname );
|
||||
if (status != TT_OK) {
|
||||
return (Tt_message)tt_error_pointer( status );
|
||||
}
|
||||
Tttk_op op = tttk_string_op( opname );
|
||||
tt_free( opname );
|
||||
int trust = ( ( geteuid() == tt_message_uid( msg ))
|
||||
&& ( getegid() == tt_message_gid( msg )));
|
||||
int from_me = 0;
|
||||
char *sender = tt_message_sender( msg );
|
||||
char *me = tt_default_procid();
|
||||
if ((tt_ptr_error( sender ) == TT_OK) && (tt_ptr_error(me) == TT_OK)) {
|
||||
from_me = (strcmp( sender, me ) == 0);
|
||||
}
|
||||
tt_free( sender );
|
||||
tt_free( me );
|
||||
if ((op == TTDT_GET_MODIFIED) && (_tttk_message_am_handling(msg))) {
|
||||
//
|
||||
// If our pattern even matches Get_Modified, it is because
|
||||
// the client called ttdt_file_event(,TTDT_MODIFIED,,).
|
||||
// Reverting or saving unregisters this pattern, so if
|
||||
// we even see the question we know the answer is yes.
|
||||
//
|
||||
tt_message_arg_ival_set( msg, 1, 1 );
|
||||
tt_message_reply( msg );
|
||||
// message destroyed by fuse
|
||||
return 0;
|
||||
}
|
||||
Ttdt_file_cb _cb = (Ttdt_file_cb)clientCB;
|
||||
msg = (*_cb)( msg, op, file, clientData, trust, from_me );
|
||||
fuse = (caddr_t)0; // prevent message destruction
|
||||
return msg;
|
||||
}
|
||||
|
||||
//
|
||||
// Create the pattern registered at file-join-time
|
||||
//
|
||||
static Tt_pattern
|
||||
_ttDtFileJoinPat(
|
||||
const char *pathname,
|
||||
Tt_scope theScope,
|
||||
Ttdt_file_cb cb,
|
||||
void *clientData
|
||||
)
|
||||
{
|
||||
Tt_pattern pat = _ttDtPatternCreate( TT_OBSERVE, theScope,
|
||||
theScope != TT_FILE, pathname,
|
||||
TTDT_DELETED, _ttDtFileCB,
|
||||
cb, clientData, 0 );
|
||||
Tt_status status = tt_ptr_error( pat );
|
||||
if (status != TT_OK) {
|
||||
return pat;
|
||||
}
|
||||
_TttkItem2Free fuse = pat;
|
||||
tt_pattern_op_add( pat, _ttDtOp( TTDT_MODIFIED ) );
|
||||
tt_pattern_op_add( pat, _ttDtOp( TTDT_REVERTED ) );
|
||||
tt_pattern_op_add( pat, _ttDtOp( TTDT_MOVED ) );
|
||||
tt_pattern_op_add( pat, _ttDtOp( TTDT_SAVED ) );
|
||||
status = tt_pattern_class_add( pat, TT_NOTICE );
|
||||
if (status != TT_OK) {
|
||||
return (Tt_pattern)tt_error_pointer( status );
|
||||
}
|
||||
status = tt_pattern_arg_add( pat, TT_IN, Tttk_file, 0 );
|
||||
if (status != TT_OK) {
|
||||
return (Tt_pattern)tt_error_pointer( status );
|
||||
}
|
||||
status = tt_pattern_register( pat );
|
||||
if (status != TT_OK) {
|
||||
return (Tt_pattern)tt_error_pointer( status );
|
||||
}
|
||||
fuse = (caddr_t)0;
|
||||
return pat;
|
||||
}
|
||||
|
||||
Tt_pattern *
|
||||
ttdt_file_join(
|
||||
const char *pathname,
|
||||
Tt_scope theScope,
|
||||
int join,
|
||||
Ttdt_file_cb cb,
|
||||
void *clientData
|
||||
)
|
||||
{
|
||||
//
|
||||
// One pattern to observe notices, one to handle requests, and
|
||||
// a null terminator.
|
||||
//
|
||||
Tt_pattern *pPats = (Tt_pattern *)malloc( 3 * sizeof(Tt_pattern) );
|
||||
if (pPats == 0) {
|
||||
return (Tt_pattern *)tt_error_pointer( TT_ERR_NOMEM );
|
||||
}
|
||||
_TttkList2Free fuses( 3 );
|
||||
fuses += (caddr_t)pPats;
|
||||
pPats[1] = 0;
|
||||
pPats[2] = 0;
|
||||
Tt_scope toTry = theScope;
|
||||
if (theScope == TT_SCOPE_NONE) {
|
||||
toTry = TT_BOTH;
|
||||
}
|
||||
pPats[0] = _ttDtFileJoinPat( pathname, toTry, cb, clientData );
|
||||
Tt_status status = tt_ptr_error( pPats[0] );
|
||||
if ((status != TT_OK) && (theScope == TT_SCOPE_NONE)) {
|
||||
toTry = TT_FILE_IN_SESSION;
|
||||
pPats[0] = _ttDtFileJoinPat( pathname, toTry, cb, clientData );
|
||||
status = tt_ptr_error( pPats[0] );
|
||||
}
|
||||
if (status != TT_OK) {
|
||||
return (Tt_pattern *)tt_error_pointer( status );
|
||||
}
|
||||
fuses += pPats[0];
|
||||
TtDtFileJoinInfo *info = (TtDtFileJoinInfo *)
|
||||
malloc( sizeof( TtDtFileJoinInfo ));
|
||||
if (info == 0) {
|
||||
return (Tt_pattern *)tt_error_pointer( TT_DESKTOP_ENOMEM );
|
||||
}
|
||||
fuses += (caddr_t)info;
|
||||
info->pathname = _tt_strdup( pathname );
|
||||
info->theScope = toTry;
|
||||
info->cb = cb;
|
||||
info->clientData = clientData;
|
||||
status = tt_pattern_user_set( pPats[0], _TttkJoinInfoKey, info );
|
||||
if (status != TT_OK) {
|
||||
return (Tt_pattern *)tt_error_pointer( status );
|
||||
}
|
||||
if (join) {
|
||||
status = tt_file_join( pathname );
|
||||
if (status != TT_OK) {
|
||||
return (Tt_pattern *)tt_error_pointer( status );
|
||||
}
|
||||
}
|
||||
fuses.flush();
|
||||
return pPats;
|
||||
}
|
||||
|
||||
Tt_message
|
||||
ttdt_file_notice(
|
||||
Tt_message context,
|
||||
Tttk_op op,
|
||||
Tt_scope theScope,
|
||||
const char *file,
|
||||
int sendAndDestroy
|
||||
)
|
||||
{
|
||||
if ((op == TTDT_MOVED) && sendAndDestroy) {
|
||||
return (Tt_message)tt_error_pointer( TT_DESKTOP_EINVAL );
|
||||
}
|
||||
Tt_message msg = tttk_message_create( context, TT_NOTICE, theScope, 0,
|
||||
_ttDtOp( op ), 0 );
|
||||
Tt_status status = tt_ptr_error( msg );
|
||||
if (status != TT_OK) {
|
||||
return msg;
|
||||
}
|
||||
//
|
||||
// Guarantees that msg will be destroyed when this function returns
|
||||
//
|
||||
_TttkItem2Free fuse = msg;
|
||||
status = tt_message_file_set( msg, file );
|
||||
if (status != TT_OK) {
|
||||
return (Tt_message)tt_error_pointer( status );
|
||||
}
|
||||
status = tt_message_arg_add( msg, TT_IN, Tttk_file, 0 );
|
||||
if (status != TT_OK) {
|
||||
return (Tt_message)tt_error_pointer( status );
|
||||
}
|
||||
if (sendAndDestroy) {
|
||||
status = tt_message_send( msg );
|
||||
if (status != TT_OK) {
|
||||
return (Tt_message)tt_error_pointer( status );
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
fuse = (caddr_t)0;
|
||||
return msg;
|
||||
}
|
||||
|
||||
Tt_message
|
||||
ttdt_file_request(
|
||||
Tt_message context,
|
||||
Tttk_op op,
|
||||
Tt_scope theScope,
|
||||
const char *file,
|
||||
Ttdt_file_cb cb,
|
||||
void *clientData,
|
||||
int send
|
||||
)
|
||||
{
|
||||
Tt_message msg = _ttDtPMessageCreate( context, TT_REQUEST, theScope, 0,
|
||||
op, _ttDtFileCB, cb, clientData);
|
||||
Tt_status status = tt_ptr_error( msg );
|
||||
if (status != TT_OK) {
|
||||
return msg;
|
||||
}
|
||||
_TttkItem2Free fuse = msg;
|
||||
status = tt_message_file_set( msg, file );
|
||||
if (status != TT_OK) {
|
||||
return (Tt_message)tt_error_pointer( status );
|
||||
}
|
||||
status = tt_message_arg_add( msg, TT_IN, Tttk_file, 0 );
|
||||
if (status != TT_OK) {
|
||||
return (Tt_message)tt_error_pointer( status );
|
||||
}
|
||||
if (op == TTDT_GET_MODIFIED) {
|
||||
status = tt_message_arg_add( msg, TT_OUT, Tttk_boolean, 0 );
|
||||
if (status != TT_OK) {
|
||||
return (Tt_message)tt_error_pointer( status );
|
||||
}
|
||||
}
|
||||
if (send) {
|
||||
status = tt_message_send( msg );
|
||||
if (status != TT_OK) {
|
||||
return (Tt_message)tt_error_pointer( status );
|
||||
}
|
||||
}
|
||||
fuse = (caddr_t)0;
|
||||
return msg;
|
||||
}
|
||||
|
||||
//
|
||||
// Create the pattern registered at file-event-time
|
||||
//
|
||||
static Tt_pattern
|
||||
_ttDtFileEventPat(
|
||||
const char *pathname,
|
||||
Tt_scope theScope,
|
||||
Ttdt_file_cb cb,
|
||||
void *clientData
|
||||
)
|
||||
{
|
||||
Tt_pattern pat = _ttDtPatternCreate( TT_HANDLE, theScope,
|
||||
theScope != TT_FILE, pathname,
|
||||
TTDT_SAVE, _ttDtFileCB,
|
||||
cb, clientData, 0 );
|
||||
Tt_status status = tt_ptr_error( pat );
|
||||
if (status != TT_OK) {
|
||||
return pat;
|
||||
}
|
||||
_TttkItem2Free fuse = pat;
|
||||
tt_pattern_op_add( pat, _ttDtOp( TTDT_GET_MODIFIED ) );
|
||||
tt_pattern_op_add( pat, _ttDtOp( TTDT_REVERT ) );
|
||||
status = tt_pattern_class_add( pat, TT_REQUEST );
|
||||
if (status != TT_OK) {
|
||||
return (Tt_pattern)tt_error_pointer( status );
|
||||
}
|
||||
status = tt_pattern_arg_add( pat, TT_IN, Tttk_file, 0 );
|
||||
if (status != TT_OK) {
|
||||
return (Tt_pattern)tt_error_pointer( status );
|
||||
}
|
||||
status = tt_pattern_register( pat );
|
||||
if (status != TT_OK) {
|
||||
return (Tt_pattern)tt_error_pointer( status );
|
||||
}
|
||||
fuse = (caddr_t)0;
|
||||
return pat;
|
||||
}
|
||||
|
||||
Tt_status
|
||||
ttdt_file_event(
|
||||
Tt_message context,
|
||||
Tttk_op event,
|
||||
Tt_pattern *pats,
|
||||
int send
|
||||
)
|
||||
{
|
||||
if ((pats == 0) || (tt_ptr_error( pats ) != TT_OK)) {
|
||||
return TT_ERR_POINTER;
|
||||
}
|
||||
TtDtFileJoinInfo *info = (TtDtFileJoinInfo *)
|
||||
tt_pattern_user( pats[0], _TttkJoinInfoKey );
|
||||
Tt_status status = tt_ptr_error( info );
|
||||
if ((status != TT_OK) || (info == 0)) {
|
||||
return status;
|
||||
}
|
||||
if (event == TTDT_MODIFIED) {
|
||||
pats[1] = _ttDtFileEventPat( info->pathname, info->theScope,
|
||||
info->cb, info->clientData );
|
||||
Tt_status status = tt_ptr_error( pats[1] );
|
||||
if (status != TT_OK) {
|
||||
// Leave pats[1] as an error pointer
|
||||
return status;
|
||||
}
|
||||
}
|
||||
if (send) {
|
||||
Tt_message msg = ttdt_file_notice( context, event,
|
||||
info->theScope, info->pathname, 1 );
|
||||
status = tt_ptr_error( msg );
|
||||
if (status != TT_OK) {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
if ((event == TTDT_SAVED) || (event == TTDT_REVERTED)) {
|
||||
status = tt_pattern_unregister( pats[1] );
|
||||
if (status != TT_OK) {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
return TT_OK;
|
||||
}
|
||||
|
||||
Tt_status
|
||||
ttdt_file_quit(
|
||||
Tt_pattern *pats,
|
||||
int quit
|
||||
)
|
||||
{
|
||||
if ((pats == 0) || (tt_ptr_error( pats ) != TT_OK)) {
|
||||
return TT_ERR_POINTER;
|
||||
}
|
||||
TtDtFileJoinInfo *info = (TtDtFileJoinInfo *)
|
||||
tt_pattern_user( pats[0], _TttkJoinInfoKey );
|
||||
Tt_status status = tt_ptr_error( info );
|
||||
if ((status != TT_OK) || (info == 0)) {
|
||||
return status;
|
||||
}
|
||||
status = _tttk_patterns_destroy( pats );
|
||||
if (quit) {
|
||||
if (info->pathname != 0) {
|
||||
status = tt_file_quit( info->pathname );
|
||||
tt_free( (char *)info->pathname );
|
||||
}
|
||||
free( info );
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
//
|
||||
// Parse Get_Modified reply and set *(int *)clientData
|
||||
//
|
||||
static Tt_message
|
||||
_ttDtGetModifiedCB(
|
||||
Tt_message msg,
|
||||
Tttk_op ,
|
||||
char *pathName,
|
||||
void *clientData,
|
||||
int ,
|
||||
int
|
||||
)
|
||||
{
|
||||
tt_free( pathName );
|
||||
if (! _tttk_message_in_final_state( msg )) {
|
||||
// Not in final state; our address space is probably handler
|
||||
return msg;
|
||||
}
|
||||
*(int *)clientData = 0; // assume not modified
|
||||
if (tt_message_state(msg) == TT_HANDLED) {
|
||||
int modified;
|
||||
Tt_status status = tt_message_arg_ival( msg, 1, &modified );
|
||||
if (status != TT_OK) {
|
||||
tttk_message_destroy( msg );
|
||||
return 0;
|
||||
}
|
||||
if (modified) {
|
||||
*(int *)clientData = -1;
|
||||
}
|
||||
}
|
||||
tttk_message_destroy( msg );
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
ttdt_Get_Modified(
|
||||
Tt_message context,
|
||||
const char *pathname,
|
||||
Tt_scope theScope,
|
||||
XtAppContext app2run,
|
||||
int msTimeOut
|
||||
)
|
||||
{
|
||||
int waiting = 1;
|
||||
Tt_message msg = ttdt_file_request( context, TTDT_GET_MODIFIED,
|
||||
theScope, pathname,
|
||||
_ttDtGetModifiedCB, &waiting, 1 );
|
||||
Tt_status status = tt_ptr_error( msg );
|
||||
if (status != TT_OK) {
|
||||
return 0;
|
||||
}
|
||||
status = tttk_block_while( app2run, &waiting, msTimeOut );
|
||||
if (status == TT_DESKTOP_ETIMEDOUT) {
|
||||
//
|
||||
// _ttDtGetModifiedCB() would have destroyed msg,
|
||||
// but this removes the callback. Now, any
|
||||
// late-breaking reply will pop out of
|
||||
// tt_message_receive(). Well-behaved applications
|
||||
// should do [what is done by] tttk_message_abandon(),
|
||||
// but poorly-written apps might panic. XXX
|
||||
//
|
||||
tttk_message_destroy( msg );
|
||||
}
|
||||
return (waiting < 0);
|
||||
}
|
||||
|
||||
//
|
||||
// Private Ttdt_file_cb hung on requests (Get_Modified, Save, Revert)
|
||||
// that we send synchronously.
|
||||
//
|
||||
static Tt_message
|
||||
_ttDtFileRequestCB(
|
||||
Tt_message msg,
|
||||
Tttk_op ,
|
||||
char *pathName,
|
||||
void *clientData,
|
||||
int ,
|
||||
int
|
||||
)
|
||||
{
|
||||
tt_free( pathName );
|
||||
return _ttTkNoteReplyStatus( msg, 0, 0, clientData );
|
||||
}
|
||||
|
||||
Tt_status
|
||||
_ttdt_file_request(
|
||||
Tttk_op op,
|
||||
Tt_message context,
|
||||
const char *pathname,
|
||||
Tt_scope theScope,
|
||||
XtAppContext app2run,
|
||||
int msTimeOut
|
||||
)
|
||||
{
|
||||
int result;
|
||||
Tt_message msg = ttdt_file_request( context, op,
|
||||
theScope, pathname,
|
||||
_ttDtFileRequestCB, &result, 1 );
|
||||
Tt_status status = tt_ptr_error( msg );
|
||||
if (status != TT_OK) {
|
||||
return status;
|
||||
}
|
||||
result = 1;
|
||||
status = tttk_block_while( app2run, &result, msTimeOut );
|
||||
if (status == TT_DESKTOP_ETIMEDOUT) {
|
||||
tttk_message_destroy( msg );
|
||||
return status;
|
||||
}
|
||||
return (Tt_status)-result;
|
||||
}
|
||||
|
||||
Tt_status
|
||||
ttdt_Save(
|
||||
Tt_message context,
|
||||
const char *pathname,
|
||||
Tt_scope theScope,
|
||||
XtAppContext app2run,
|
||||
int msTimeOut
|
||||
)
|
||||
{
|
||||
return _ttdt_file_request( TTDT_SAVE, context, pathname, theScope,
|
||||
app2run, msTimeOut );
|
||||
}
|
||||
|
||||
Tt_status
|
||||
ttdt_Revert(
|
||||
Tt_message context,
|
||||
const char *pathname,
|
||||
Tt_scope theScope,
|
||||
XtAppContext app2run,
|
||||
int msTimeOut
|
||||
)
|
||||
{
|
||||
return _ttdt_file_request( TTDT_REVERT, context, pathname, theScope,
|
||||
app2run, msTimeOut );
|
||||
}
|
||||
161
cde/lib/tt/lib/tttk/ttdtprocid.C
Normal file
161
cde/lib/tt/lib/tttk/ttdtprocid.C
Normal file
@@ -0,0 +1,161 @@
|
||||
//%% (c) Copyright 1993, 1994 Hewlett-Packard Company
|
||||
//%% (c) Copyright 1993, 1994 International Business Machines Corp.
|
||||
//%% (c) Copyright 1993, 1994 Sun Microsystems, Inc.
|
||||
//%% (c) Copyright 1993, 1994 Novell, Inc.
|
||||
//%% $XConsortium: ttdtprocid.C /main/3 1995/10/23 10:32:27 rswiston $
|
||||
/*
|
||||
* @(#)ttdtprocid.C 1.3 93/09/07
|
||||
*
|
||||
* Copyright 1993 Sun Microsystems, Inc. All rights reserved.
|
||||
*/
|
||||
|
||||
#include <limits.h>
|
||||
#include <X11/Intrinsic.h>
|
||||
#include "util/tt_Xlib.h"
|
||||
#include "api/c/api_api.h"
|
||||
#include "tttk/ttdtprocid.h"
|
||||
#include "tttk/tttkmessage.h"
|
||||
#include "tttk/tttkpattern.h"
|
||||
#include "tttk/tttkutils.h"
|
||||
#include "tttk/tttk2free.h"
|
||||
#include "tttk/ttdesktop.h"
|
||||
|
||||
_TtDtProcid::_TtDtProcid(
|
||||
const char *toolName,
|
||||
const char *vendor,
|
||||
const char *version
|
||||
)
|
||||
{
|
||||
// XXX Initialize procid's default contexts from environ(5).
|
||||
_toolname = _tt_strdup( toolName );
|
||||
_vendor = _tt_strdup( vendor );
|
||||
_version = _tt_strdup( version );
|
||||
}
|
||||
|
||||
_TtDtProcid::~_TtDtProcid()
|
||||
{
|
||||
tt_free( _toolname );
|
||||
tt_free( _vendor );
|
||||
tt_free( _version );
|
||||
}
|
||||
|
||||
//
|
||||
// Create patterns for either session_join or message_accept
|
||||
//
|
||||
Tt_pattern *_TtDtProcid::
|
||||
pats_create(
|
||||
Tt_message contract,
|
||||
Ttdt_contract_cb cb,
|
||||
Widget shell,
|
||||
void *clientData
|
||||
) const
|
||||
{
|
||||
int numPats = 11;
|
||||
if (contract == 0) {
|
||||
numPats = 13;
|
||||
}
|
||||
Tt_pattern *pats = (Tt_pattern *)malloc(numPats * sizeof(Tt_pattern));
|
||||
if (pats == 0) {
|
||||
return (Tt_pattern *)tt_error_pointer( TT_ERR_NOMEM );
|
||||
}
|
||||
int i = -1;
|
||||
char *sess = tt_default_session();
|
||||
if (shell != 0) {
|
||||
pats[++i] = ttdt_Get_Geometry_pat( TT_HANDLE, contract,
|
||||
_ttdt_do_GSet_Geometry, shell, 1 );
|
||||
pats[++i] = ttdt_Set_Geometry_pat( TT_HANDLE, contract,
|
||||
_ttdt_do_GSet_Geometry, shell, 1 );
|
||||
pats[++i] = ttdt_Get_Iconified_pat( TT_HANDLE, contract,
|
||||
_ttdt_do_wm_state, shell, 0 );
|
||||
tt_pattern_op_add( pats[i], _ttDtOp( TTDT_GET_MAPPED ) );
|
||||
tt_pattern_session_add( pats[i], sess );
|
||||
tt_pattern_register( pats[i] );
|
||||
pats[++i] = ttdt_Set_Iconified_pat( TT_HANDLE, contract,
|
||||
_ttdt_do_wm_state, shell, 0 );
|
||||
tt_pattern_op_add( pats[i], _ttDtOp( TTDT_SET_MAPPED ) );
|
||||
tt_pattern_session_add( pats[i], sess );
|
||||
tt_pattern_register( pats[i] );
|
||||
pats[++i] = ttdt_Get_XInfo_pat( TT_HANDLE, contract,
|
||||
_ttdt_do_Get_XInfo, shell, 1 );
|
||||
pats[++i] = ttdt_Set_XInfo_pat( TT_HANDLE, contract,
|
||||
_ttdt_do_Set_XInfo, shell, 1 );
|
||||
pats[++i] = _ttdt_pat(TTDT_RAISE, _ttdt_contract_cb, TT_HANDLE,
|
||||
contract, _ttdt_do_RaiseLower, shell, 0 );
|
||||
tt_pattern_op_add( pats[i], _ttDtOp( TTDT_LOWER ) );
|
||||
tt_pattern_session_add( pats[i], sess );
|
||||
tt_pattern_register( pats[i] );
|
||||
} else {
|
||||
pats[++i] = ttdt_Get_Geometry_pat( TT_HANDLE, contract,
|
||||
(Ttdt_Geometry_out_cb)cb, clientData, 1 );
|
||||
pats[++i] = ttdt_Set_Geometry_pat( TT_HANDLE, contract,
|
||||
(Ttdt_Geometry_out_cb)cb, clientData, 1 );
|
||||
pats[++i] = ttdt_Get_Iconified_pat( TT_HANDLE, contract,
|
||||
(Ttdt_Iconified_out_cb)cb, clientData, 0 );
|
||||
tt_pattern_op_add( pats[i], _ttDtOp( TTDT_GET_MAPPED ) );
|
||||
tt_pattern_session_add( pats[i], sess );
|
||||
tt_pattern_register( pats[i] );
|
||||
pats[++i] = ttdt_Set_Iconified_pat( TT_HANDLE, contract,
|
||||
(Ttdt_Iconified_out_cb)cb, clientData, 0 );
|
||||
tt_pattern_op_add( pats[i], _ttDtOp( TTDT_SET_MAPPED ) );
|
||||
tt_pattern_session_add( pats[i], sess );
|
||||
tt_pattern_register( pats[i] );
|
||||
pats[++i] = ttdt_Get_XInfo_pat( TT_HANDLE, contract,
|
||||
(Ttdt_XInfo_out_cb)cb, clientData, 1 );
|
||||
pats[++i] = ttdt_Set_XInfo_pat( TT_HANDLE, contract,
|
||||
(Ttdt_XInfo_in_cb)cb, clientData, 1 );
|
||||
pats[++i] = _ttdt_pat(TTDT_RAISE, _ttdt_contract_cb, TT_HANDLE,
|
||||
contract, cb, clientData, 0 );
|
||||
tt_pattern_op_add( pats[i], _ttDtOp( TTDT_LOWER ) );
|
||||
tt_pattern_session_add( pats[i], sess );
|
||||
tt_pattern_register( pats[i] );
|
||||
}
|
||||
void *_clientData = clientData;
|
||||
if (cb == 0) {
|
||||
// No callback, so set up our own client data
|
||||
if (contract == 0) {
|
||||
// tttk will send WM_DELETE_WINDOW to shell...
|
||||
_clientData = shell;
|
||||
} else {
|
||||
// ...but that quits entire app, so do not do it
|
||||
// for ttdt_message_accept(). Seeing no shell,
|
||||
// _ttdt_contract_cb() will fail the Quit.
|
||||
_clientData = 0;
|
||||
}
|
||||
}
|
||||
pats[++i] = _ttdt_pat( TTDT_QUIT, _ttdt_contract_cb, TT_HANDLE,
|
||||
contract, cb, _clientData, 1 );
|
||||
pats[++i] = _ttdt_pat( TTDT_PAUSE, _ttdt_contract_cb, TT_HANDLE,
|
||||
contract, cb, (cb ? clientData : shell), 0 );
|
||||
tt_pattern_op_add( pats[i], _ttDtOp( TTDT_RESUME ));
|
||||
tt_pattern_session_add( pats[i], sess );
|
||||
tt_pattern_register( pats[i] );
|
||||
pats[++i] = _ttdt_pat( TTDT_GET_STATUS, _ttdt_contract_cb, TT_HANDLE,
|
||||
contract, cb, clientData, 1 );
|
||||
if (contract == 0) {
|
||||
pats[++i]= _ttdt_pat( TTDT_DO_COMMAND, _ttdt_contract_cb,
|
||||
TT_HANDLE, contract, cb, clientData, 1 );
|
||||
pats[++i]= _ttdt_pat( TTDT_SET_LOCALE, _ttdt_posix_cb,
|
||||
TT_HANDLE, contract, 0, 0, 0 );
|
||||
tt_pattern_op_add( pats[i], _ttDtOp( TTDT_GET_LOCALE ));
|
||||
tt_pattern_op_add( pats[i], _ttDtOp( TTDT_SET_ENVIRONMENT ));
|
||||
tt_pattern_op_add( pats[i], _ttDtOp( TTDT_GET_ENVIRONMENT ));
|
||||
tt_pattern_op_add( pats[i], _ttDtOp( TTDT_SET_SITUATION ));
|
||||
tt_pattern_op_add( pats[i], _ttDtOp( TTDT_GET_SITUATION ));
|
||||
tt_pattern_op_add( pats[i], _ttDtOp( TTDT_SIGNAL ));
|
||||
tt_pattern_op_add( pats[i], _ttDtOp( TTDT_GET_SYSINFO ));
|
||||
tt_pattern_session_add( pats[i], sess );
|
||||
tt_pattern_register( pats[i] );
|
||||
}
|
||||
pats[++i] = 0;
|
||||
Tt_pattern *pat = pats;
|
||||
while (*pat != 0) {
|
||||
Tt_status status = tt_ptr_error( *pat );
|
||||
if (status != TT_OK) {
|
||||
_tttk_patterns_destroy( pats );
|
||||
return (Tt_pattern *)tt_error_pointer( status );
|
||||
}
|
||||
pat++;
|
||||
}
|
||||
tt_free( sess );
|
||||
return pats;
|
||||
}
|
||||
43
cde/lib/tt/lib/tttk/ttdtprocid.h
Normal file
43
cde/lib/tt/lib/tttk/ttdtprocid.h
Normal file
@@ -0,0 +1,43 @@
|
||||
/*%% (c) Copyright 1993, 1994 Hewlett-Packard Company */
|
||||
/*%% (c) Copyright 1993, 1994 International Business Machines Corp. */
|
||||
/*%% (c) Copyright 1993, 1994 Sun Microsystems, Inc. */
|
||||
/*%% (c) Copyright 1993, 1994 Novell, Inc. */
|
||||
/*%% $XConsortium: ttdtprocid.h /main/3 1995/10/23 10:32:34 rswiston $ */
|
||||
/* -*-C++-*-
|
||||
*
|
||||
* @(#)ttdtprocid.h 1.3 93/09/07
|
||||
*
|
||||
* Copyright 1993 Sun Microsystems, Inc. All rights reserved.
|
||||
*/
|
||||
#ifndef ttdtprocid_h
|
||||
#define ttdtprocid_h
|
||||
|
||||
#include "util/tt_new.h"
|
||||
#include "tttk/tttk.h"
|
||||
|
||||
class _TtDtProcid: public _Tt_allocated {
|
||||
public:
|
||||
_TtDtProcid(
|
||||
const char *toolName,
|
||||
const char *vendor,
|
||||
const char *version
|
||||
);
|
||||
~_TtDtProcid();
|
||||
|
||||
const char *toolname() const {return _toolname;}
|
||||
const char *vendor() const {return _vendor;}
|
||||
const char *version() const {return _version;}
|
||||
|
||||
Tt_pattern *pats_create(
|
||||
Tt_message contract,
|
||||
Ttdt_contract_cb cb,
|
||||
Widget shell,
|
||||
void *clientData
|
||||
) const;
|
||||
private:
|
||||
char *_toolname;
|
||||
char *_vendor;
|
||||
char *_version;
|
||||
};
|
||||
|
||||
#endif
|
||||
539
cde/lib/tt/lib/tttk/ttmedia.C
Normal file
539
cde/lib/tt/lib/tttk/ttmedia.C
Normal file
@@ -0,0 +1,539 @@
|
||||
//%% (c) Copyright 1993, 1994 Hewlett-Packard Company
|
||||
//%% (c) Copyright 1993, 1994 International Business Machines Corp.
|
||||
//%% (c) Copyright 1993, 1994 Sun Microsystems, Inc.
|
||||
//%% (c) Copyright 1993, 1994 Novell, Inc.
|
||||
//%% $XConsortium: ttmedia.C /main/3 1995/10/23 10:32:41 rswiston $
|
||||
#include "api/c/tt_c.h"
|
||||
#include "util/tt_gettext.h"
|
||||
#include "tttk/tttk.h"
|
||||
#include "tttk/ttdesktop.h"
|
||||
#include "tttk/tttkmessage.h"
|
||||
#include "tttk/tttkpattern.h"
|
||||
#include "tttk/tttkutils.h"
|
||||
#include "tttk/tttk2free.h"
|
||||
|
||||
Tt_status _tt_ptype_opnum_user_set(const char *ptype, int opnum,
|
||||
void *clientdata);
|
||||
void * _tt_ptype_opnum_user(const char *ptype, int opnum);
|
||||
|
||||
class _Ttmedia_ptype_info: public _Tt_allocated {
|
||||
public:
|
||||
_Ttmedia_ptype_info(
|
||||
Ttmedia_load_pat_cb loadCB,
|
||||
void *clientData
|
||||
);
|
||||
|
||||
Ttmedia_load_pat_cb _loadCB;
|
||||
void *_clientData;
|
||||
};
|
||||
|
||||
_Ttmedia_ptype_info::_Ttmedia_ptype_info(
|
||||
Ttmedia_load_pat_cb loadCB,
|
||||
void *clientData)
|
||||
{
|
||||
_loadCB = loadCB;
|
||||
_clientData = clientData;
|
||||
}
|
||||
|
||||
Tt_message
|
||||
ttMediaLoadPatCB(
|
||||
Tt_message msg,
|
||||
Tt_pattern ,
|
||||
Ttmedia_load_pat_cb callback,
|
||||
void *clientData,
|
||||
Tttk_op op,
|
||||
int counterfoilArg = -1,
|
||||
int docNameArg = -1
|
||||
)
|
||||
{
|
||||
static const char here[] = "ttMediaLoadPatCB()";
|
||||
unsigned char *contents = 0;
|
||||
int len = 0;
|
||||
char *file = 0;
|
||||
Tt_status status;
|
||||
Tt_status diagnosis = TT_OK;
|
||||
const char *diagnosisStr= 0;
|
||||
char *counterfoil = 0;
|
||||
char *docName = 0;
|
||||
|
||||
if (callback == 0) {
|
||||
return msg;
|
||||
}
|
||||
status = tt_message_arg_bval( msg, 0, &contents, &len );
|
||||
if (status != TT_OK) {
|
||||
diagnosis = status;
|
||||
diagnosisStr = "tt_message_arg_bval( msg, 0 )";
|
||||
} else if (len == 0) {
|
||||
//
|
||||
// contents arg empty; contents are in named file
|
||||
//
|
||||
file = tt_message_file( msg );
|
||||
status = tt_ptr_error( file );
|
||||
if (status != TT_OK) {
|
||||
file = 0;
|
||||
diagnosis = status;
|
||||
diagnosisStr = "tt_message_file()";
|
||||
} else if ( (file == 0)
|
||||
&& (tt_message_arg_mode( msg, 0 ) != TT_OUT)
|
||||
&& (op != TTME_INSTANTIATE))
|
||||
{
|
||||
diagnosis = TT_DESKTOP_ENODATA;
|
||||
diagnosisStr = catgets( _ttcatd, 1, 25,
|
||||
"empty document and no file" );
|
||||
}
|
||||
}
|
||||
if (counterfoilArg >= 0) {
|
||||
counterfoil = tt_message_arg_val( msg, counterfoilArg );
|
||||
status = tt_ptr_error( counterfoil );
|
||||
if (status != TT_OK) {
|
||||
_ttDtPrintStatus( here,
|
||||
catgets( _ttcatd, 1, 26,
|
||||
"cannot get messageID; "
|
||||
"operation may not be "
|
||||
"cancel-able, because "
|
||||
"tt_message_arg_val()"),
|
||||
status );
|
||||
counterfoil = 0; // charge ahead
|
||||
}
|
||||
}
|
||||
if (docNameArg > 0) {
|
||||
docName = tt_message_arg_val( msg, docNameArg );
|
||||
status = tt_ptr_error( docName );
|
||||
if (status != TT_OK) {
|
||||
_ttDtPrintStatus( here,
|
||||
catgets( _ttcatd, 1, 27,
|
||||
"cannot get title; document "
|
||||
"will be untitled because "
|
||||
"tt_message_arg_val()" ),
|
||||
status );
|
||||
docName = 0; // charge ahead
|
||||
}
|
||||
}
|
||||
msg = (*callback)( msg, clientData, op, diagnosis, contents,
|
||||
len, file, docName );
|
||||
status = tt_ptr_error( msg );
|
||||
if ((status == TT_OK) && (msg != 0) && (diagnosis != TT_OK)) {
|
||||
tttk_message_fail( msg, diagnosis, diagnosisStr, 1 );
|
||||
return (Tt_message)tt_error_pointer( diagnosis );
|
||||
} else {
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
|
||||
Tt_callback_action
|
||||
_ttMeOpnumCB(
|
||||
Tt_message msg,
|
||||
Tt_pattern pat
|
||||
)
|
||||
{
|
||||
static const char here[] = "_ttMeOpnumCB()";
|
||||
|
||||
if ( (tt_message_state( msg ) != TT_SENT)
|
||||
|| (tt_message_class( msg ) != TT_REQUEST )
|
||||
|| (! _tttk_message_am_handling( msg )))
|
||||
{
|
||||
return TT_CALLBACK_CONTINUE;
|
||||
}
|
||||
int opnum = tt_message_opnum( msg );
|
||||
Tt_status status = tt_int_error( opnum );
|
||||
if ((status != TT_OK) && (opnum != -1)) {
|
||||
return TT_CALLBACK_PROCESSED;
|
||||
}
|
||||
int base = opnum - (opnum % 1000);
|
||||
int offset = opnum - base;
|
||||
char *ptype = tt_message_handler_ptype( msg );
|
||||
_Ttmedia_ptype_info *i = (_Ttmedia_ptype_info *)
|
||||
_tt_ptype_opnum_user( ptype, base );
|
||||
tt_free( ptype );
|
||||
status = tt_ptr_error( i );
|
||||
if ((status != TT_OK) || (i == 0)) {
|
||||
return TT_CALLBACK_PROCESSED;
|
||||
}
|
||||
switch (offset) {
|
||||
case 1:
|
||||
msg = ttMediaLoadPatCB( msg, pat, i->_loadCB, i->_clientData,
|
||||
TTME_DISPLAY );
|
||||
break;
|
||||
case 2:
|
||||
msg = ttMediaLoadPatCB( msg, pat, i->_loadCB, i->_clientData,
|
||||
TTME_DISPLAY, 1 );
|
||||
break;
|
||||
case 3:
|
||||
msg = ttMediaLoadPatCB( msg, pat, i->_loadCB, i->_clientData,
|
||||
TTME_DISPLAY, -1, 1 );
|
||||
break;
|
||||
case 4:
|
||||
msg = ttMediaLoadPatCB( msg, pat, i->_loadCB, i->_clientData,
|
||||
TTME_DISPLAY, 1, 2 );
|
||||
break;
|
||||
case 101:
|
||||
msg = ttMediaLoadPatCB( msg, pat, i->_loadCB, i->_clientData,
|
||||
TTME_EDIT );
|
||||
break;
|
||||
case 102:
|
||||
msg = ttMediaLoadPatCB( msg, pat, i->_loadCB, i->_clientData,
|
||||
TTME_EDIT, 1 );
|
||||
break;
|
||||
case 103:
|
||||
msg = ttMediaLoadPatCB( msg, pat, i->_loadCB, i->_clientData,
|
||||
TTME_EDIT, -1, 1 );
|
||||
break;
|
||||
case 104:
|
||||
msg = ttMediaLoadPatCB( msg, pat, i->_loadCB, i->_clientData,
|
||||
TTME_EDIT, 1, 2 );
|
||||
break;
|
||||
case 201:
|
||||
msg = ttMediaLoadPatCB( msg, pat, i->_loadCB, i->_clientData,
|
||||
TTME_COMPOSE );
|
||||
break;
|
||||
case 202:
|
||||
msg = ttMediaLoadPatCB( msg, pat, i->_loadCB, i->_clientData,
|
||||
TTME_COMPOSE, 1 );
|
||||
break;
|
||||
case 203:
|
||||
msg = ttMediaLoadPatCB( msg, pat, i->_loadCB, i->_clientData,
|
||||
TTME_COMPOSE, -1, 1 );
|
||||
break;
|
||||
case 204:
|
||||
msg = ttMediaLoadPatCB( msg, pat, i->_loadCB, i->_clientData,
|
||||
TTME_COMPOSE, 1, 2 );
|
||||
break;
|
||||
case 301:
|
||||
msg = ttMediaLoadPatCB( msg, pat, i->_loadCB, i->_clientData,
|
||||
TTME_MAIL );
|
||||
break;
|
||||
case 311:
|
||||
msg = ttMediaLoadPatCB( msg, pat, i->_loadCB, i->_clientData,
|
||||
TTME_MAIL_EDIT );
|
||||
break;
|
||||
case 313:
|
||||
msg = ttMediaLoadPatCB( msg, pat, i->_loadCB, i->_clientData,
|
||||
TTME_MAIL_EDIT, -1, 1 );
|
||||
break;
|
||||
case 321:
|
||||
msg = ttMediaLoadPatCB( msg, pat, i->_loadCB, i->_clientData,
|
||||
TTME_MAIL_COMPOSE );
|
||||
break;
|
||||
case 323:
|
||||
msg = ttMediaLoadPatCB( msg, pat, i->_loadCB, i->_clientData,
|
||||
TTME_MAIL_COMPOSE, -1, 1 );
|
||||
break;
|
||||
case 401:
|
||||
msg = ttMediaLoadPatCB( msg, pat, i->_loadCB, i->_clientData,
|
||||
TTME_INSTANTIATE );
|
||||
break;
|
||||
// Add any new offsets to ttmedia_ptype_declare()
|
||||
default:
|
||||
_ttDtPrintInt( here,
|
||||
catgets(_ttcatd, 1, 28, "unknown opnum offset"),
|
||||
offset );
|
||||
return TT_CALLBACK_CONTINUE;
|
||||
}
|
||||
return _ttDtCallbackAction( msg );
|
||||
}
|
||||
|
||||
Tt_status
|
||||
ttmedia_ptype_declare(
|
||||
const char *ptype,
|
||||
int baseOpnum,
|
||||
Ttmedia_load_pat_cb loadCB,
|
||||
void *clientData,
|
||||
int declare
|
||||
)
|
||||
{
|
||||
Tt_status status;
|
||||
|
||||
/*
|
||||
* XXX Join default contexts of current default procid.
|
||||
*/
|
||||
for (int i = 0; i <= 200; i += 100) {
|
||||
for (int j = 1; j <= 4; j++) {
|
||||
status = tt_ptype_opnum_callback_add( ptype,
|
||||
i + j + baseOpnum, _ttMeOpnumCB );
|
||||
if (status != TT_OK) {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
}
|
||||
status = tt_ptype_opnum_callback_add( ptype, 301, _ttMeOpnumCB );
|
||||
if (status != TT_OK) return status;
|
||||
status = tt_ptype_opnum_callback_add( ptype, 311, _ttMeOpnumCB );
|
||||
if (status != TT_OK) return status;
|
||||
status = tt_ptype_opnum_callback_add( ptype, 313, _ttMeOpnumCB );
|
||||
if (status != TT_OK) return status;
|
||||
status = tt_ptype_opnum_callback_add( ptype, 321, _ttMeOpnumCB );
|
||||
if (status != TT_OK) return status;
|
||||
status = tt_ptype_opnum_callback_add( ptype, 323, _ttMeOpnumCB );
|
||||
if (status != TT_OK) return status;
|
||||
status = tt_ptype_opnum_callback_add( ptype, 401, _ttMeOpnumCB );
|
||||
if (status != TT_OK) return status;
|
||||
//
|
||||
// Like opnum callbacks themselves, this memory lives as long
|
||||
// as the procid.
|
||||
//
|
||||
_Ttmedia_ptype_info *info =
|
||||
new _Ttmedia_ptype_info( loadCB, clientData );
|
||||
status = _tt_ptype_opnum_user_set( ptype, baseOpnum, info );
|
||||
if (status != TT_OK) {
|
||||
return status;
|
||||
}
|
||||
if (declare) {
|
||||
status = tt_ptype_declare( ptype );
|
||||
if (status != TT_OK) {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
return TT_OK;
|
||||
}
|
||||
|
||||
//
|
||||
// Parse Display/Edit/Compose reply, or Deposit request, and pass to
|
||||
// client callback.
|
||||
//
|
||||
static Tt_message
|
||||
_ttMediaLoadMsgCB(
|
||||
Tt_message msg,
|
||||
Tt_pattern ,
|
||||
void *clientCB,
|
||||
void *clientData
|
||||
)
|
||||
{
|
||||
char *opname = tt_message_op( msg );
|
||||
Tttk_op op = tttk_string_op( opname );
|
||||
tt_free( opname );
|
||||
int final = _tttk_message_in_final_state( msg );
|
||||
switch (tt_message_state( msg )) {
|
||||
case TT_STARTED:
|
||||
case TT_QUEUED:
|
||||
return 0;
|
||||
case TT_SENT:
|
||||
if (op != TTME_DEPOSIT) {
|
||||
// This address space is handler, but is not
|
||||
// through handling, so continue.
|
||||
return msg;
|
||||
}
|
||||
break;
|
||||
}
|
||||
Tt_pattern depositPat = 0;
|
||||
if (final) {
|
||||
depositPat =
|
||||
(Tt_pattern)tt_message_user( msg, _TttkDepositPatKey );
|
||||
}
|
||||
Ttmedia_load_msg_cb _cb = (Ttmedia_load_msg_cb)clientCB;
|
||||
if (_cb != 0) {
|
||||
_TttkItem2Free fuse = msg;
|
||||
unsigned char *contents = 0;
|
||||
int len = 0;
|
||||
Tt_status status;
|
||||
status = tt_message_arg_bval( msg, 0, &contents, &len );
|
||||
if (status != TT_OK) {
|
||||
return (Tt_message)tt_error_pointer( status );
|
||||
}
|
||||
char *file = tt_message_file( msg );
|
||||
if (tt_ptr_error( file ) != TT_OK) {
|
||||
file = 0;
|
||||
}
|
||||
fuse = (caddr_t)0;
|
||||
msg = (*_cb)( msg, clientData, op, contents, len, file );
|
||||
}
|
||||
if (final) {
|
||||
//
|
||||
// The reply has now come in, so there can be no
|
||||
// more Deposit requests on this buffer.
|
||||
//
|
||||
tt_pattern_destroy( depositPat );
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
static Tt_pattern
|
||||
ttmedia_Deposit_pat(
|
||||
Tt_category category,
|
||||
const char *media_type,
|
||||
Tt_message commission,
|
||||
const char *buffer_id,
|
||||
Ttmedia_load_msg_cb clientcb,
|
||||
void *clientdata,
|
||||
int register_it
|
||||
)
|
||||
{
|
||||
Tt_pattern pat = _ttDtPatternCreate( category, TT_SESSION,
|
||||
register_it, 0, TTME_DEPOSIT,
|
||||
_ttMediaLoadMsgCB, clientcb,
|
||||
clientdata, 0 );
|
||||
Tt_status status = tt_ptr_error( pat );
|
||||
if (status != TT_OK) {
|
||||
return pat;
|
||||
}
|
||||
_TttkItem2Free fuse = pat;
|
||||
status = tt_pattern_arg_add( pat, TT_IN, media_type, 0 );
|
||||
if (status != TT_OK) {
|
||||
return (Tt_pattern)tt_error_pointer( status );
|
||||
}
|
||||
if (buffer_id != 0) {
|
||||
status = tt_pattern_arg_add( pat, TT_IN, "bufferID",
|
||||
buffer_id );
|
||||
if (status != TT_OK) {
|
||||
return (Tt_pattern)tt_error_pointer( status );
|
||||
}
|
||||
}
|
||||
fuse = (caddr_t)0;
|
||||
return _ttDesktopPatternFinish( pat, commission, register_it );
|
||||
}
|
||||
|
||||
Tt_message
|
||||
ttmedia_load(
|
||||
Tt_message context,
|
||||
Ttmedia_load_msg_cb cb,
|
||||
void *clientData,
|
||||
Tttk_op op,
|
||||
const char *mediaType,
|
||||
const unsigned char *contents,
|
||||
int len,
|
||||
const char *file,
|
||||
const char *docname,
|
||||
int send
|
||||
)
|
||||
{
|
||||
Tt_message msg = _ttDtPMessageCreate( context, TT_REQUEST, TT_SESSION,
|
||||
0, op, _ttMediaLoadMsgCB, cb, clientData );
|
||||
Tt_status status = tt_ptr_error( msg );
|
||||
if (status != TT_OK) {
|
||||
return msg;
|
||||
}
|
||||
_TttkItem2Free fuse = msg;
|
||||
Tt_mode mode;
|
||||
switch (op) {
|
||||
case TTME_DISPLAY:
|
||||
case TTME_MAIL:
|
||||
case TTME_INSTANTIATE:
|
||||
mode = TT_IN;
|
||||
break;
|
||||
case TTME_COMPOSE:
|
||||
case TTME_MAIL_COMPOSE:
|
||||
mode = TT_OUT;
|
||||
break;
|
||||
default:
|
||||
mode = TT_INOUT;
|
||||
break;
|
||||
}
|
||||
status = tt_message_barg_add( msg, mode, mediaType, contents, len );
|
||||
if (status != TT_OK) {
|
||||
return (Tt_message)tt_error_pointer( status );
|
||||
}
|
||||
if (file != 0) {
|
||||
status = tt_message_file_set( msg, file );
|
||||
if (status != TT_OK) {
|
||||
return (Tt_message)tt_error_pointer( status );
|
||||
}
|
||||
}
|
||||
if (docname != 0) {
|
||||
status = tt_message_arg_add( msg, TT_IN, Tttk_title, docname );
|
||||
if (status != TT_OK) {
|
||||
return (Tt_message)tt_error_pointer( status );
|
||||
}
|
||||
}
|
||||
Tt_pattern pat = ttmedia_Deposit_pat( TT_HANDLE, mediaType,
|
||||
msg, 0, cb, clientData, 1 );
|
||||
status = tt_ptr_error( pat );
|
||||
if (status == TT_OK) {
|
||||
// Save the pattern so we can destroy it when
|
||||
// the message reaches a final state.
|
||||
tt_message_user_set( msg, _TttkDepositPatKey, pat );
|
||||
}
|
||||
if (send) {
|
||||
status = tt_message_send( msg );
|
||||
if (status != TT_OK) {
|
||||
return (Tt_message)tt_error_pointer( status );
|
||||
}
|
||||
}
|
||||
fuse = (caddr_t)0;
|
||||
return msg;
|
||||
}
|
||||
|
||||
Tt_status
|
||||
ttmedia_load_reply(
|
||||
Tt_message contract,
|
||||
const unsigned char *newContents,
|
||||
int newLen,
|
||||
int reply_and_destroy
|
||||
)
|
||||
{
|
||||
Tt_status status = TT_OK;
|
||||
status = tt_message_arg_bval_set( contract, 0, newContents, newLen );
|
||||
if (status != TT_OK) {
|
||||
return status;
|
||||
}
|
||||
if (reply_and_destroy) {
|
||||
status = tt_message_reply( contract );
|
||||
if (status != TT_OK) {
|
||||
return status;
|
||||
}
|
||||
tttk_message_destroy( contract );
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
Tt_status
|
||||
ttmedia_Deposit(
|
||||
Tt_message contract,
|
||||
const char *buffer_id,
|
||||
const char *media_type,
|
||||
const unsigned char *new_contents,
|
||||
int new_len,
|
||||
const char *file,
|
||||
XtAppContext app2run,
|
||||
int ms_timeout
|
||||
)
|
||||
{
|
||||
Tt_status status;
|
||||
char *handler = 0;
|
||||
if (buffer_id == 0) {
|
||||
handler = tt_message_sender( contract );
|
||||
status = tt_ptr_error( handler );
|
||||
if (status != TT_OK) {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
int replyStatus = 1;
|
||||
Tt_message msg = _ttDtPMessageCreate( contract, TT_REQUEST, TT_SESSION,
|
||||
handler, TTME_DEPOSIT, _ttTkNoteReplyStatus,
|
||||
0, &replyStatus );
|
||||
tt_free( handler );
|
||||
status = tt_ptr_error( msg );
|
||||
if (status != TT_OK) {
|
||||
return status;
|
||||
}
|
||||
_TttkItem2Free fuse = msg;
|
||||
const char *_media_type = media_type;
|
||||
if (media_type == 0) {
|
||||
_media_type = tt_message_arg_type( contract, 0 );
|
||||
}
|
||||
status = tt_message_barg_add( msg, TT_IN, _media_type, new_contents,
|
||||
new_len );
|
||||
if (media_type == 0) {
|
||||
tt_free( (caddr_t)_media_type );
|
||||
}
|
||||
if (status != TT_OK) {
|
||||
return status;
|
||||
}
|
||||
if (file != 0) {
|
||||
status = tt_message_file_set( msg, file );
|
||||
if (status != TT_OK) {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
msg = _ttDesktopMessageFinish( msg, contract, 1 );
|
||||
status = tt_ptr_error( msg );
|
||||
if (status != TT_OK) {
|
||||
return status;
|
||||
}
|
||||
fuse = (caddr_t)0;
|
||||
status = tttk_block_while( app2run, &replyStatus, ms_timeout );
|
||||
if (status == TT_DESKTOP_ETIMEDOUT) {
|
||||
// See comment in ttdt_Get_Modified()
|
||||
tttk_message_destroy( msg );
|
||||
return status;
|
||||
}
|
||||
return (Tt_status)-replyStatus;
|
||||
}
|
||||
502
cde/lib/tt/lib/tttk/tttk.C
Normal file
502
cde/lib/tt/lib/tttk/tttk.C
Normal file
@@ -0,0 +1,502 @@
|
||||
//%% (c) Copyright 1993, 1994 Hewlett-Packard Company
|
||||
//%% (c) Copyright 1993, 1994 International Business Machines Corp.
|
||||
//%% (c) Copyright 1993, 1994 Sun Microsystems, Inc.
|
||||
//%% (c) Copyright 1993, 1994 Novell, Inc.
|
||||
//%% $TOG: tttk.C /main/5 1999/09/14 13:00:44 mgreess $
|
||||
#if defined(linux)
|
||||
# include <sys/poll.h>
|
||||
#else
|
||||
# include <poll.h>
|
||||
#endif
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <limits.h>
|
||||
#include "api/c/tt_c.h"
|
||||
#include "util/tt_gettext.h"
|
||||
#include "util/tt_Xlib.h"
|
||||
#include "util/tt_port.h"
|
||||
#include "tttk/tttk.h"
|
||||
#include "tttk/tttk2free.h"
|
||||
#include "tttk/tttkutils.h"
|
||||
#include "tttk/tttkpattern.h"
|
||||
#include "tttk/ttdtprocid.h"
|
||||
#include "tttk/ttdesktop.h"
|
||||
|
||||
extern Tt_status _tt_errno_status( int err_no );
|
||||
|
||||
const char *Tttk_integer = "integer";
|
||||
const char *Tttk_string = "string";
|
||||
const char *Tttk_boolean = "boolean";
|
||||
const char *Tttk_file = "File";
|
||||
const char *Tttk_message_id = "messageID";
|
||||
const char *Tttk_title = "title";
|
||||
const char *Tttk_width = "width";
|
||||
const char *Tttk_height = "height";
|
||||
const char *Tttk_xoffset = "xOffset";
|
||||
const char *Tttk_yoffset = "yOffset";
|
||||
|
||||
_TtDtProcid *_ttdtme = 0;
|
||||
|
||||
// API calls below...
|
||||
|
||||
char *
|
||||
ttdt_open(
|
||||
int *ttFD,
|
||||
const char *toolName,
|
||||
const char *vendor,
|
||||
const char *version,
|
||||
int sendStarted
|
||||
)
|
||||
{
|
||||
_ttdtme = new _TtDtProcid( toolName, vendor, version );
|
||||
if (_ttdtme == 0) {
|
||||
return (char *)tt_error_pointer( TT_ERR_NOMEM );
|
||||
}
|
||||
char *procID = tt_open();
|
||||
Tt_status status = tt_ptr_error( procID );
|
||||
if (status != TT_OK) {
|
||||
return procID;
|
||||
}
|
||||
*ttFD = tt_fd();
|
||||
status = tt_int_error( *ttFD );
|
||||
if (status != TT_OK) {
|
||||
tt_free( procID );
|
||||
tt_close();
|
||||
return (char *)tt_error_pointer( status );
|
||||
}
|
||||
if (sendStarted) {
|
||||
ttdt_Started( 0, toolName, vendor, version, 1 );
|
||||
}
|
||||
return procID;
|
||||
}
|
||||
|
||||
//
|
||||
// A callback used internally to pick geometry info out of
|
||||
// a Get_Geometry reply and stuff it into (DisplayInfo *)clientData.
|
||||
//
|
||||
static Tt_message
|
||||
_ttDtApplyGeom(
|
||||
Tt_message msg,
|
||||
void *clientData,
|
||||
Tt_message ,
|
||||
int width,
|
||||
int height,
|
||||
int xOffset,
|
||||
int yOffset
|
||||
)
|
||||
{
|
||||
DisplayInfo *info = (DisplayInfo *)clientData;
|
||||
if (info != 0) {
|
||||
info->repliesOutStanding--;
|
||||
info->width = width;
|
||||
info->height = height;
|
||||
info->xOffset = xOffset;
|
||||
info->yOffset = yOffset;
|
||||
}
|
||||
tttk_message_destroy( msg );
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
// A TtDtGetXInfoMsgCB used internally to pick X11 info out of
|
||||
// a Get_XInfo reply and stuff it into (DisplayInfo *)clientData.
|
||||
//
|
||||
static Tt_message
|
||||
_ttDtApplyXInfo(
|
||||
Tt_message msg,
|
||||
void *clientData,
|
||||
Tt_message ,
|
||||
char *display,
|
||||
int, //visual
|
||||
int //depth
|
||||
)
|
||||
{
|
||||
DisplayInfo *info = (DisplayInfo *)clientData;
|
||||
if (info != 0) {
|
||||
info->repliesOutStanding--;
|
||||
info->display = display;
|
||||
}
|
||||
tttk_message_destroy( msg );
|
||||
return 0;
|
||||
}
|
||||
|
||||
Tt_status
|
||||
ttdt_sender_imprint_on(
|
||||
const char *handler,
|
||||
Tt_message commission,
|
||||
char **pDisplay,
|
||||
int *width,
|
||||
int *height,
|
||||
int *xOffset,
|
||||
int *yOffset,
|
||||
XtAppContext app2run,
|
||||
int msTimeOut
|
||||
)
|
||||
{
|
||||
Tt_status status;
|
||||
Tt_message msg;
|
||||
DisplayInfo info;
|
||||
info.repliesOutStanding = 0;
|
||||
info.width = -1;
|
||||
info.height = -1;
|
||||
info.xOffset = INT_MAX;
|
||||
info.yOffset = INT_MAX;
|
||||
info.display = 0;
|
||||
if ((width != 0) || (height != 0) || (xOffset != 0) || (yOffset != 0)){
|
||||
msg = ttdt_Get_Geometry( handler, commission,
|
||||
_ttDtApplyGeom, &info, 1 );
|
||||
status = tt_ptr_error( msg );
|
||||
if (status == TT_OK) {
|
||||
info.repliesOutStanding++;
|
||||
}
|
||||
}
|
||||
// XXX sending XInfo before Geometry causes segv in handler!? Saberize.
|
||||
msg = ttdt_Get_XInfo( handler, commission,
|
||||
_ttDtApplyXInfo, &info, 1);
|
||||
status = tt_ptr_error( msg );
|
||||
if (status == TT_OK) {
|
||||
info.repliesOutStanding++;
|
||||
}
|
||||
msg = ttdt_Get_Locale( handler, commission, 0, &info, 0, 1 );
|
||||
status = tt_ptr_error( msg );
|
||||
if (status == TT_OK) {
|
||||
info.repliesOutStanding++;
|
||||
}
|
||||
msg = ttdt_Get_Situation( handler, commission, 0, &info, 1 );
|
||||
status = tt_ptr_error( msg );
|
||||
if (status == TT_OK) {
|
||||
info.repliesOutStanding++;
|
||||
}
|
||||
if (info.repliesOutStanding == 0) {
|
||||
return status;
|
||||
}
|
||||
status = tttk_block_while( app2run,
|
||||
&info.repliesOutStanding, msTimeOut );
|
||||
if (pDisplay == 0) {
|
||||
if (info.display != 0) {
|
||||
_tt_putenv( "DISPLAY", info.display );
|
||||
}
|
||||
tt_free( info.display );
|
||||
} else {
|
||||
*pDisplay = info.display;
|
||||
}
|
||||
if (width != 0) {
|
||||
*width = info.width;
|
||||
}
|
||||
if (height != 0) {
|
||||
*height = info.height;
|
||||
}
|
||||
if (xOffset != 0) {
|
||||
*xOffset = info.xOffset;
|
||||
}
|
||||
if (yOffset != 0) {
|
||||
*yOffset = info.yOffset;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
Tt_status
|
||||
ttdt_close(
|
||||
const char *procid,
|
||||
const char *newProcid,
|
||||
int sendStopped
|
||||
)
|
||||
{
|
||||
Tt_status status;
|
||||
if (procid != 0) {
|
||||
status = tt_default_procid_set( procid );
|
||||
if (status != TT_OK) {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
if (sendStopped) {
|
||||
ttdt_Stopped( 0, _ttdtme->toolname(), _ttdtme->vendor(),
|
||||
_ttdtme->version(), 1 );
|
||||
}
|
||||
status = tt_close();
|
||||
if (status != TT_OK) {
|
||||
return status;
|
||||
}
|
||||
if (newProcid != 0) {
|
||||
status = tt_default_procid_set( newProcid );
|
||||
if (status != TT_OK) {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
return TT_OK;
|
||||
}
|
||||
|
||||
Tt_pattern *
|
||||
ttdt_session_join(
|
||||
const char *sessid,
|
||||
Ttdt_contract_cb cb,
|
||||
Widget shell,
|
||||
void *clientdata,
|
||||
int join
|
||||
)
|
||||
{
|
||||
Tt_status status;
|
||||
_TttkItem2Free item2free;
|
||||
if (sessid == 0) {
|
||||
sessid = tt_default_session();
|
||||
status = tt_ptr_error( sessid );
|
||||
if (status != TT_OK) {
|
||||
return (Tt_pattern *)tt_error_pointer( status );
|
||||
}
|
||||
item2free = (char *)sessid;
|
||||
}
|
||||
Tt_pattern *pats = _ttdtme->pats_create( 0, cb, shell, clientdata );
|
||||
if (join) {
|
||||
status = tt_session_join( sessid );
|
||||
if (status != TT_OK) {
|
||||
return (Tt_pattern *)tt_error_pointer( status );
|
||||
}
|
||||
}
|
||||
return pats;
|
||||
}
|
||||
|
||||
Tt_status
|
||||
ttdt_session_quit(
|
||||
const char *sessid,
|
||||
Tt_pattern *pats,
|
||||
int quit
|
||||
)
|
||||
{
|
||||
Tt_status status;
|
||||
_TttkItem2Free item2free;
|
||||
if (sessid == 0) {
|
||||
sessid = tt_default_session();
|
||||
status = tt_ptr_error( sessid );
|
||||
if (status != TT_OK) {
|
||||
return status;
|
||||
}
|
||||
item2free = (char *)sessid;
|
||||
}
|
||||
status = _tttk_patterns_destroy( pats );
|
||||
if (status != TT_OK) {
|
||||
return status;
|
||||
}
|
||||
if (quit) {
|
||||
status = tt_session_quit( sessid );
|
||||
if (status != TT_OK) {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
Tt_pattern *
|
||||
ttdt_message_accept(
|
||||
Tt_message contract,
|
||||
Ttdt_contract_cb cb,
|
||||
Widget shell,
|
||||
void *clientData,
|
||||
int accept,
|
||||
int sendStatus
|
||||
)
|
||||
{
|
||||
Tt_status status;
|
||||
if (accept) {
|
||||
status = tt_message_accept( contract );
|
||||
if (status != TT_OK) {
|
||||
// Not fatal
|
||||
}
|
||||
}
|
||||
Tt_pattern *pats = _ttdtme->pats_create( contract, cb, shell,
|
||||
clientData );
|
||||
status = tt_ptr_error( pats );
|
||||
if (status == TT_OK) {
|
||||
tt_message_user_set( contract, _TttkContractKey, pats );
|
||||
}
|
||||
if (sendStatus) {
|
||||
ttdt_Status( contract, contract,
|
||||
catgets( _ttcatd, 1, 24, "Accepting request" ),
|
||||
_ttdtme->toolname(), _ttdtme->vendor(),
|
||||
_ttdtme->version(), 1 );
|
||||
}
|
||||
return pats;
|
||||
}
|
||||
|
||||
Tt_pattern *
|
||||
ttdt_subcontract_manage(
|
||||
Tt_message subcontract,
|
||||
Ttdt_contract_cb cb,
|
||||
Widget shell,
|
||||
void *clientData
|
||||
)
|
||||
{
|
||||
const int numPats = 4;
|
||||
Tt_pattern *pats = (Tt_pattern *)malloc(numPats * sizeof(Tt_pattern));
|
||||
if (pats == 0) {
|
||||
return (Tt_pattern *)tt_error_pointer( TT_ERR_NOMEM );
|
||||
}
|
||||
pats[ 0 ] = 0;
|
||||
if (shell != 0) {
|
||||
pats[0] = ttdt_Get_Geometry_pat( TT_HANDLE, subcontract,
|
||||
_ttdt_do_GSet_Geometry, shell, 1 );
|
||||
pats[1] = ttdt_Get_XInfo_pat( TT_HANDLE, subcontract,
|
||||
_ttdt_do_Get_XInfo, shell, 1 );
|
||||
} else {
|
||||
pats[0] = ttdt_Get_Geometry_pat( TT_HANDLE, subcontract,
|
||||
(Ttdt_Geometry_out_cb)cb, clientData, 1 );
|
||||
pats[1] = ttdt_Get_XInfo_pat( TT_HANDLE, subcontract,
|
||||
(Ttdt_XInfo_out_cb)cb, clientData, 1 );
|
||||
}
|
||||
pats[2] = _ttdt_pat( TTDT_STATUS, _ttdt_contract_cb, TT_OBSERVE,
|
||||
subcontract, cb, clientData, 1 );
|
||||
pats[ numPats - 1 ] = 0;
|
||||
for (int i = 0; i < numPats; i++) {
|
||||
Tt_status status = tt_ptr_error( pats[ i ] );
|
||||
if (status != TT_OK) {
|
||||
_tttk_patterns_destroy( pats );
|
||||
free( pats );
|
||||
return (Tt_pattern *)tt_error_pointer( status );
|
||||
}
|
||||
}
|
||||
tt_message_user_set( subcontract, _TttkSubContractKey, pats );
|
||||
return pats;
|
||||
}
|
||||
|
||||
void
|
||||
tttk_Xt_input_handler(
|
||||
XtPointer procid,
|
||||
int *,
|
||||
XtInputId *id
|
||||
)
|
||||
{
|
||||
static const char *here = "ttdt_Xt_input_handler()";
|
||||
|
||||
Tt_message msg = _tttk_message_receive( (char *)procid );
|
||||
Tt_status status = tt_ptr_error( msg );
|
||||
if (status != TT_OK) {
|
||||
_ttDtPrintStatus( here, "tttk_message_receive()", status);
|
||||
if (status == TT_ERR_NOMP) {
|
||||
ttdt_close( (const char *)procid, 0, 0 );
|
||||
if (! _tt_load_xt()) {
|
||||
return;
|
||||
}
|
||||
if (id != 0) {
|
||||
CALLXT(XtRemoveInput)( *id );
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (msg == 0) {
|
||||
return;
|
||||
}
|
||||
status = tttk_message_abandon( msg );
|
||||
if (status != TT_OK) {
|
||||
_ttDtPrintStatus( here, "tttk_message_abandon()", status );
|
||||
}
|
||||
}
|
||||
|
||||
Tt_status
|
||||
_tttk_block_procid_while(
|
||||
const int *blocked,
|
||||
int msTimeOut
|
||||
)
|
||||
{
|
||||
int fd = tt_fd();
|
||||
Tt_status status = tt_int_error( fd );
|
||||
if (status != TT_OK) {
|
||||
return status;
|
||||
}
|
||||
while ((blocked == 0) || (*blocked > 0)) {
|
||||
struct pollfd fds[ 1 ];
|
||||
fds[0].fd = fd;
|
||||
fds[0].events = POLLIN;
|
||||
int activeFDs = poll( fds, 1, msTimeOut );
|
||||
if (activeFDs == 0) {
|
||||
return TT_DESKTOP_ETIMEDOUT;
|
||||
} else if (activeFDs < 0) {
|
||||
if ((blocked != 0) && (*blocked)) {
|
||||
_ttDtPError( "_tttk_block_procid_while()",
|
||||
"poll()" );
|
||||
return _tt_errno_status( errno );
|
||||
}
|
||||
}
|
||||
if (fds[ 0 ].revents != 0) {
|
||||
//
|
||||
// AIX has fd in struct pollfd as a long, not
|
||||
// an int, and complains (justifiably) when
|
||||
// long* is passed when int* is needed. So use
|
||||
// call-by-value-return instead of
|
||||
// call-by-reference. Hey,
|
||||
// tttk_Xt_input_handler doesn\'t use the
|
||||
// value anyway...
|
||||
//
|
||||
int fd_temp;
|
||||
fd_temp = fds[0].fd;
|
||||
tttk_Xt_input_handler( 0, &fd_temp, 0 );
|
||||
fds[0].fd = fd_temp;
|
||||
}
|
||||
if (msTimeOut == 0) {
|
||||
return TT_OK;
|
||||
}
|
||||
if (msTimeOut == 0) {
|
||||
return TT_OK;
|
||||
}
|
||||
}
|
||||
return TT_OK;
|
||||
}
|
||||
|
||||
void
|
||||
_tttk_timed_out(
|
||||
XtPointer p_timed_out,
|
||||
XtIntervalId
|
||||
)
|
||||
{
|
||||
*(int *)p_timed_out = 1;
|
||||
}
|
||||
|
||||
Tt_status
|
||||
_tttk_block_app_while(
|
||||
XtAppContext app2run,
|
||||
const int *blocked,
|
||||
int msTimeOut
|
||||
)
|
||||
{
|
||||
XtIntervalId alarm = 0;
|
||||
if ((blocked != 0) && (*blocked <= 0)) return TT_OK;
|
||||
int timed_out = (msTimeOut == 0);
|
||||
if ((! _tt_load_xt()) || (! _tt_load_xlib())) {
|
||||
return TT_ERR_ACCESS; // i.e. ELIBACC
|
||||
}
|
||||
if ((timed_out) && (! CALLXT(XtAppPending)( app2run ))) {
|
||||
//
|
||||
// We are non-blocking and no input is available,
|
||||
// so return.
|
||||
//
|
||||
return TT_DESKTOP_ETIMEDOUT;
|
||||
}
|
||||
if (msTimeOut > 0) {
|
||||
alarm = CALLXT(XtAppAddTimeOut)( app2run,
|
||||
(unsigned long)msTimeOut,
|
||||
(XtTimerCallbackProc)_tttk_timed_out,
|
||||
&timed_out );
|
||||
}
|
||||
do {
|
||||
CALLXT(XtAppProcessEvent)( app2run, XtIMAll );
|
||||
} while ((! timed_out) && ((blocked == 0) || (*blocked > 0)));
|
||||
if (alarm != 0) {
|
||||
CALLXT(XtRemoveTimeOut)( alarm );
|
||||
}
|
||||
if (timed_out && (msTimeOut > 0)) {
|
||||
return TT_DESKTOP_ETIMEDOUT;
|
||||
}
|
||||
return TT_OK;
|
||||
}
|
||||
|
||||
Tt_status
|
||||
tttk_block_while(
|
||||
XtAppContext app2run,
|
||||
const int *blocked,
|
||||
int msTimeOut
|
||||
)
|
||||
{
|
||||
if (app2run == 0) {
|
||||
return _tttk_block_procid_while( blocked, msTimeOut );
|
||||
} else {
|
||||
return _tttk_block_app_while( app2run, blocked, msTimeOut );
|
||||
}
|
||||
}
|
||||
344
cde/lib/tt/lib/tttk/tttk.h
Normal file
344
cde/lib/tt/lib/tttk/tttk.h
Normal file
@@ -0,0 +1,344 @@
|
||||
/* $XConsortium: tttk.h /main/3 1995/10/23 10:33:00 rswiston $ */
|
||||
/*%% (c) Copyright 1993, 1994 Hewlett-Packard Company */
|
||||
/*%% (c) Copyright 1993, 1994 International Business Machines Corp. */
|
||||
/*%% (c) Copyright 1993, 1994 Sun Microsystems, Inc. */
|
||||
/*%% (c) Copyright 1993, 1994 Novell, Inc. */
|
||||
|
||||
/*
|
||||
* @(#)tttk.h 1.11 93/09/29
|
||||
*/
|
||||
|
||||
#ifndef tttk_h
|
||||
#define tttk_h
|
||||
|
||||
#include <Tt/tt_c.h>
|
||||
#include <X11/Intrinsic.h>
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
TTDT_OP_NONE,
|
||||
TTDT_CREATED,
|
||||
TTDT_DELETED,
|
||||
TTDT_DO_COMMAND,
|
||||
TTDT_SET_ENVIRONMENT,
|
||||
TTDT_GET_ENVIRONMENT,
|
||||
TTDT_SET_GEOMETRY,
|
||||
TTDT_GET_GEOMETRY,
|
||||
TTDT_SET_ICONIFIED,
|
||||
TTDT_GET_ICONIFIED,
|
||||
TTDT_SET_LOCALE,
|
||||
TTDT_GET_LOCALE,
|
||||
TTDT_SET_MAPPED,
|
||||
TTDT_GET_MAPPED,
|
||||
TTDT_MODIFIED,
|
||||
TTDT_REVERTED,
|
||||
TTDT_GET_MODIFIED,
|
||||
TTDT_MOVED,
|
||||
TTDT_PAUSE,
|
||||
TTDT_RESUME,
|
||||
TTDT_QUIT,
|
||||
TTDT_RAISE,
|
||||
TTDT_LOWER,
|
||||
TTDT_SAVE,
|
||||
TTDT_REVERT,
|
||||
TTDT_SAVED,
|
||||
TTDT_SET_SITUATION,
|
||||
TTDT_GET_SITUATION,
|
||||
TTDT_SIGNAL,
|
||||
TTDT_STARTED,
|
||||
TTDT_STOPPED,
|
||||
TTDT_STATUS,
|
||||
TTDT_GET_STATUS,
|
||||
TTDT_GET_SYSINFO,
|
||||
TTDT_SET_XINFO,
|
||||
TTDT_GET_XINFO,
|
||||
TTME_ABSTRACT,
|
||||
TTME_DEPOSIT,
|
||||
TTME_DISPLAY,
|
||||
TTME_EDIT,
|
||||
TTME_COMPOSE,
|
||||
TTME_INTERPRET,
|
||||
TTME_PRINT,
|
||||
TTME_TRANSLATE,
|
||||
TTME_MAIL,
|
||||
TTME_MAIL_COMPOSE,
|
||||
TTME_MAIL_EDIT,
|
||||
TTME_INSTANTIATE,
|
||||
TTDT_OP_LAST
|
||||
} Tttk_op;
|
||||
|
||||
/*
|
||||
* Standard vtype names
|
||||
*/
|
||||
extern const char *Tttk_integer;
|
||||
extern const char *Tttk_string;
|
||||
extern const char *Tttk_boolean;
|
||||
extern const char *Tttk_file;
|
||||
extern const char *Tttk_message_id;
|
||||
extern const char *Tttk_title;
|
||||
extern const char *Tttk_width;
|
||||
extern const char *Tttk_height;
|
||||
extern const char *Tttk_xoffset;
|
||||
extern const char *Tttk_yoffset;
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* Procid lifecycle
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
char *ttdt_open(
|
||||
int *tt_fd,
|
||||
const char *toolname,
|
||||
const char *vendor,
|
||||
const char *version,
|
||||
int sendStarted
|
||||
);
|
||||
Tt_status ttdt_sender_imprint_on(
|
||||
const char *handler,
|
||||
Tt_message commission,
|
||||
char **display,
|
||||
int *width,
|
||||
int *height,
|
||||
int *xoffset,
|
||||
int *yoffset,
|
||||
XtAppContext app2run,
|
||||
int ms_timeout
|
||||
);
|
||||
Tt_status ttdt_close(
|
||||
const char *procid,
|
||||
const char *newprocid,
|
||||
int sendStopped
|
||||
);
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* Sessions
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
typedef Tt_message (*Ttdt_contract_cb)(
|
||||
Tt_message msg,
|
||||
void *clientdata,
|
||||
Tt_message contract
|
||||
);
|
||||
Tt_pattern *ttdt_session_join(
|
||||
const char *sessid,
|
||||
Ttdt_contract_cb cb,
|
||||
Widget shell,
|
||||
void *clientdata,
|
||||
int join
|
||||
);
|
||||
Tt_status ttdt_session_quit(
|
||||
const char *sessid,
|
||||
Tt_pattern *sess_pats,
|
||||
int quit
|
||||
);
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* Contracts
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
Tt_pattern *ttdt_message_accept(
|
||||
Tt_message contract,
|
||||
Ttdt_contract_cb cb,
|
||||
Widget shell,
|
||||
void *clientdata,
|
||||
int accept,
|
||||
int sendStatus
|
||||
);
|
||||
Tt_pattern *ttdt_subcontract_manage(
|
||||
Tt_message subcontract,
|
||||
Ttdt_contract_cb cb,
|
||||
Widget shell,
|
||||
void *clientdata
|
||||
);
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* Desktop: Files
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
typedef Tt_message (*Ttdt_file_cb)(
|
||||
Tt_message msg,
|
||||
Tttk_op op,
|
||||
char *pathname,
|
||||
void *clientdata,
|
||||
int same_euid_egid,
|
||||
int same_procid
|
||||
);
|
||||
Tt_pattern *ttdt_file_join(
|
||||
const char *pathname,
|
||||
Tt_scope scope,
|
||||
int join,
|
||||
Ttdt_file_cb cb,
|
||||
void *clientdata
|
||||
);
|
||||
Tt_status ttdt_file_event(
|
||||
Tt_message context,
|
||||
Tttk_op event,
|
||||
Tt_pattern *patterns,
|
||||
int send
|
||||
);
|
||||
Tt_status ttdt_file_quit(
|
||||
Tt_pattern *patterns,
|
||||
int quit
|
||||
);
|
||||
int ttdt_Get_Modified(
|
||||
Tt_message context,
|
||||
const char *pathname,
|
||||
Tt_scope scope,
|
||||
XtAppContext app2run,
|
||||
int ms_timeout
|
||||
);
|
||||
Tt_status ttdt_Save(
|
||||
Tt_message context,
|
||||
const char *pathname,
|
||||
Tt_scope scope,
|
||||
XtAppContext app2run,
|
||||
int ms_timeout
|
||||
);
|
||||
Tt_status ttdt_Revert(
|
||||
Tt_message context,
|
||||
const char *pathname,
|
||||
Tt_scope scope,
|
||||
XtAppContext app2run,
|
||||
int ms_timeout
|
||||
);
|
||||
Tt_message ttdt_file_notice(
|
||||
Tt_message context,
|
||||
Tttk_op op,
|
||||
Tt_scope scope,
|
||||
const char *file,
|
||||
int send_and_destroy
|
||||
);
|
||||
Tt_message ttdt_file_request(
|
||||
Tt_message context,
|
||||
Tttk_op op,
|
||||
Tt_scope scope,
|
||||
const char *file,
|
||||
Ttdt_file_cb cb,
|
||||
void *clientdata,
|
||||
int send
|
||||
);
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* Media Exchange
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
typedef Tt_message (*Ttmedia_load_pat_cb)(
|
||||
Tt_message msg,
|
||||
void *clientdata,
|
||||
Tttk_op op,
|
||||
Tt_status diagnosis,
|
||||
unsigned char *contents,
|
||||
int len,
|
||||
char *file,
|
||||
char *docname
|
||||
);
|
||||
Tt_status ttmedia_ptype_declare(
|
||||
const char *ptype,
|
||||
int base_opnum,
|
||||
Ttmedia_load_pat_cb cb,
|
||||
void *clientdata,
|
||||
int declare
|
||||
);
|
||||
typedef Tt_message (*Ttmedia_load_msg_cb)(
|
||||
Tt_message msg,
|
||||
void *clientdata,
|
||||
Tttk_op op,
|
||||
unsigned char *contents,
|
||||
int len,
|
||||
char *file
|
||||
);
|
||||
Tt_message ttmedia_load(
|
||||
Tt_message context,
|
||||
Ttmedia_load_msg_cb cb,
|
||||
void *clientdata,
|
||||
Tttk_op op,
|
||||
const char *media_type,
|
||||
const unsigned char *contents,
|
||||
int len,
|
||||
const char *file,
|
||||
const char *docname,
|
||||
int send
|
||||
);
|
||||
Tt_status ttmedia_load_reply(
|
||||
Tt_message contract,
|
||||
const unsigned char *new_contents,
|
||||
int new_len,
|
||||
int reply_and_destroy
|
||||
);
|
||||
Tt_status ttmedia_Deposit(
|
||||
Tt_message contract,
|
||||
const char *buffer_id,
|
||||
const char *media_type,
|
||||
const unsigned char *new_contents,
|
||||
int new_len,
|
||||
const char *file,
|
||||
XtAppContext app2run,
|
||||
int ms_timeout
|
||||
);
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* ToolTalk Toolkit
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
void tttk_Xt_input_handler(
|
||||
XtPointer procid,
|
||||
int *,
|
||||
XtInputId *
|
||||
);
|
||||
Tt_status tttk_block_while(
|
||||
XtAppContext app2run,
|
||||
const int *blocked,
|
||||
int ms_timeout
|
||||
);
|
||||
Tt_message tttk_message_create(
|
||||
Tt_message context,
|
||||
Tt_class the_class,
|
||||
Tt_scope the_scope,
|
||||
const char *handler,
|
||||
const char *op,
|
||||
Tt_message_callback callback
|
||||
);
|
||||
Tt_status tttk_message_destroy(
|
||||
Tt_message msg
|
||||
);
|
||||
Tt_status tttk_message_reject(
|
||||
Tt_message msg,
|
||||
Tt_status status,
|
||||
const char *status_string,
|
||||
int destroy
|
||||
);
|
||||
Tt_status tttk_message_fail(
|
||||
Tt_message msg,
|
||||
Tt_status status,
|
||||
const char *status_string,
|
||||
int destroy
|
||||
);
|
||||
Tt_status tttk_message_abandon(
|
||||
Tt_message msg
|
||||
);
|
||||
Tttk_op tttk_string_op(
|
||||
const char *s
|
||||
);
|
||||
char *tttk_op_string(
|
||||
Tttk_op op
|
||||
);
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
203
cde/lib/tt/lib/tttk/tttk2free.C
Normal file
203
cde/lib/tt/lib/tttk/tttk2free.C
Normal file
@@ -0,0 +1,203 @@
|
||||
//%% (c) Copyright 1993, 1994 Hewlett-Packard Company
|
||||
//%% (c) Copyright 1993, 1994 International Business Machines Corp.
|
||||
//%% (c) Copyright 1993, 1994 Sun Microsystems, Inc.
|
||||
//%% (c) Copyright 1993, 1994 Novell, Inc.
|
||||
//%% $XConsortium: tttk2free.C /main/3 1995/10/23 10:33:09 rswiston $
|
||||
/*
|
||||
* @(#)tttk2free.C 1.3 93/09/07
|
||||
*
|
||||
* Copyright 1993 Sun Microsystems, Inc. All rights reserved.
|
||||
*/
|
||||
#include "tttk/tttk2free.h"
|
||||
|
||||
_TttkItem2Free::_TttkItem2Free()
|
||||
{
|
||||
_type = NoItem;
|
||||
}
|
||||
|
||||
_TttkItem2Free::_TttkItem2Free(
|
||||
Tt_message msg
|
||||
)
|
||||
{
|
||||
operator=( msg );
|
||||
}
|
||||
|
||||
_TttkItem2Free::_TttkItem2Free(
|
||||
Tt_pattern pat
|
||||
)
|
||||
{
|
||||
operator=( pat );
|
||||
}
|
||||
|
||||
_TttkItem2Free::_TttkItem2Free(
|
||||
caddr_t ptr
|
||||
)
|
||||
{
|
||||
operator=( ptr );
|
||||
}
|
||||
|
||||
_TttkItem2Free::~_TttkItem2Free()
|
||||
{
|
||||
switch (_type) {
|
||||
case Message:
|
||||
if (_msg != 0) {
|
||||
tttk_message_destroy( _msg );
|
||||
}
|
||||
break;
|
||||
case Pattern:
|
||||
if (_pat != 0) {
|
||||
tt_pattern_destroy( _pat );
|
||||
}
|
||||
break;
|
||||
case Pointer:
|
||||
if (_ptr != 0) {
|
||||
tt_free( _ptr );
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Tt_message
|
||||
_TttkItem2Free::operator =(
|
||||
Tt_message msg
|
||||
)
|
||||
{
|
||||
_type = Message;
|
||||
_msg = msg;
|
||||
return msg;
|
||||
}
|
||||
|
||||
Tt_pattern
|
||||
_TttkItem2Free::operator =(
|
||||
Tt_pattern pat
|
||||
)
|
||||
{
|
||||
_type = Pattern;
|
||||
_pat = pat;
|
||||
return pat;
|
||||
}
|
||||
|
||||
caddr_t
|
||||
_TttkItem2Free::operator =(
|
||||
caddr_t ptr
|
||||
)
|
||||
{
|
||||
_type = Pointer;
|
||||
_ptr = ptr;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
_TttkList2Free::_TttkList2Free(
|
||||
unsigned int maxElems
|
||||
)
|
||||
{
|
||||
_num = 0;
|
||||
_max = maxElems;
|
||||
#ifdef OPT_VECNEW
|
||||
_items = new _TttkItem2Free[ maxElems ];
|
||||
if (_items == 0) {
|
||||
_max = 0;
|
||||
}
|
||||
#else
|
||||
_items = (_TttkItem2Free **)malloc( maxElems * sizeof(_TttkItem2Free *));
|
||||
if (_items == 0) {
|
||||
_max = 0;
|
||||
}
|
||||
for (int i = 0; i < _max; i++) {
|
||||
_items[ i ] = new _TttkItem2Free();
|
||||
if (_items[ i ] == 0) {
|
||||
_destruct();
|
||||
_max = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
_TttkList2Free::~_TttkList2Free()
|
||||
{
|
||||
_destruct();
|
||||
}
|
||||
|
||||
Tt_message
|
||||
_TttkList2Free::operator +=(
|
||||
Tt_message msg
|
||||
)
|
||||
{
|
||||
if (_num >= _max) {
|
||||
return msg;
|
||||
}
|
||||
// LIFO
|
||||
_item( _max - _num - 1 ) = msg;
|
||||
_num++;
|
||||
return msg;
|
||||
}
|
||||
|
||||
Tt_pattern
|
||||
_TttkList2Free::operator +=(
|
||||
Tt_pattern pat
|
||||
)
|
||||
{
|
||||
if (_num >= _max) {
|
||||
return pat;
|
||||
}
|
||||
// LIFO
|
||||
_item( _max - _num - 1 ) = pat;
|
||||
_num++;
|
||||
return pat;
|
||||
}
|
||||
|
||||
caddr_t
|
||||
_TttkList2Free::operator +=(
|
||||
caddr_t ptr
|
||||
)
|
||||
{
|
||||
if (_num >= _max) {
|
||||
return ptr;
|
||||
}
|
||||
// LIFO
|
||||
_item( _max - _num - 1 ) = ptr;
|
||||
_num++;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void
|
||||
_TttkList2Free::flush()
|
||||
{
|
||||
for (int i = 0; i < _num; i++) {
|
||||
_item( i ) = (caddr_t)0;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
_TttkList2Free::_destruct()
|
||||
{
|
||||
if (_items != 0) {
|
||||
#ifdef OPT_VECNEW
|
||||
delete [] _items;
|
||||
#else
|
||||
for (int i = 0; i < _max; i++) {
|
||||
if (_items[ i ] != 0) {
|
||||
delete _items[ i ];
|
||||
_items[ i ] = 0;
|
||||
}
|
||||
}
|
||||
free( _items );
|
||||
_items = 0;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
_TttkItem2Free &
|
||||
_TttkList2Free::_item(
|
||||
int i
|
||||
)
|
||||
{
|
||||
#ifdef OPT_VECNEW
|
||||
return _items[ i ];
|
||||
#else
|
||||
return *_items[ i ];
|
||||
#endif
|
||||
}
|
||||
114
cde/lib/tt/lib/tttk/tttk2free.h
Normal file
114
cde/lib/tt/lib/tttk/tttk2free.h
Normal file
@@ -0,0 +1,114 @@
|
||||
/*%% (c) Copyright 1993, 1994 Hewlett-Packard Company */
|
||||
/*%% (c) Copyright 1993, 1994 International Business Machines Corp. */
|
||||
/*%% (c) Copyright 1993, 1994 Sun Microsystems, Inc. */
|
||||
/*%% (c) Copyright 1993, 1994 Novell, Inc. */
|
||||
/*%% $XConsortium: tttk2free.h /main/3 1995/10/23 10:33:17 rswiston $ */
|
||||
/*
|
||||
* @(#)tttk2free.h 1.3 93/09/07
|
||||
*
|
||||
* Copyright 1993 Sun Microsystems, Inc. All rights reserved.
|
||||
*/
|
||||
#ifndef tttk2free_h
|
||||
#define tttk2free_h
|
||||
|
||||
#include "api/c/tt_c.h"
|
||||
#include "util/tt_new.h"
|
||||
#include "tttk/tttk.h"
|
||||
|
||||
//
|
||||
// An instance of this class will automatically destroy() a message or
|
||||
// tt_free() a pointer when the instance goes out of scope. This lets
|
||||
// you avoid having to repetitively code the destroy() or free() right
|
||||
// before every possible return from the scope. Typical usage:
|
||||
//
|
||||
// TtDtItem2Free item;
|
||||
// Tt_message msg = tt_message_create();
|
||||
// item = msg;
|
||||
// ...
|
||||
// if (error) return error; // msg is automatically destroyed here
|
||||
// ...
|
||||
// item = 0; // now, msg won't be destroyed on return
|
||||
// return TT_OK;
|
||||
//
|
||||
// This class actually uses ttDtDestroy() instead of tt_message_destroy().
|
||||
//
|
||||
class _TttkItem2Free : public _Tt_allocated {
|
||||
public:
|
||||
_TttkItem2Free();
|
||||
_TttkItem2Free(
|
||||
Tt_message msg
|
||||
);
|
||||
_TttkItem2Free(
|
||||
Tt_pattern pat
|
||||
);
|
||||
_TttkItem2Free(
|
||||
caddr_t ptr
|
||||
);
|
||||
~_TttkItem2Free();
|
||||
|
||||
Tt_message operator =(
|
||||
Tt_message msg
|
||||
);
|
||||
Tt_pattern operator =(
|
||||
Tt_pattern pat
|
||||
);
|
||||
caddr_t operator =(
|
||||
caddr_t ptr
|
||||
);
|
||||
private:
|
||||
enum {
|
||||
NoItem,
|
||||
Message,
|
||||
Pattern,
|
||||
Pointer
|
||||
} _type;
|
||||
union {
|
||||
Tt_message _msg;
|
||||
Tt_pattern _pat;
|
||||
caddr_t _ptr;
|
||||
};
|
||||
};
|
||||
|
||||
//
|
||||
// This class is an array of _TttkItem2Free's. Its main benefit is
|
||||
// that the ::flush() method lets you defuse all the items at once
|
||||
// (typically, right before returning successfully from a scope).
|
||||
//
|
||||
// A malloc() is only done at constructor-time, so that you need not
|
||||
// check if the +=() method failed due to malloc() failure. Thus,
|
||||
// you have to know the max size of your list at constructor-time.
|
||||
// Overflow items are ignored, and are thus potential memory leaks.
|
||||
//
|
||||
class _TttkList2Free : public _Tt_allocated {
|
||||
public:
|
||||
_TttkList2Free(
|
||||
unsigned int maxElems
|
||||
);
|
||||
~_TttkList2Free();
|
||||
|
||||
Tt_message operator +=(
|
||||
Tt_message msg2Destroy
|
||||
);
|
||||
Tt_pattern operator +=(
|
||||
Tt_pattern pat2Destroy
|
||||
);
|
||||
caddr_t operator +=(
|
||||
caddr_t ptr2tt_free
|
||||
);
|
||||
void flush();
|
||||
private:
|
||||
void _destruct();
|
||||
_TttkItem2Free &_item(
|
||||
int i
|
||||
);
|
||||
|
||||
unsigned int _num;
|
||||
unsigned int _max;
|
||||
#ifdef OPT_VECNEW
|
||||
_TttkItem2Free *_items;
|
||||
#else
|
||||
_TttkItem2Free **_items;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif
|
||||
461
cde/lib/tt/lib/tttk/tttkmessage.C
Normal file
461
cde/lib/tt/lib/tttk/tttkmessage.C
Normal file
@@ -0,0 +1,461 @@
|
||||
//%% (c) Copyright 1993, 1994 Hewlett-Packard Company
|
||||
//%% (c) Copyright 1993, 1994 International Business Machines Corp.
|
||||
//%% (c) Copyright 1993, 1994 Sun Microsystems, Inc.
|
||||
//%% (c) Copyright 1993, 1994 Novell, Inc.
|
||||
//%% $TOG: tttkmessage.C /main/5 1998/03/19 18:34:28 mgreess $
|
||||
/*
|
||||
* @(#)tttkmessage.C 1.3 93/09/07
|
||||
*
|
||||
* Copyright 1993 Sun Microsystems, Inc. All rights reserved.
|
||||
*/
|
||||
#include "api/c/tt_c.h"
|
||||
#include "api/c/api_mp.h"
|
||||
#include "tttk/tttk.h"
|
||||
#include "tttk/tttkpattern.h"
|
||||
#include "tttk/tttkmessage.h"
|
||||
#include "tttk/tttk2free.h"
|
||||
#include "tttk/tttkutils.h"
|
||||
|
||||
Tt_message
|
||||
tttk_message_create( // XXX propagate contexts
|
||||
Tt_message ,
|
||||
Tt_class theClass,
|
||||
Tt_scope theScope,
|
||||
const char *handler,
|
||||
const char *op,
|
||||
Tt_message_callback callback
|
||||
)
|
||||
{
|
||||
Tt_message msg = tt_message_create();
|
||||
Tt_status status = tt_ptr_error( msg );
|
||||
if (status != TT_OK) {
|
||||
return msg;
|
||||
}
|
||||
// fuse msg for automatic destruction if we return before defusing
|
||||
_TttkItem2Free temp = msg;
|
||||
status = tt_message_class_set( msg, theClass );
|
||||
if (status != TT_OK) {
|
||||
return (Tt_message)tt_error_pointer( status );
|
||||
}
|
||||
status = tt_message_scope_set( msg, theScope );
|
||||
if (status != TT_OK) {
|
||||
return (Tt_message)tt_error_pointer( status );
|
||||
}
|
||||
Tt_address address = TT_PROCEDURE;
|
||||
if (handler != 0) {
|
||||
status = tt_message_handler_set( msg, handler );
|
||||
if (status != TT_OK) {
|
||||
return (Tt_message)tt_error_pointer( status );
|
||||
}
|
||||
address = TT_HANDLER;
|
||||
}
|
||||
status = tt_message_address_set( msg, address );
|
||||
if (status != TT_OK) {
|
||||
return (Tt_message)tt_error_pointer( status );
|
||||
}
|
||||
if (op != 0) {
|
||||
status = tt_message_op_set( msg, op );
|
||||
if (status != TT_OK) {
|
||||
return (Tt_message)tt_error_pointer( status );
|
||||
}
|
||||
}
|
||||
if (callback != 0) {
|
||||
status = tt_message_callback_add( msg, callback );
|
||||
if (status != TT_OK) {
|
||||
return (Tt_message)tt_error_pointer( status );
|
||||
}
|
||||
}
|
||||
temp = (caddr_t)0; // defuse
|
||||
return msg;
|
||||
}
|
||||
|
||||
// extern "C" { extern Tt_status _tt_message_destroy( Tt_message ); }
|
||||
|
||||
Tt_status
|
||||
tttk_message_destroy(
|
||||
Tt_message msg
|
||||
)
|
||||
{
|
||||
Tt_pattern *pats1;
|
||||
Tt_pattern *pats2;
|
||||
pats1 = (Tt_pattern *)tt_message_user( msg, _TttkContractKey );
|
||||
pats2 = (Tt_pattern *)tt_message_user( msg, _TttkSubContractKey );
|
||||
Tt_status status = _tt_message_destroy( msg );
|
||||
if (status != TT_WRN_STOPPED) {
|
||||
_tttk_patterns_destroy( pats1 );
|
||||
_tttk_patterns_destroy( pats2 );
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
//
|
||||
// This is the only message callback we ever use. It retrieves
|
||||
// the clientdata, client callback, and a tttk internal callback.
|
||||
// That internal callback will parse the message and pass the
|
||||
// info (along with the clientdata) to the client callback.
|
||||
//
|
||||
Tt_callback_action
|
||||
_ttDtMessageCB(
|
||||
Tt_message msg,
|
||||
Tt_pattern pat
|
||||
)
|
||||
{
|
||||
_TtDtMessageCB cb = (_TtDtMessageCB)
|
||||
tt_message_user( msg, _TttkCBKey );
|
||||
Tt_status status = tt_ptr_error( cb );
|
||||
if (status != TT_OK) {
|
||||
return TT_CALLBACK_PROCESSED;
|
||||
}
|
||||
if (cb == 0) {
|
||||
return TT_CALLBACK_CONTINUE;
|
||||
}
|
||||
void *clientCB = tt_message_user( msg, _TttkClientCBKey );
|
||||
status = tt_ptr_error( clientCB );
|
||||
if (status != TT_OK) {
|
||||
return TT_CALLBACK_PROCESSED;
|
||||
}
|
||||
// clientCB is allowed to be 0. cf. ttmedia_Deposit()
|
||||
void *clientData = tt_message_user( msg, _TttkClientDataKey );
|
||||
status = tt_ptr_error( clientData );
|
||||
if (status != TT_OK) {
|
||||
return TT_CALLBACK_PROCESSED;
|
||||
}
|
||||
msg = (*cb)( msg, pat, clientCB, clientData );
|
||||
return _ttDtCallbackAction( msg );
|
||||
}
|
||||
|
||||
//
|
||||
// Create a message and and store on it an internal callback, a
|
||||
// client callback, and a client datum.
|
||||
//
|
||||
Tt_message
|
||||
_ttDtPMessageCreate(
|
||||
Tt_message context,
|
||||
Tt_class theClass,
|
||||
Tt_scope theScope,
|
||||
const char *handler,
|
||||
Tttk_op op,
|
||||
_TtDtMessageCB cb,
|
||||
void *clientCB,
|
||||
void *clientData
|
||||
)
|
||||
{
|
||||
Tt_message msg = tttk_message_create( context, theClass, theScope,
|
||||
handler, _ttDtOp( op ), _ttDtMessageCB );
|
||||
Tt_status status = tt_ptr_error( msg );
|
||||
if (status != TT_OK) {
|
||||
return msg;
|
||||
}
|
||||
_TttkItem2Free fuse( msg );
|
||||
status = tt_message_user_set( msg, _TttkCBKey, cb );
|
||||
if (status != TT_OK) {
|
||||
return (Tt_message)tt_error_pointer( status );
|
||||
}
|
||||
status = tt_message_user_set( msg, _TttkClientCBKey, clientCB );
|
||||
if (status != TT_OK) {
|
||||
return (Tt_message)tt_error_pointer( status );
|
||||
}
|
||||
status = tt_message_user_set( msg, _TttkClientDataKey, clientData );
|
||||
if (status != TT_OK) {
|
||||
return (Tt_message)tt_error_pointer( status );
|
||||
}
|
||||
fuse = (caddr_t)0;
|
||||
return msg;
|
||||
}
|
||||
|
||||
//
|
||||
// Set the status info on a message, fail or reject it, and optionally
|
||||
// destroy it.
|
||||
//
|
||||
Tt_status
|
||||
_ttDtMessageGong(
|
||||
Tt_message msg,
|
||||
Tt_status status,
|
||||
const char *statusString,
|
||||
int reject,
|
||||
int destroy
|
||||
)
|
||||
{
|
||||
tt_message_status_set( msg, status );
|
||||
if (statusString != 0) {
|
||||
tt_message_status_string_set( msg, statusString );
|
||||
}
|
||||
Tt_status ttStatus;
|
||||
if (reject) {
|
||||
ttStatus = tt_message_reject( msg );
|
||||
} else {
|
||||
ttStatus = tt_message_fail( msg );
|
||||
}
|
||||
if (destroy) {
|
||||
tttk_message_destroy( msg );
|
||||
}
|
||||
return ttStatus;
|
||||
}
|
||||
|
||||
Tt_status
|
||||
tttk_message_reject(
|
||||
Tt_message msg,
|
||||
Tt_status status,
|
||||
const char *statusString,
|
||||
int destroy
|
||||
)
|
||||
{
|
||||
return _ttDtMessageGong( msg, status, statusString, 1, destroy );
|
||||
}
|
||||
|
||||
Tt_status
|
||||
tttk_message_fail(
|
||||
Tt_message msg,
|
||||
Tt_status status,
|
||||
const char *statusString,
|
||||
int destroy
|
||||
)
|
||||
{
|
||||
if (tt_message_class( msg ) == TT_REQUEST) {
|
||||
return _ttDtMessageGong( msg, status, statusString, 0,
|
||||
destroy );
|
||||
} else if (destroy) {
|
||||
return tttk_message_destroy( msg );
|
||||
}
|
||||
return TT_OK;
|
||||
}
|
||||
|
||||
//
|
||||
// Set the default procid and call tt_message_receive()
|
||||
//
|
||||
Tt_message
|
||||
_tttk_message_receive(
|
||||
const char *procid
|
||||
)
|
||||
{
|
||||
Tt_status status;
|
||||
if (procid != 0) {
|
||||
status = tt_default_procid_set( procid );
|
||||
if (status != TT_OK) {
|
||||
return (Tt_message)tt_error_pointer( status );
|
||||
}
|
||||
}
|
||||
return tt_message_receive();
|
||||
}
|
||||
|
||||
//
|
||||
// Used internally to reply to messages that might be edicts (i.e. notices)
|
||||
//
|
||||
Tt_status
|
||||
_tttk_message_reply(
|
||||
Tt_message msg
|
||||
)
|
||||
{
|
||||
if (tt_message_class( msg ) == TT_REQUEST) {
|
||||
return tt_message_reply( msg );
|
||||
}
|
||||
return TT_OK;
|
||||
}
|
||||
|
||||
Tt_status
|
||||
tttk_message_abandon(
|
||||
Tt_message msg
|
||||
)
|
||||
{
|
||||
if (_tttk_message_am_handling( msg )) {
|
||||
int fail = 0;
|
||||
if (tt_message_address( msg ) == TT_HANDLER) {
|
||||
fail = 1;
|
||||
} else if (tt_message_status( msg ) == TT_WRN_START_MESSAGE) {
|
||||
fail = 1;
|
||||
}
|
||||
if (fail) {
|
||||
return tttk_message_fail( msg, TT_DESKTOP_ENOTSUP,0,1);
|
||||
} else {
|
||||
return tttk_message_reject(msg, TT_DESKTOP_ENOTSUP,0,1);
|
||||
}
|
||||
} else {
|
||||
return tttk_message_destroy( msg );
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Returns the sender-set message id if any, otherwise the tt_message_id()
|
||||
//
|
||||
char *
|
||||
_tttk_message_id(
|
||||
Tt_message msg,
|
||||
int arg
|
||||
)
|
||||
{
|
||||
int numArgs = tt_message_args_count( msg );
|
||||
Tt_status status = tt_int_error( numArgs );
|
||||
if (status != TT_OK) {
|
||||
return 0;
|
||||
}
|
||||
for (int i = arg; i < numArgs; i++) {
|
||||
char *type = tt_message_arg_type( msg, i );
|
||||
status = tt_ptr_error( type );
|
||||
if (status != TT_OK) {
|
||||
return 0;
|
||||
}
|
||||
if (type == 0) {
|
||||
continue;
|
||||
}
|
||||
int miss = strcmp( type, Tttk_message_id );
|
||||
tt_free( type );
|
||||
if (miss) {
|
||||
continue;
|
||||
}
|
||||
char *msgID = tt_message_arg_val( msg, i );
|
||||
status = tt_ptr_error( type );
|
||||
if (status != TT_OK) {
|
||||
return 0;
|
||||
}
|
||||
return msgID;
|
||||
}
|
||||
return tt_message_id( msg );
|
||||
}
|
||||
|
||||
int
|
||||
_tttk_message_in_final_state(
|
||||
Tt_message msg
|
||||
)
|
||||
{
|
||||
Tt_state theState = tt_message_state( msg );
|
||||
switch (tt_message_class( msg )) {
|
||||
case TT_NOTICE:
|
||||
return theState == TT_SENT;
|
||||
case TT_REQUEST:
|
||||
return (theState == TT_HANDLED) || (theState == TT_FAILED);
|
||||
case TT_OFFER:
|
||||
return theState == TT_RETURNED;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Can I reply to this message?
|
||||
//
|
||||
int
|
||||
_tttk_message_am_handling(
|
||||
Tt_message msg
|
||||
)
|
||||
{
|
||||
if (tt_message_class( msg ) != TT_REQUEST) {
|
||||
return 0;
|
||||
}
|
||||
if (tt_message_state( msg ) != TT_SENT) {
|
||||
return 0;
|
||||
}
|
||||
char *handler = tt_message_handler( msg );
|
||||
int am_handling = 0;
|
||||
if ((tt_ptr_error( handler ) == TT_OK) && (handler != 0)) {
|
||||
am_handling = 1;
|
||||
}
|
||||
tt_free( handler );
|
||||
return am_handling;
|
||||
}
|
||||
|
||||
//
|
||||
// Get arg value and return default_val on error.
|
||||
//
|
||||
int
|
||||
_tttk_message_arg_ival(
|
||||
Tt_message msg,
|
||||
unsigned int n,
|
||||
int default_val
|
||||
)
|
||||
{
|
||||
if (! _tttk_message_arg_is_set( msg, n )) {
|
||||
return default_val;
|
||||
}
|
||||
int val;
|
||||
Tt_status status = tt_message_arg_ival( msg, n, &val );
|
||||
if (status != TT_OK) {
|
||||
return default_val;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
char *
|
||||
_tttk_message_arg_val(
|
||||
Tt_message msg,
|
||||
unsigned int n,
|
||||
const char *default_val
|
||||
)
|
||||
{
|
||||
if (! _tttk_message_arg_is_set( msg, n )) {
|
||||
return (char *)default_val;
|
||||
}
|
||||
char *val = tt_message_arg_val( msg, n );
|
||||
Tt_status status = tt_ptr_error( val );
|
||||
if (status != TT_OK) {
|
||||
return (char *)default_val;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
//
|
||||
// Does arg n have a value?
|
||||
//
|
||||
int
|
||||
_tttk_message_arg_is_set(
|
||||
Tt_message msg,
|
||||
unsigned int n
|
||||
)
|
||||
{
|
||||
int val;
|
||||
Tt_status status = tt_message_arg_ival( msg, n, &val );
|
||||
if (status == TT_OK) {
|
||||
return 1;
|
||||
}
|
||||
if (status != TT_ERR_NUM) {
|
||||
return 0;
|
||||
}
|
||||
unsigned char *s;
|
||||
int len;
|
||||
status = tt_message_arg_bval( msg, n, &s, &len );
|
||||
if (status != TT_OK) {
|
||||
return 0;
|
||||
}
|
||||
return (s != 0);
|
||||
}
|
||||
|
||||
//
|
||||
// Generic _TtDtMessageCB that sets *clientData to the negated
|
||||
// tt_message_status() of the reply (or failure) of the message.
|
||||
// Useful when sending synchronous requests and you only care to
|
||||
// know the Tt_status of the reply/failure.
|
||||
//
|
||||
Tt_message
|
||||
_ttTkNoteReplyStatus(
|
||||
Tt_message msg,
|
||||
Tt_pattern ,
|
||||
void *,
|
||||
void *clientData
|
||||
)
|
||||
{
|
||||
if (! _tttk_message_in_final_state( msg )) {
|
||||
return msg;
|
||||
}
|
||||
int *result = (int *)clientData;
|
||||
*result = -TT_DESKTOP_ETIMEDOUT;
|
||||
switch (tt_message_state( msg )) {
|
||||
case TT_HANDLED:
|
||||
*result = -TT_OK;
|
||||
break;
|
||||
case TT_FAILED:
|
||||
*result = -tt_message_status( msg );
|
||||
if (*result == -TT_OK) {
|
||||
//
|
||||
// The handler did not say why he failed the
|
||||
// request, so we have to make up a reason
|
||||
// to pass back through e.g. ttdt_Save().
|
||||
//
|
||||
*result = -TT_DESKTOP_EPROTO;
|
||||
}
|
||||
break;
|
||||
}
|
||||
tttk_message_destroy( msg );
|
||||
// Protect against bogus message status causing infinite loop
|
||||
if (*result > 0) {
|
||||
*result = -(*result);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
71
cde/lib/tt/lib/tttk/tttkmessage.h
Normal file
71
cde/lib/tt/lib/tttk/tttkmessage.h
Normal file
@@ -0,0 +1,71 @@
|
||||
/*%% (c) Copyright 1993, 1994 Hewlett-Packard Company */
|
||||
/*%% (c) Copyright 1993, 1994 International Business Machines Corp. */
|
||||
/*%% (c) Copyright 1993, 1994 Sun Microsystems, Inc. */
|
||||
/*%% (c) Copyright 1993, 1994 Novell, Inc. */
|
||||
/*%% $XConsortium: tttkmessage.h /main/3 1995/10/23 10:33:31 rswiston $ */
|
||||
/* -*-C++-*-
|
||||
*
|
||||
* @(#)tttkmessage.h 1.3 93/09/07
|
||||
*
|
||||
* Copyright 1993 Sun Microsystems, Inc. All rights reserved.
|
||||
*/
|
||||
#ifndef ttdtmessage_h
|
||||
#define ttdtmessage_h
|
||||
|
||||
#include "tttk/tttk.h"
|
||||
|
||||
typedef Tt_message (*_TtDtMessageCB)(
|
||||
Tt_message msg,
|
||||
Tt_pattern pat,
|
||||
void *clientCB,
|
||||
void *clientData
|
||||
);
|
||||
|
||||
Tt_message _tttk_message_receive(
|
||||
const char *procid
|
||||
);
|
||||
Tt_status _tttk_message_reply(
|
||||
Tt_message msg
|
||||
);
|
||||
Tt_message _ttDtPMessageCreate(
|
||||
Tt_message context,
|
||||
Tt_class theClass,
|
||||
Tt_scope theScope,
|
||||
const char *handler,
|
||||
Tttk_op op,
|
||||
_TtDtMessageCB ttDtCb,
|
||||
void *clientCB,
|
||||
void *clientData
|
||||
);
|
||||
char *_tttk_message_id(
|
||||
Tt_message msg,
|
||||
int arg = 0
|
||||
);
|
||||
int _tttk_message_in_final_state(
|
||||
Tt_message msg
|
||||
);
|
||||
int _tttk_message_am_handling(
|
||||
Tt_message msg
|
||||
);
|
||||
int _tttk_message_arg_ival(
|
||||
Tt_message msg,
|
||||
unsigned int n,
|
||||
int default_val
|
||||
);
|
||||
char *_tttk_message_arg_val(
|
||||
Tt_message msg,
|
||||
unsigned int n,
|
||||
const char *default_val
|
||||
);
|
||||
int _tttk_message_arg_is_set(
|
||||
Tt_message msg,
|
||||
unsigned int n
|
||||
);
|
||||
Tt_message _ttTkNoteReplyStatus(
|
||||
Tt_message msg,
|
||||
Tt_pattern ,
|
||||
void *,
|
||||
void *clientData
|
||||
);
|
||||
|
||||
#endif
|
||||
175
cde/lib/tt/lib/tttk/tttkpattern.C
Normal file
175
cde/lib/tt/lib/tttk/tttkpattern.C
Normal file
@@ -0,0 +1,175 @@
|
||||
//%% (c) Copyright 1993, 1994 Hewlett-Packard Company
|
||||
//%% (c) Copyright 1993, 1994 International Business Machines Corp.
|
||||
//%% (c) Copyright 1993, 1994 Sun Microsystems, Inc.
|
||||
//%% (c) Copyright 1993, 1994 Novell, Inc.
|
||||
//%% $XConsortium: tttkpattern.C /main/3 1995/10/23 10:33:41 rswiston $
|
||||
/*
|
||||
* @(#)tttkpattern.C 1.3 93/09/07
|
||||
*
|
||||
* Copyright 1993 Sun Microsystems, Inc. All rights reserved.
|
||||
*/
|
||||
#include "api/c/tt_c.h"
|
||||
#include "tttk/tttk.h"
|
||||
#include "tttk/tttkmessage.h"
|
||||
#include "tttk/tttk2free.h"
|
||||
#include "tttk/tttkutils.h"
|
||||
|
||||
Tt_status
|
||||
_tttk_patterns_destroy(
|
||||
Tt_pattern *pats
|
||||
)
|
||||
{
|
||||
if (pats == 0) {
|
||||
return TT_OK;
|
||||
}
|
||||
Tt_status worst = tt_ptr_error( pats );
|
||||
if (worst != TT_OK) {
|
||||
return worst;
|
||||
}
|
||||
Tt_pattern *pats2free = pats;
|
||||
while (*pats != 0) {
|
||||
if (tt_ptr_error( *pats ) == TT_OK) {
|
||||
Tt_status status = tt_pattern_destroy( *pats );
|
||||
if (status != TT_OK) {
|
||||
worst = status;
|
||||
}
|
||||
}
|
||||
pats++;
|
||||
}
|
||||
if (pats2free != 0) {
|
||||
free( (caddr_t)pats2free );
|
||||
}
|
||||
return worst;
|
||||
}
|
||||
|
||||
//
|
||||
// This is the only pattern callback that we use. It retrieves and
|
||||
// calls the op-specific internal unmarshalling routine, which in turn
|
||||
// will call the user's op-specific callback.
|
||||
//
|
||||
static Tt_callback_action
|
||||
_ttDtPatternCB(
|
||||
Tt_message msg,
|
||||
Tt_pattern pat
|
||||
)
|
||||
{
|
||||
// XXX optimization: use 1 key, store a struct w/ all 3 datums
|
||||
_TtDtMessageCB cb = (_TtDtMessageCB)
|
||||
tt_pattern_user( pat, _TttkCBKey );
|
||||
Tt_status status = tt_ptr_error( cb );
|
||||
if (status != TT_OK) {
|
||||
return TT_CALLBACK_PROCESSED;
|
||||
}
|
||||
if (cb == 0) {
|
||||
return TT_CALLBACK_CONTINUE;
|
||||
}
|
||||
void *clientCB = tt_pattern_user( pat, _TttkClientCBKey );
|
||||
status = tt_ptr_error( clientCB );
|
||||
if (status != TT_OK) {
|
||||
return TT_CALLBACK_PROCESSED;
|
||||
}
|
||||
// clientCB is allowed to be 0. cf. TTDT_QUIT in ttdt_session_join
|
||||
void *clientData = tt_pattern_user( pat, _TttkClientDataKey );
|
||||
status = tt_ptr_error( clientData );
|
||||
if (status != TT_OK) {
|
||||
return TT_CALLBACK_PROCESSED;
|
||||
}
|
||||
msg = (*cb)( msg, pat, clientCB, clientData );
|
||||
return _ttDtCallbackAction( msg );
|
||||
}
|
||||
|
||||
Tt_pattern
|
||||
_ttDtPatternCreate(
|
||||
Tt_category category,
|
||||
Tt_scope theScope,
|
||||
int addDefaultSess,
|
||||
const char *file,
|
||||
Tttk_op op,
|
||||
_TtDtMessageCB cb,
|
||||
void *clientCB,
|
||||
void *clientData,
|
||||
int registerIt
|
||||
)
|
||||
{
|
||||
Tt_pattern pat = tt_pattern_create();
|
||||
Tt_status status = tt_ptr_error( pat );
|
||||
if (status != TT_OK) {
|
||||
return pat;
|
||||
}
|
||||
_TttkItem2Free fuse( pat );
|
||||
status = tt_pattern_category_set( pat, category );
|
||||
if (status != TT_OK) {
|
||||
return (Tt_pattern)tt_error_pointer( status );
|
||||
}
|
||||
// we only observe notices and only handle requests
|
||||
if (category == TT_HANDLE) {
|
||||
status = tt_pattern_class_add( pat, TT_REQUEST );
|
||||
}
|
||||
if (category == TT_OBSERVE) {
|
||||
status = tt_pattern_class_add( pat, TT_NOTICE );
|
||||
}
|
||||
if (status != TT_OK) {
|
||||
return (Tt_pattern)tt_error_pointer( status );
|
||||
}
|
||||
status = tt_pattern_scope_add( pat, theScope );
|
||||
if (status != TT_OK) {
|
||||
return (Tt_pattern)tt_error_pointer( status );
|
||||
}
|
||||
if (addDefaultSess) {
|
||||
char *sess = tt_default_session();
|
||||
status = tt_pattern_session_add( pat, sess );
|
||||
tt_free( sess );
|
||||
if (status != TT_OK) {
|
||||
return (Tt_pattern)tt_error_pointer( status );
|
||||
}
|
||||
}
|
||||
if (file != 0) {
|
||||
status = tt_pattern_file_add( pat, file );
|
||||
if (status != TT_OK) {
|
||||
return (Tt_pattern)tt_error_pointer( status );
|
||||
}
|
||||
}
|
||||
if (op != 0) {
|
||||
status = tt_pattern_op_add( pat, _ttDtOp( op ) );
|
||||
if (status != TT_OK) {
|
||||
return (Tt_pattern)tt_error_pointer( status );
|
||||
}
|
||||
}
|
||||
status = tt_pattern_callback_add( pat, _ttDtPatternCB );
|
||||
if (status != TT_OK) {
|
||||
return (Tt_pattern)tt_error_pointer( status );
|
||||
}
|
||||
status = tt_pattern_user_set( pat, _TttkCBKey, cb );
|
||||
if (status != TT_OK) {
|
||||
return (Tt_pattern)tt_error_pointer( status );
|
||||
}
|
||||
status = tt_pattern_user_set( pat, _TttkClientCBKey, clientCB );
|
||||
if (status != TT_OK) {
|
||||
return (Tt_pattern)tt_error_pointer( status );
|
||||
}
|
||||
status = tt_pattern_user_set( pat, _TttkClientDataKey, clientData );
|
||||
if (status != TT_OK) {
|
||||
return (Tt_pattern)tt_error_pointer( status );
|
||||
}
|
||||
if (registerIt) {
|
||||
status = tt_pattern_register( pat );
|
||||
if (status != TT_OK) {
|
||||
return (Tt_pattern)tt_error_pointer( status );
|
||||
}
|
||||
}
|
||||
fuse = (caddr_t)0;
|
||||
return pat;
|
||||
}
|
||||
|
||||
Tt_message
|
||||
_tttk_pattern_contract(
|
||||
Tt_pattern pat
|
||||
)
|
||||
{
|
||||
void *p = tt_pattern_user( pat, _TttkContractKey );
|
||||
Tt_status status = tt_ptr_error( p );
|
||||
if (status != TT_OK) {
|
||||
return 0;
|
||||
}
|
||||
return (Tt_message)p;
|
||||
}
|
||||
36
cde/lib/tt/lib/tttk/tttkpattern.h
Normal file
36
cde/lib/tt/lib/tttk/tttkpattern.h
Normal file
@@ -0,0 +1,36 @@
|
||||
/*%% (c) Copyright 1993, 1994 Hewlett-Packard Company */
|
||||
/*%% (c) Copyright 1993, 1994 International Business Machines Corp. */
|
||||
/*%% (c) Copyright 1993, 1994 Sun Microsystems, Inc. */
|
||||
/*%% (c) Copyright 1993, 1994 Novell, Inc. */
|
||||
/*%% $XConsortium: tttkpattern.h /main/3 1995/10/23 10:33:51 rswiston $ */
|
||||
/* -*-C++-*-
|
||||
*
|
||||
* @(#)tttkpattern.h 1.3 93/09/07
|
||||
*
|
||||
* Copyright 1993 Sun Microsystems, Inc. All rights reserved.
|
||||
*/
|
||||
#ifndef tttkpattern_h
|
||||
#define tttkpattern_h
|
||||
|
||||
#include "tttk/tttk.h"
|
||||
#include "tttk/tttkmessage.h"
|
||||
|
||||
Tt_status _tttk_patterns_destroy(
|
||||
Tt_pattern *pats
|
||||
);
|
||||
Tt_pattern _ttDtPatternCreate(
|
||||
Tt_category category,
|
||||
Tt_scope theScope,
|
||||
int addDefaultSess,
|
||||
const char *file,
|
||||
Tttk_op op,
|
||||
_TtDtMessageCB cb,
|
||||
void *clientCB,
|
||||
void *clientData,
|
||||
int registerIt
|
||||
);
|
||||
Tt_message _tttk_pattern_contract(
|
||||
Tt_pattern pat
|
||||
);
|
||||
|
||||
#endif
|
||||
163
cde/lib/tt/lib/tttk/tttkutils.C
Normal file
163
cde/lib/tt/lib/tttk/tttkutils.C
Normal file
@@ -0,0 +1,163 @@
|
||||
//%% (c) Copyright 1993, 1994 Hewlett-Packard Company
|
||||
//%% (c) Copyright 1993, 1994 International Business Machines Corp.
|
||||
//%% (c) Copyright 1993, 1994 Sun Microsystems, Inc.
|
||||
//%% (c) Copyright 1993, 1994 Novell, Inc.
|
||||
//%% $XConsortium: tttkutils.C /main/4 1996/02/27 16:06:59 drk $
|
||||
/*
|
||||
* @(#)tttkutils.C 1.3 93/09/07
|
||||
*
|
||||
* Copyright 1993 Sun Microsystems, Inc. All rights reserved.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include "api/c/tt_c.h"
|
||||
#include "util/tt_port.h"
|
||||
#include "api/c/api_api.h"
|
||||
#include "tttk/tttk.h"
|
||||
#include "tttk/tttkutils.h"
|
||||
|
||||
char _TttkKeys[ _TttkNumKeys ] = { 0 };
|
||||
|
||||
// Array of supported desktop messages
|
||||
|
||||
const char *TtDtOps[] = {
|
||||
"TtDtOpNone",
|
||||
"Created",
|
||||
"Deleted",
|
||||
"Do_Command",
|
||||
"Set_Environment",
|
||||
"Get_Environment",
|
||||
"Set_Geometry",
|
||||
"Get_Geometry",
|
||||
"Set_Iconified",
|
||||
"Get_Iconified",
|
||||
"Set_Locale",
|
||||
"Get_Locale",
|
||||
"Set_Mapped",
|
||||
"Get_Mapped",
|
||||
"Modified",
|
||||
"Reverted",
|
||||
"Get_Modified",
|
||||
"Moved",
|
||||
"Pause",
|
||||
"Resume",
|
||||
"Quit",
|
||||
"Raise",
|
||||
"Lower",
|
||||
"Save",
|
||||
"Revert",
|
||||
"Saved",
|
||||
"Set_Situation",
|
||||
"Get_Situation",
|
||||
"Signal",
|
||||
"Started",
|
||||
"Stopped",
|
||||
"Status",
|
||||
"Get_Status",
|
||||
"Get_Sysinfo",
|
||||
"Set_XInfo",
|
||||
"Get_XInfo",
|
||||
"Abstract",
|
||||
"Deposit",
|
||||
"Display",
|
||||
"Edit",
|
||||
"Edit",
|
||||
"Interpret",
|
||||
"Print",
|
||||
"Translate",
|
||||
"Mail",
|
||||
"Mail",
|
||||
"Mail",
|
||||
"Instantiate"
|
||||
};
|
||||
|
||||
Tt_callback_action
|
||||
_ttDtCallbackAction(
|
||||
Tt_message msg
|
||||
)
|
||||
{
|
||||
Tt_status status = tt_ptr_error( msg );
|
||||
if ((status != TT_OK) || (msg == 0)) {
|
||||
return TT_CALLBACK_PROCESSED;
|
||||
} else {
|
||||
return TT_CALLBACK_CONTINUE;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
_ttDtPrint(
|
||||
const char *whence,
|
||||
const char *msg
|
||||
)
|
||||
{
|
||||
_tt_syslog( 0, LOG_ERR, "%s: %s", whence, msg );
|
||||
}
|
||||
|
||||
void
|
||||
_ttDtPrintStatus(
|
||||
const char *whence,
|
||||
const char *expr,
|
||||
Tt_status status
|
||||
)
|
||||
{
|
||||
_tt_syslog( 0, LOG_ERR, "%s: %s: %s\n",
|
||||
whence, expr, tt_status_message( status ));
|
||||
}
|
||||
|
||||
void
|
||||
_ttDtPrintInt(
|
||||
const char *whence,
|
||||
const char *expr,
|
||||
int n
|
||||
)
|
||||
{
|
||||
_tt_syslog( 0, LOG_ERR, "%s: %s: %d\n", whence, expr, n );
|
||||
}
|
||||
|
||||
void
|
||||
_ttDtPError(
|
||||
const char *whence,
|
||||
const char *msg
|
||||
)
|
||||
{
|
||||
_tt_syslog( 0, LOG_ERR, "%s: %s: %m", whence, msg );
|
||||
}
|
||||
|
||||
Tttk_op
|
||||
tttk_string_op(
|
||||
const char *s
|
||||
)
|
||||
{
|
||||
if (s == 0) return TTDT_OP_NONE;
|
||||
for (int op = TTDT_OP_NONE; op < TTDT_OP_LAST; op++) {
|
||||
const char *opStr = _ttDtOp( (Tttk_op)op );
|
||||
if (opStr == 0) {
|
||||
continue;
|
||||
}
|
||||
if (strcmp( opStr, s ) == 0) {
|
||||
return (Tttk_op)op;
|
||||
}
|
||||
}
|
||||
return TTDT_OP_NONE;
|
||||
}
|
||||
|
||||
const char *
|
||||
_ttDtOp(
|
||||
Tttk_op op
|
||||
)
|
||||
{
|
||||
if ((op > TTDT_OP_NONE) && (op < TTDT_OP_LAST)) {
|
||||
return TtDtOps[ op ];
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
char *
|
||||
tttk_op_string(
|
||||
Tttk_op op
|
||||
)
|
||||
{
|
||||
return _tt_strdup( _ttDtOp( op ));
|
||||
}
|
||||
51
cde/lib/tt/lib/tttk/tttkutils.h
Normal file
51
cde/lib/tt/lib/tttk/tttkutils.h
Normal file
@@ -0,0 +1,51 @@
|
||||
/*%% (c) Copyright 1993, 1994 Hewlett-Packard Company */
|
||||
/*%% (c) Copyright 1993, 1994 International Business Machines Corp. */
|
||||
/*%% (c) Copyright 1993, 1994 Sun Microsystems, Inc. */
|
||||
/*%% (c) Copyright 1993, 1994 Novell, Inc. */
|
||||
/*%% $XConsortium: tttkutils.h /main/3 1995/10/23 10:34:07 rswiston $ */
|
||||
/*
|
||||
* @(#)tttkutils.h 1.3 93/09/07
|
||||
*
|
||||
* Copyright 1993 Sun Microsystems, Inc. All rights reserved.
|
||||
*/
|
||||
#ifndef ttdtutils_h
|
||||
#define ttdtutils_h
|
||||
|
||||
extern char _TttkKeys[];
|
||||
|
||||
#define _TttkCBKey ((int)(long)&_TttkKeys[0])
|
||||
#define _TttkClientCBKey ((int)(long)&_TttkKeys[1])
|
||||
#define _TttkClientDataKey ((int)(long)&_TttkKeys[2])
|
||||
#define _TttkDepositPatKey ((int)(long)&_TttkKeys[3])
|
||||
#define _TttkJoinInfoKey ((int)(long)&_TttkKeys[4])
|
||||
#define _TttkContractKey ((int)(long)&_TttkKeys[5])
|
||||
#define _TttkSubContractKey ((int)(long)&_TttkKeys[6])
|
||||
|
||||
const int _TttkNumKeys = 7;
|
||||
|
||||
void _ttDtPrint(
|
||||
const char *whence,
|
||||
const char *msg
|
||||
);
|
||||
void _ttDtPrintStatus(
|
||||
const char *whence,
|
||||
const char *expr,
|
||||
Tt_status err
|
||||
);
|
||||
void _ttDtPrintInt(
|
||||
const char *whence,
|
||||
const char *msg,
|
||||
int n
|
||||
);
|
||||
void _ttDtPError(
|
||||
const char *whence,
|
||||
const char *msg
|
||||
);
|
||||
const char *_ttDtOp(
|
||||
Tttk_op op
|
||||
);
|
||||
Tt_callback_action _ttDtCallbackAction(
|
||||
Tt_message msg
|
||||
);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user