Blame lib/Mrm/Mrmmodule.c

Packit b099d7
/* 
Packit b099d7
 * Motif
Packit b099d7
 *
Packit b099d7
 * Copyright (c) 1987-2012, The Open Group. All rights reserved.
Packit b099d7
 *
Packit b099d7
 * These libraries and programs are free software; you can
Packit b099d7
 * redistribute them and/or modify them under the terms of the GNU
Packit b099d7
 * Lesser General Public License as published by the Free Software
Packit b099d7
 * Foundation; either version 2 of the License, or (at your option)
Packit b099d7
 * any later version.
Packit b099d7
 *
Packit b099d7
 * These libraries and programs are distributed in the hope that
Packit b099d7
 * they will be useful, but WITHOUT ANY WARRANTY; without even the
Packit b099d7
 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
Packit b099d7
 * PURPOSE. See the GNU Lesser General Public License for more
Packit b099d7
 * details.
Packit b099d7
 *
Packit b099d7
 * You should have received a copy of the GNU Lesser General Public
Packit b099d7
 * License along with these librararies and programs; if not, write
Packit b099d7
 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
Packit b099d7
 * Floor, Boston, MA 02110-1301 USA
Packit b099d7
 */ 
Packit b099d7
/* 
Packit b099d7
 * HISTORY
Packit b099d7
 */ 
Packit b099d7
#ifdef HAVE_CONFIG_H
Packit b099d7
#include <config.h>
Packit b099d7
#endif
Packit b099d7
Packit b099d7
Packit b099d7
#ifdef REV_INFO
Packit b099d7
#ifndef lint
Packit b099d7
static char rcsid[] = "$XConsortium: Mrmmodule.c /main/12 1996/11/13 14:03:12 drk $"
Packit b099d7
#endif
Packit b099d7
#endif
Packit b099d7
Packit b099d7
/* (c) Copyright 1989, 1990, DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS. */
Packit b099d7
Packit b099d7
/*
Packit b099d7
 *++
Packit b099d7
 *  FACILITY:
Packit b099d7
 *
Packit b099d7
 *      UIL Resource Manager (URM):
Packit b099d7
 *
Packit b099d7
 *  ABSTRACT:
Packit b099d7
 *
Packit b099d7
 *	These routines get and put data entries from a record into a buffer.
Packit b099d7
 *
Packit b099d7
 *--
Packit b099d7
 */
Packit b099d7
Packit b099d7
Packit b099d7
/*
Packit b099d7
 *
Packit b099d7
 *  INCLUDE FILES
Packit b099d7
 *
Packit b099d7
 */
Packit b099d7
Packit b099d7
#include <Mrm/MrmAppl.h>
Packit b099d7
#include <Mrm/Mrm.h>
Packit b099d7
#include "MrmMsgI.h"
Packit b099d7
Packit b099d7
Packit b099d7
/*
Packit b099d7
 *
Packit b099d7
 *  TABLE OF CONTENTS
Packit b099d7
 *
Packit b099d7
 *	UrmIFMInitModule		- Init module in a context
Packit b099d7
 *
Packit b099d7
 *	UrmIFMSetTopmost		- Set a topmost widget in module
Packit b099d7
 *
Packit b099d7
 *	UrmIFMPutModule			- Write module to IDB file
Packit b099d7
 *
Packit b099d7
 *	UrmIFMHGetModule		- Get module from hierarchy
Packit b099d7
 *
Packit b099d7
 *	UrmIFMGetModule			- Get module from IDB file
Packit b099d7
 *
Packit b099d7
 *
Packit b099d7
 */
Packit b099d7
Packit b099d7
Packit b099d7
/*
Packit b099d7
 *
Packit b099d7
 *  MACROS
Packit b099d7
 *
Packit b099d7
 */
Packit b099d7
Packit b099d7
/*
Packit b099d7
 * Macro to validate a resource context and bind interface module pointer
Packit b099d7
 *
Packit b099d7
 * Formal parameters:
Packit b099d7
 *	ctx_ptr		variable bound to context pointer
Packit b099d7
 *	routine		quoted string giving routine name
Packit b099d7
 *	recptr		variable to be bound to module pointer
Packit b099d7
 *
Packit b099d7
 * WARNING: Don't use expressions where variables are expected!
Packit b099d7
 *
Packit b099d7
 */
