home *** CD-ROM | disk | FTP | other *** search
/ Oracle Video Server 3.0.3.1 / OVS_3031_NT.iso / win32 / medianet / server / include / yslog.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-15  |  15.5 KB  |  423 lines

  1. /* Copyright (c) 1996 by Oracle Corporation.  All Rights Reserved.
  2.  *
  3.  * yslog.h - Log Operations
  4.  *
  5.  * DESCRIPTION
  6.  * The logging mechanism provides a backbone for portable logging
  7.  * operations.  Messages are recorded by "facilities", or component
  8.  * parts of a "product".  Every message that is recorded is filtered
  9.  * and possibly passed to a "sink" which can process the message as
  10.  * is appropriate for the type of sink.  Most developers will need
  11.  * to use only ysRecord().
  12.  */
  13.  
  14. #ifndef YSLOG_ORACLE
  15. #define YSLOG_ORACLE
  16.  
  17. #ifndef SYSX_ORACLE
  18. #include <sysx.h>
  19. #endif
  20. #ifndef YSX_ORACLE
  21. #include <ysx.h>
  22. #endif
  23.  
  24. EXTC_START
  25.  
  26. /*
  27.  * BASIC PRIMITIVES
  28.  *
  29.  */
  30.  
  31. /*
  32.  * ysRecord - log a message
  33.  *
  34.  * DESCRIPTION
  35.  * ysRecord() causes a message to be logged.  The prod and fac identify
  36.  * where the message is generated from.  msgid is a message id number of
  37.  * the message.  Message identifiers must be unique within a product.
  38.  * 
  39.  * The severity may be one of the following (following syslog conventions):
  40.  *
  41.  *   YSLSEV_EMERG    - a panic condition
  42.  *   YSLSEV_ALERT    - a condition that should be corrected immediately
  43.  *   YSLSEV_CRIT     - critical conditions
  44.  *   YSLSEV_ERR      - errors
  45.  *   YSLSEV_WARNING  - warning messages
  46.  *   YSLSEV_NOTICE   - conditions that are not errors, but may require
  47.  *                     special handling
  48.  *   YSLSEV_INFO     - informational messages
  49.  *   YSLSEV_DEBUG(n) - messages that contain information normally of use
  50.  *                     only when debugging; (debugging messages are further
  51.  *                     subdivided into debug severities ranging from 0 to 8)
  52.  *
  53.  * assoc is an abstract association for the message.  It should be used to
  54.  * indicate in some sense on whose behalf the program is working when the
  55.  * message is recorded.
  56.  *
  57.  * The variable argument list passed to ysRecord() must be built using
  58.  * the following macros:
  59.  *
  60.  *   YSLSTR(char *v) - for strings
  61.  *   YSLUB4(ub4 v) - for unsigned integers
  62.  *   YSLSB4(sb4 v) - for signed integers
  63.  *   YSLSB8(sysb8 *v) - for signed 64-bit integers
  64.  *   YSLPTR(dvoid *ptr) - for raw pointers (converted to strings)
  65.  *   YSLOCTETS(size_t len, ub1 *buf) - for opaque buffers
  66.  *   YSLANY(CONST yotk *type, dvoid *ptr) - for all extended data types
  67.  *
  68.  * To terminate the argument list, use YSLEND.  An empty argument list
  69.  * should be denoted with YSLNONE in place of the variable part of the
  70.  * argument list.
  71.  */
  72. #define YSLSEV_EMERG    ((ub4) 0)
  73. #define YSLSEV_ALERT    ((ub4) 1)
  74. #define YSLSEV_CRIT     ((ub4) 2)
  75. #define YSLSEV_ERR      ((ub4) 3)
  76. #define YSLSEV_WARNING  ((ub4) 4)
  77. #define YSLSEV_NOTICE   ((ub4) 5)
  78. #define YSLSEV_INFO     ((ub4) 6)
  79. #define YSLSEV_DEBUG(n) ((ub4) (7 + (n)))
  80. #define YSLSEV_MAX      YSLSEV_DEBUG(8)
  81.  
  82. #define YSLSTR(v)       YSLSTR_ID, (v)
  83. #define YSLUB4(v)       YSLUB4_ID, (ub4) (v)
  84. #define YSLSB4(v)       YSLSB4_ID, (sb4) (v)
  85. #define YSLSB8(v)       YSLSB8_ID, (v)
  86. #define YSLPTR(p)       YSLPTR_ID, (dvoid *) (p)
  87. #define YSLOCTETS(l, b) YSLOCTETS_ID, (size_t) (l), (b)
  88. #define YSLANY(t, p)    YSLANY_ID, (CONST ub1 *) (t), (dvoid *) (p)
  89. #define YSLARGS(n, a)   YSLARGS_ID, (sword) (n), (a)              /* private */
  90. #define YSLEND          ((ub4) 0)
  91. #define YSLNONE         ((ub4) 0)
  92.  
  93. void ysRecord(CONST char *prod, CONST char *fac, ub4 msgid, ub4 sev,
  94.           CONST char *assoc, ...);
  95.  
  96. /*
  97.  * SINK MANIPULATION
  98.  *
  99.  * DESCRIPTION
  100.  * A sink is the possible destination of messages recorded using
  101.  * ysLogRecord().  Multiple independent sinks can be created.  For
  102.  * each sink, there is an associated filter callback and a record
  103.  * callback.  For every message, the filter callback is invoked.  If
  104.  * the filter callback returns TRUE, then the record callback is invoked
  105.  * to record the message.
  106.  */
  107. typedef struct yssnk  yssnk;                                  /* sink handle */
  108. typedef struct yslrec yslrec;                           /* record descriptor */
  109. typedef struct yslarg yslarg;                         /* argument descriptor */
  110.  
  111. /*
  112.  * ysFilterCB - filter callback
  113.  *
  114.  * DESCRIPTION
  115.  * The filter callback is invoked by the logging mechanism to determine
  116.  * if the record passed is selected by the filter.  fusrp is the same as
  117.  * passed to ysSinkSetFilter().  fes is a list of compiled filter
  118.  * expressions added to the sink with ysAddFilter().
  119.  */
  120. typedef boolean (*ysFilterCB)(dvoid *fusrp, yslst *fes, yslrec *rec);
  121.  
  122. /*
  123.  * ysRecordCB - record callback
  124.  *
  125.  * DESCRIPTION
  126.  * The record callback is invoked by the logging mechanism whenever
  127.  * the filter for the sink selects the message.  rusrp is the same as
  128.  * passed to ysSinkCreate().  The rec fields are set to describe the
  129.  * message.  See yslrec below for more information.
  130.  *
  131.  * This function is called once when the sink is destroyed for any
  132.  * cleanup that may be necessary.  This call is indicated by a null
  133.  * pointer for rec.
  134.  */
  135. typedef void (*ysRecordCB)(dvoid *rusrp, yslrec *rec);
  136.  
  137. /*
  138.  * ysSinkCreate - create a sink
  139.  *
  140.  * DESCRIPTION
  141.  * ysSinkCreate() creates a sink and returns a handle to the created sink.
  142.  * nm is the name of the sink, used for identification purposes.  sink names
  143.  * must be unique.
  144.  *
  145.  * reccb is the callback function that will be called to record messages.
  146.  * rusrp is the user pointer passed back to the callback function.  See
  147.  * ysRecordCB above.
  148.  *
  149.  * The nm argument is not copied.  The sink is created with no filter.
  150.  * This means that all records are selected by default.
  151.  *
  152.  * EXCEPTIONS
  153.  * YS_EX_ALREADY if the name is already in use
  154.  */
  155. yssnk *ysSinkCreate(CONST char *nm, ysRecordCB cb, dvoid *rusrp);
  156.  
  157. /*
  158.  * ysSinkDestroy - destroy a sink
  159.  *
  160.  * DESCRIPTION
  161.  * ysSinkDestroy() destroys a sink previously created with ysSinkCreate().
  162.  */
  163. void ysSinkDestroy(yssnk *sink);
  164.  
  165. /*
  166.  * ysSinkFind - find a sink by name
  167.  *
  168.  * DESCRIPTION
  169.  * ysSinkFind() finds a sink by name.  If it doesn't exist, a null pointer
  170.  * is returned.
  171.  */
  172. yssnk *ysSinkFind(CONST char *nm);
  173.  
  174. /*
  175.  * ysSinkSetFilter - set or replace filter for sink
  176.  *
  177.  * DESCRIPTION
  178.  * ysSinkSetFilter() associates a filter callback with a sink.  fusrp
  179.  * is the user pointer passed back to the callback when invoked.  See
  180.  * ysFilterCB above for more information.
  181.  *
  182.  * If oldfiltcb and oldfusrp are not null, the previous filter callback
  183.  * and user pointer are written.
  184.  */
  185. void ysSinkSetFilter(yssnk *sink, ysFilterCB filtcb, dvoid *fusrp,
  186.              ysFilterCB *oldfiltcb, dvoid **oldfusrp);
  187.  
  188. /*
  189.  * yslrec - record descriptor
  190.  *
  191.  * DESCRIPTION
  192.  * yslrec is the type of the record descriptor used to pass recorded
  193.  * messages to a callback sink routine.
  194.  *
  195.  * Product & Facility
  196.  *   The prod field points to the product name.  The fac field points
  197.  *   to the facility name.
  198.  *
  199.  * Association
  200.  *   The association is whatever was passed to ysLogRecord().  The pointer
  201.  *   is not guaranteed to be valid upon return from the callback.
  202.  *
  203.  * Severity
  204.  *   The sev field contains the severity of the message.  For the open
  205.  *   action, this field contains the severity of the sink.
  206.  *
  207.  * Message ID
  208.  *   The msgid field contains the message ID of the message.  For the
  209.  *   open action, this field contains the ID or range of the sink.
  210.  *
  211.  * Sequence
  212.  *   The seqid field contains a sequence ID that is process-wide, and is
  213.  *   incremented once for every call to ysLogRecord().
  214.  *
  215.  * Arguments
  216.  *   The arguments are passed in an argvec, whose shape is exactly
  217.  *   identical to YCIDL_sequence_yoany and may be safely cast to that.
  218.  *   The dummy slot exists for sequence compatibility.  narg specifies
  219.  *   the number of arguments in the args array.  Each element of the args
  220.  *   array is an argument passed to ysLogRecord().
  221.  */
  222. /* DISABLE check_naming */
  223. struct yslrec
  224. {
  225.   CONST char *prod;                                          /* product name */
  226.   CONST char *fac;                                          /* facility name */
  227.   CONST char *assoc;                                          /* association */
  228.   ub4         sev;                                               /* severity */
  229.   ub4         msgid;                                   /* message identifier */
  230.   ub4         seqid;                                      /* sequence number */
  231.   struct
  232.     {
  233.       ub4     dummy;                                          /* slot holder */
  234.       ub4     narg;                                   /* number of arguments */
  235.       yslarg *args;                                  /* argument descriptors */
  236.     } argvec;
  237. };
  238. /* ENABLE check_naming */
  239.  
  240. /*
  241.  * yslarg - argument descriptor
  242.  *
  243.  * DESCRIPTION
  244.  * yslarg is the type of the argument descriptors used to pass the variadic
  245.  * arguments passed to ysLogRecord().  A yslarg is exactly equivalent to
  246.  * an any structure in the object layer (and may be cast safely to yoany).
  247.  * The typecodes are themselves also typecodes as defined by the object
  248.  * layer.  They are safely castable to yotk.  (Pointers via YSLPTR have
  249.  * been converted to strings by the time it is passed to the callback.)
  250.  */
  251.  
  252. /* DISABLE check_naming */
  253. struct yslarg
  254. {
  255.   CONST ub1 *tc;                                                 /* typecode */
  256.   dvoid     *val;                                        /* pointer to value */
  257. };
  258. /* ENABLE check_naming */
  259.  
  260. /*
  261.  * ysSinkGetTypeId - get type id from typecode
  262.  *
  263.  * DESCRIPTION
  264.  * For processing of yslargs without requiring the object layer,
  265.  * (and for use in a switch statement), ysSinkGetTypeId() may be
  266.  * used to translate a typecode into one of the simple types below
  267.  * (convenient for doing a switch as well).
  268.  *
  269.  * Any unrecognized type code is identified with YSLANY_ID.  This
  270.  * does not mean that the val is a itself a yoany.  It simply means
  271.  * that the type code is not one of the other simple types.
  272.  *
  273.  * Note that YSLPTR_ID will never be returned by this function, since
  274.  * there is no typecode for pointers.
  275.  */
  276. #define YSLSTR_ID    ((ub4) 1)
  277. #define YSLUB4_ID    ((ub4) 2)
  278. #define YSLSB4_ID    ((ub4) 3)
  279. #define YSLSB8_ID    ((ub4) 4)
  280. #define YSLPTR_ID    ((ub4) 5)
  281. #define YSLOCTETS_ID ((ub4) 6)
  282. #define YSLANY_ID    ((ub4) 7)
  283. #define YSLARGS_ID   ((ub4) 8)                                    /* private */
  284.  
  285. ub4 ysSinkGetTypeId(CONST ub1 *tc);
  286.  
  287. /*
  288.  * TYPE CONVERSION REGISTRY
  289.  *
  290.  * DESCRIPTION
  291.  * Media Net maintains a registry for translation functions that apply
  292.  * to arbitrary typecodes.  There are two kinds of translation possible.
  293.  * The first translates a value into a stringified, printable form.  The
  294.  * second translates a value into an encoded binary form.
  295.  *
  296.  * These translations are suitable for the extension of almost any
  297.  * imaginable sink.  The translation functions may be registered at any
  298.  * time.  Registration associates a typecode with a callback.  When
  299.  * processing arguments, sinks will look up the appropriate callback
  300.  * by typecode.  Registering a null typecode provides a default callback
  301.  * that can handle any typecode.  yotkEncode() and yotkFormat() are such
  302.  * routines, and are automatically registered by yoInit().
  303.  *
  304.  * ysSinkRegister() registers one or the other or both callbacks for
  305.  * a particular typecode.  The typecode is not copied.  A null value
  306.  * may be passed for an inapplicable callback.  To unregister the
  307.  * callbacks, simply re-register with null callbacks.  ysSinkFmtLookup()
  308.  * and ysSinkEncLookup() look up the appropriate callback for the given
  309.  * typecode.  If none is found, null is returned.
  310.  */
  311. typedef char *(*ysSinkFmtCB)(CONST ub1 *tc, dvoid *val);
  312. typedef void (*ysSinkEncCB)(CONST ub1 *tc, dvoid *val, ysx *x);
  313.  
  314. void ysSinkRegister(CONST ub1 *tc, size_t tcsz,
  315.             ysSinkFmtCB fmtcb, ysSinkEncCB enccb);
  316.  
  317. ysSinkFmtCB ysSinkFmtLookup(CONST ub1 *tc);
  318. ysSinkEncCB ysSinkEncLookup(CONST ub1 *tc);
  319.  
  320. /*
  321.  * Typecode Names (PRIVATE USE ONLY)
  322.  */
  323. CONST ub1 *YSLSB4__getTC(void);
  324. CONST ub1 *YSLUB4__getTC(void);
  325. CONST ub1 *YSLSB8__getTC(void);
  326. CONST ub1 *YSLSTR__getTC(void);
  327. CONST ub1 *YSLOCTETS__getTC(void);
  328.  
  329. #define YSLSB4_TC       YSLSB4__getTC()
  330. #define YSLUB4_TC       YSLUB4__getTC()
  331. #define YSLSB8_TC       YSLSB8__getTC()
  332. #define YSLSTR_TC       YSLSTR__getTC()
  333. #define YSLOCTETS_TC    YSLOCTETS__getTC()
  334.  
  335. /*
  336.  * FILTER MANIPULATION
  337.  *
  338.  * DESCRIPTION
  339.  * During startup, a single sink named "tty" is created using
  340.  * ysSimpleFilter().  If the resource ys.log.tty.filter exists,
  341.  * the resource values are passed to ysAddFilter() for the tty
  342.  * sink.  The tty sink writes messages using yslError().  The
  343.  * messages are formatted using message text obtained from a
  344.  * message file.  The values of resource ys.log.msg-path define
  345.  * paths where the message file is searched for.
  346.  */
  347.  
  348. /*
  349.  * ysAddFilter - add a filter expression to a sink
  350.  *
  351.  * DESCRIPTION
  352.  * ysAddFilter() adds a filter expression to the given sink.  Filter
  353.  * expressions supported by this routine observe the following syntax:
  354.  *
  355.  *   expr ::= and-expr [ or and_expr ]
  356.  *   or ::= "OR" | ","
  357.  *   and-expr ::= primary [ [ "AND" ] primary ]
  358.  *   primary ::= "NOT" primary | predicate literal | relop-expr | "(" expr ")"
  359.  *   relop-expr ::= variable relop literal
  360.  *   relop ::= "<" | "<=" | "==" | "!=" | ">=" | ">"
  361.  *   literal ::= unquoted-string | quoted-string
  362.  *
  363.  * All whitespace is ignored, except as a token separator.  variable and
  364.  * predicate are identifiers, following C syntax.  An unquoted-string means
  365.  * that any unrecognized word (bounded by spaces, parentheses, commas and
  366.  * relational operators) constitutes a single string.  A quoted-string is
  367.  * a string that contains any character between two quotes (").
  368.  *
  369.  * The following predicates are defined:
  370.  *   prod <string> - true if the product is <string>
  371.  *   fac <string> - true if the facility is <string>
  372.  *   msg <int> - true if the message id is <int1>
  373.  *   msg <int1>:<int2> - true if the message id is between int1 and int2
  374.  *   maxsev <int> - true if the severity of the message is <= int
  375.  *
  376.  * The following variables are defined:
  377.  *   msgid - the message id
  378.  *   sev - the severity
  379.  *   assoc - the association
  380.  *   seqid - the sequence id
  381.  *
  382.  * To build your own filter as a superset of this, see ysLogGetMap() below.
  383.  */
  384. void ysAddFilter(yssnk *sink, CONST char *srcexpr);
  385. void ysClearFilters(yssnk *sink);
  386.  
  387. /*
  388.  * BUILT-IN FILTERS
  389.  */
  390.  
  391. /*
  392.  * ysFilterSimple - simple filter
  393.  *
  394.  * DESCRIPTION
  395.  * This simple filter merely evaluates each of the compiled filter
  396.  * expressions in turn until one of them is TRUE or until the list
  397.  * is exhausted, in which case the filter returns FALSE.
  398.  */
  399. boolean ysFilterSimple(dvoid *fusrp, yslst *les, yslrec *rec);
  400.  
  401. /*
  402.  * ysLogGetFilterMap - get built-in filter map
  403.  *
  404.  * DESCRIPTION
  405.  * To construct extended filters, call ysLogGetMap() to get the base
  406.  * filter map.  Then, extend this by adding additional rows in a new
  407.  * array.  The number of rows in the base filter map is written to
  408.  * *nmap.  The base filter map expects values to be in the vals array
  409.  * according to the index constants below.
  410.  */
  411. #define YSLOGFEVAL_PROD   ((ub1) 0)                                /* char * */
  412. #define YSLOGFEVAL_FAC    ((ub1) 1)                                /* char * */
  413. #define YSLOGFEVAL_MSGID  ((ub1) 2)                                 /* ub4 * */
  414. #define YSLOGFEVAL_SEV    ((ub1) 3)                                 /* ub4 * */
  415. #define YSLOGFEVAL_ASSOC  ((ub1) 4)                                /* char * */
  416. #define YSLOGFEVAL_SEQID  ((ub1) 5)                                 /* ub4 * */
  417. #define YSLOGFEVAL_MAX    6
  418.  
  419. CONST struct ysfemap *ysLogGetMap(sword *nmap);
  420.  
  421. EXTC_END
  422. #endif /* YSLOG_ORACLE */
  423.