Packit b099d7
#define	_validate_context(ctx_ptr,routine,recptr)		\
Packit b099d7
 {								\
Packit b099d7
  if ( ! UrmRCValid(ctx_ptr) )					\
Packit b099d7
    return Urm__UT_Error (routine, _MrmMMsg_0043,		\
Packit b099d7
			  NULL, ctx_ptr, MrmBAD_CONTEXT) ;	\
Packit b099d7
  recptr = (RGMModuleDescPtr) UrmRCBuffer (ctx_ptr) ;		\
Packit b099d7
 }
Packit b099d7
Packit b099d7

Packit b099d7
/*
Packit b099d7
 *++
Packit b099d7
 *
Packit b099d7
 *  PROCEDURE DESCRIPTION:
Packit b099d7
 *
Packit b099d7
 *	UrmIFMInitModule initializes a context for creating a new
Packit b099d7
 *	interface module. It stores the access and lock attributes, and
Packit b099d7
 *	sizes and initializes the topmost widget descriptors for the number
Packit b099d7
 *	of widgets specified.
Packit b099d7
 *
Packit b099d7
 *	This routine sets all the context parameters, including group,
Packit b099d7
 *	type, and size.
Packit b099d7
 *
Packit b099d7
 *  FORMAL PARAMETERS:
Packit b099d7
 *
Packit b099d7
 *	context_id	URM resource context in which to build the
Packit b099d7
 *			interface module
Packit b099d7
 *	num_widget	number of topmost widgets to allocate in module
Packit b099d7
 *	access		The module's access attribute, URMaPublic or
Packit b099d7
 *			URMaPrivate
Packit b099d7
 *	lock		The module's locking attribute, TRUE to lock the
Packit b099d7
 *			module
Packit b099d7
 *
Packit b099d7
 *  IMPLICIT INPUTS:
Packit b099d7
 *
Packit b099d7
 *  IMPLICIT OUTPUTS:
Packit b099d7
 *
Packit b099d7
 *  FUNCTION VALUE:
Packit b099d7
 *
Packit b099d7
 *	MrmSUCCESS	operation succeeded
Packit b099d7
 *	MrmBAD_CONTEXT	invalid resource context
Packit b099d7
 *	MrmTOO_MANY	number of indexes exceeds internal limit
Packit b099d7
 *	MrmFAILURE	unexplained failure
Packit b099d7
 *
Packit b099d7
 *  SIDE EFFECTS:
Packit b099d7
 *
Packit b099d7
 *--
Packit b099d7
 */
Packit b099d7
Packit b099d7
Cardinal 
Packit b099d7
UrmIFMInitModule (URMResourceContextPtr		context_id,
Packit b099d7
		  MrmCount			num_widget,
Packit b099d7
		  MrmCode			access,
Packit b099d7
		  MrmCode			lock)
Packit b099d7
{
Packit b099d7
  /*
Packit b099d7
   *  Local variables
Packit b099d7
   */
Packit b099d7
  Cardinal		result ;	/* Function results */
Packit b099d7
  RGMModuleDescPtr	ifmodptr ;	/* IF module in context */
Packit b099d7
  MrmCount		descsiz ;	/* # bytes for descriptor */
Packit b099d7
  int			ndx ;		/* loop index */
Packit b099d7
Packit b099d7
Packit b099d7
  /*
Packit b099d7
   * validate context and bind pointer. Size check.
Packit b099d7
   */
Packit b099d7
  _validate_context (context_id, "UrmIFMInitModule", ifmodptr) ;
Packit b099d7
  if ( num_widget >= RGMListSizeMax )
Packit b099d7
    return Urm__UT_Error ("UrmIFMInitModule", _MrmMMsg_0044,
Packit b099d7
			  NULL, context_id, MrmTOO_MANY) ;
Packit b099d7
Packit b099d7
  /*
Packit b099d7
   * compute descriptor size and guarantee space. Null all the widgets.
Packit b099d7
   */
Packit b099d7
  descsiz = sizeof(RGMModuleDesc) + (num_widget-1)*sizeof(RGMTopmostDesc) ;
Packit b099d7
  descsiz = _FULLWORD (descsiz) ;
Packit b099d7
Packit b099d7
  result = UrmResizeResourceContext (context_id, descsiz) ;
Packit b099d7
  if ( result != MrmSUCCESS ) return result ;
Packit b099d7
Packit b099d7
  ifmodptr = (RGMModuleDescPtr) UrmRCBuffer(context_id) ;
Packit b099d7
  ifmodptr->validation = URMInterfaceModuleValid ;
Packit b099d7
  ifmodptr->count = num_widget ;
Packit b099d7
  ifmodptr->annex1 = 0 ;
Packit b099d7
  ifmodptr->annex2 = 0 ;
Packit b099d7
Packit b099d7
  for ( ndx=0 ; ndx
Packit b099d7
    strcpy (ifmodptr->topmost[ndx].index, "") ;
Packit b099d7
Packit b099d7
  /*
Packit b099d7
   * Set context parameters
Packit b099d7
   */
Packit b099d7
  UrmRCSetSize (context_id, descsiz) ;
Packit b099d7
  UrmRCSetGroup (context_id, URMgResourceSet) ;
Packit b099d7
  UrmRCSetType (context_id, URMrsInterfaceModule) ;
Packit b099d7
  UrmRCSetAccess (context_id, access) ;
Packit b099d7
  UrmRCSetLock (context_id, lock) ;
Packit b099d7
Packit b099d7
  /*
Packit b099d7
   * Successfully created
Packit b099d7
   */
Packit b099d7
  return MrmSUCCESS ;
Packit b099d7
Packit b099d7
}
Packit b099d7
Packit b099d7
Packit b099d7

Packit b099d7
/*
Packit b099d7
 *++
Packit b099d7
 *
Packit b099d7
 *  PROCEDURE DESCRIPTION:
Packit b099d7
 *
Packit b099d7
 *	This routine sets the topmost widget index for one of the topmost
Packit b099d7
 *	widgets specified by an interface module.
Packit b099d7
 *
Packit b099d7
 *  FORMAL PARAMETERS:
Packit b099d7
 *
Packit b099d7
 *	context_id	resource context holding a valid interface module
Packit b099d7
 *	topmost_ndx	0-based index of the widget in the module
Packit b099d7
 *	index		the widget's index (name)
Packit b099d7
 *
Packit b099d7
 *  IMPLICIT INPUTS:
Packit b099d7
 *
Packit b099d7
 *  IMPLICIT OUTPUTS:
Packit b099d7
 *
Packit b099d7
 *  FUNCTION VALUE:
Packit b099d7
 *
Packit b099d7
 *	MrmSUCCESS	operation succeeded
Packit b099d7
 *	MrmBAD_IF_MODULE	invalid interface module
Packit b099d7
 *	MrmOUT_OF_BOUNDS	topmost_ndx out of bounds
Packit b099d7
 *
Packit b099d7
 *  SIDE EFFECTS:
Packit b099d7
 *
Packit b099d7
 *--
Packit b099d7
 */
Packit b099d7
Packit b099d7
Cardinal 
Packit b099d7
UrmIFMSetTopmost (URMResourceContextPtr		context_id ,
Packit b099d7
		  Cardinal			topmost_ndx ,
Packit b099d7
		  String			index )
Packit b099d7
Packit b099d7
{
Packit b099d7
Packit b099d7
  /*
Packit b099d7
   *  Local variables
Packit b099d7
   */
Packit b099d7
  RGMModuleDescPtr	ifmodptr ;	/* IF module in context */
Packit b099d7
Packit b099d7
Packit b099d7
  /*
Packit b099d7
   * Validate context and interface module. Make sure the index is in bounds
Packit b099d7
   */
Packit b099d7
  _validate_context (context_id, "UrmIFMSetTopmost", ifmodptr) ;
Packit b099d7
  if ( ifmodptr->validation != URMInterfaceModuleValid )
Packit b099d7
    return Urm__UT_Error ("UrmIFMSetTopmost", _MrmMMsg_0025,
Packit b099d7
			  NULL, context_id, MrmBAD_IF_MODULE) ;
Packit b099d7
Packit b099d7
  if ( topmost_ndx >= ifmodptr->count )
Packit b099d7
    return Urm__UT_Error ("UrmIFMSetTopmost", _MrmMMsg_0045,
Packit b099d7
			  NULL, context_id, MrmOUT_OF_BOUNDS) ;
Packit b099d7
Packit b099d7
  /*
Packit b099d7
   * Copy in index, and return
Packit b099d7
   */
Packit b099d7
  strncat (ifmodptr->topmost[topmost_ndx].index, index, URMMaxIndexLen) ;
Packit b099d7
Packit b099d7
  return MrmSUCCESS ;
Packit b099d7
Packit b099d7
}
Packit b099d7
Packit b099d7

Packit b099d7
/*
Packit b099d7
 *++
Packit b099d7
 *
Packit b099d7
 *  PROCEDURE DESCRIPTION:
Packit b099d7
 *
Packit b099d7
 *	UrmIFMPutModule creates a resource set entry of type interface
Packit b099d7
 *	module in the given IDB file. The access and locking attriutes
Packit b099d7
 *	are taken from the context.
Packit b099d7
 *
Packit b099d7
 *  FORMAL PARAMETERS:
Packit b099d7
 *
Packit b099d7
 *	file_id		IDB file into which to write the interface module
Packit b099d7
 *	index		index (name) under which to enter the module
Packit b099d7
 *	context_id	URM resource context containing the module
Packit b099d7
 *			representation. This must be a valid interface
Packit b099d7
 *			module.
Packit b099d7
 *
Packit b099d7
 *  IMPLICIT INPUTS:
Packit b099d7
 *
Packit b099d7
 *  IMPLICIT OUTPUTS:
Packit b099d7
 *
Packit b099d7
 *	MrmSUCCESS	Operation succeeded
Packit b099d7
 *	MrmBAD_CONTEXT	invalid resource context
Packit b099d7
 *	MrmBAD_IF_MODULE	invalid interface module in context
Packit b099d7
 *	Others		see UrmIdbPutIndexedResource
Packit b099d7
 *
Packit b099d7
 *  FUNCTION VALUE:
Packit b099d7
 *
Packit b099d7
 *  SIDE EFFECTS:
Packit b099d7
 *
Packit b099d7
 *--
Packit b099d7
 */
Packit b099d7
Packit b099d7
Cardinal 
Packit b099d7
UrmIFMPutModule (IDBFile		file_id ,
Packit b099d7
		 String			index ,
Packit b099d7
		 URMResourceContextPtr	context_id )
Packit b099d7
{
Packit b099d7
Packit b099d7
  /*
Packit b099d7
   *  Local variables
Packit b099d7
   */
Packit b099d7
  Cardinal		result ;	/* Function results */
Packit b099d7
  RGMModuleDescPtr	ifmodptr ;	/* IF module in context */
Packit b099d7
Packit b099d7
Packit b099d7
  /*
Packit b099d7
   * Validate context and interface module.
Packit b099d7
   */
Packit b099d7
  _validate_context (context_id, "UrmIFMPutModule", ifmodptr) ;
Packit b099d7
  if ( ifmodptr->validation != URMInterfaceModuleValid )
Packit b099d7
    return Urm__UT_Error ("UrmIFMPutModule", _MrmMMsg_0025,
Packit b099d7
			  NULL, context_id, MrmBAD_IF_MODULE) ;
Packit b099d7
Packit b099d7
  /*
Packit b099d7
   * Make sure the context is properly set, then put the module in the file
Packit b099d7
   */
Packit b099d7
  UrmRCSetGroup (context_id, URMgResourceSet) ;
Packit b099d7
  UrmRCSetType (context_id, URMrsInterfaceModule) ;
Packit b099d7
Packit b099d7
  result = UrmIdbPutIndexedResource (file_id, index, context_id) ;
Packit b099d7
  return result ;
Packit b099d7
Packit b099d7
}
Packit b099d7
Packit b099d7
Packit b099d7

Packit b099d7
/*
Packit b099d7
 *++
Packit b099d7
 *
Packit b099d7
 *  PROCEDURE DESCRIPTION:
Packit b099d7
 *
Packit b099d7
 *	UrmIFMHGetModule searches the database hierarchy for the module
Packit b099d7
 *	given its index. It returns the module descriptor in the resource
Packit b099d7
 *	context.
Packit b099d7
 *
Packit b099d7
 *  FORMAL PARAMETERS:
Packit b099d7
 *
Packit b099d7
 *	hierarchy_id	id of an open URM database hierarchy
Packit b099d7
 *	index		index (name) of the desired interface module
Packit b099d7
 *	context_id	resource context into which to read the module
Packit b099d7
 *	file_id_return	to return IDB file in which the module is found
Packit b099d7
 *
Packit b099d7
 *  IMPLICIT INPUTS:
Packit b099d7
 *
Packit b099d7
 *  IMPLICIT OUTPUTS:
Packit b099d7
 *
Packit b099d7
 *  FUNCTION VALUE:
Packit b099d7
 *
Packit b099d7
 *	MrmSUCCESS	module found and loaded in context
Packit b099d7
 *	MrmNOT_FOUND	module not found in hierarchy
Packit b099d7
 *	MrmBAD_HIERARCHY	hierarchy not valid
Packit b099d7
 *	Others		See UrmGetModule
Packit b099d7
 *
Packit b099d7
 *  SIDE EFFECTS:
Packit b099d7
 *
Packit b099d7
 *--
Packit b099d7
 */
Packit b099d7
Packit b099d7
Cardinal 
Packit b099d7
UrmIFMHGetModule (MrmHierarchy		hierarchy_id ,
Packit b099d7
		  String		index ,
Packit b099d7
		  URMResourceContextPtr	context_id ,
Packit b099d7
		  IDBFile		*file_id_return )
Packit b099d7
{
Packit b099d7
Packit b099d7
  /*
Packit b099d7
   *  Local variables
Packit b099d7
   */
Packit b099d7
  Cardinal		result ;	/* function results */
Packit b099d7
Packit b099d7
  /*
Packit b099d7
   * Get the module
Packit b099d7
   */
Packit b099d7
  result = UrmHGetIndexedResource
Packit b099d7
    (hierarchy_id, index, URMgResourceSet, URMrsInterfaceModule,
Packit b099d7
     context_id, file_id_return) ;
Packit b099d7
Packit b099d7
  return result ;
Packit b099d7
Packit b099d7
}
Packit b099d7
Packit b099d7
Packit b099d7

Packit b099d7
/*
Packit b099d7
 *++
Packit b099d7
 *
Packit b099d7
 *  PROCEDURE DESCRIPTION:
Packit b099d7
 *
Packit b099d7
 *	UrmIFMGetModule retrieves an interface module from an IDB file, and
Packit b099d7
 *	reads it into the given resource context.
Packit b099d7
 *
Packit b099d7
 *  FORMAL PARAMETERS:
Packit b099d7
 *
Packit b099d7
 *	file_id		open IDB file from which to retrieve module
Packit b099d7
 *	index		index (name) of the desired interface module
Packit b099d7
 *	context_id	resource context into which to read the module
Packit b099d7
 *
Packit b099d7
 *  IMPLICIT INPUTS:
Packit b099d7
 *
Packit b099d7
 *  IMPLICIT OUTPUTS:
Packit b099d7
 *
Packit b099d7
 *  FUNCTION VALUE:
Packit b099d7
 *
Packit b099d7
 *	MrmSUCCESS	operation succeeded
Packit b099d7
 *	DMBadContext	invalid resource context
Packit b099d7
 *	MrmBAD_IF_MODULE	invalid interface module found in file
Packit b099d7
 *	Others		see UrmIdbGetIndexedResource
Packit b099d7
 *
Packit b099d7
 *  SIDE EFFECTS:
Packit b099d7
 *
Packit b099d7
 *--
Packit b099d7
 */
Packit b099d7
Packit b099d7
Cardinal 
Packit b099d7
UrmIFMGetModule (IDBFile		file_id ,
Packit b099d7
		 String			index ,
Packit b099d7
		 URMResourceContextPtr	context_id )
Packit b099d7
{
Packit b099d7
Packit b099d7
  /*
Packit b099d7
   *  Local variables
Packit b099d7
   */
Packit b099d7
  Cardinal		result ;	/* function results */
Packit b099d7
  RGMModuleDescPtr	ifmodptr ;	/* IF module in context */
Packit b099d7
Packit b099d7
Packit b099d7
  /*
Packit b099d7
   * Validate context, then attempt the read
Packit b099d7
   */
Packit b099d7
  if ( ! UrmRCValid(context_id) )
Packit b099d7
    return Urm__UT_Error ("UrmIFMGetModule", _MrmMMsg_0043,
Packit b099d7
			  file_id, context_id, MrmBAD_CONTEXT) ;
Packit b099d7
Packit b099d7
  result = UrmIdbGetIndexedResource (file_id, index, URMgResourceSet,
Packit b099d7
				     URMrsInterfaceModule, context_id) ;
Packit b099d7
  if ( result != MrmSUCCESS ) return result ;
Packit b099d7
Packit b099d7
  /*
Packit b099d7
   * validate the interface module
Packit b099d7
   */
Packit b099d7
  ifmodptr = (RGMModuleDescPtr) UrmRCBuffer(context_id) ;
Packit b099d7
  if ( ifmodptr->validation != URMInterfaceModuleValid )
Packit b099d7
    return Urm__UT_Error ("UrmIFMPutModule", _MrmMMsg_0025,
Packit b099d7
			  NULL, context_id, MrmBAD_IF_MODULE) ;
Packit b099d7
Packit b099d7
  /*
Packit b099d7
   * Successfully retrieved
Packit b099d7
   */
Packit b099d7
  return MrmSUCCESS ;
Packit b099d7
Packit b099d7
}
Packit b099d7