Add untested replicant framework

This commit is contained in:
Sasha Koshka
2023-11-13 00:39:44 -05:00
parent 854fbf371c
commit 55dfca6341
8 changed files with 445 additions and 19 deletions

View File

@@ -11,7 +11,10 @@ typedef long unsigned int XmdMapKey;
typedef struct _XmdMap XmdMap;
/* XmdMapIterator is a function that can iterate over a map. */
typedef Bool (*XmdMapIterator) (XmdMap *map, XmdMapKey key, void *value);
typedef Bool (*XmdMapIterator) (
XmdMap *map,
XmdMapKey key, void *value,
void *clientData);
/* XmdMapNew creates a new map.*/
XmdMap *XmdMapNew ();
@@ -27,7 +30,7 @@ void *XmdMapGet (XmdMap *map, XmdMapKey key);
void *XmdMapSet (XmdMap *map, XmdMapKey key, void *value);
/* XmdMapIterate calls iterator for each key/value pair in a map. */
void XmdMapIterate (XmdMap *map, XmdMapIterator iterator);
void XmdMapIterate (XmdMap *map, XmdMapIterator iterator, void *clientData);
/* XmdMapLength returns the number of key/value entries stored in a map. */
Cardinal XmdMapLength (XmdMap *map);

View File

@@ -0,0 +1,64 @@
#ifndef _XmdReplicant_h
#define _XmdReplicant_h
#include <X11/Xlib.h>
#include <X11/Intrinsic.h>
#include <Xm/Xm.h>
#include <Xmd/String.h>
#define XmdREPLICANT_VERSION 0
/* XmdReplicantState contains state information for a replicant instance. */
typedef struct _XmdReplicantState XmdReplicantState;
typedef int (*XmdReplicantVersion) ();
typedef Widget (*XmdReplicantCreate) (Widget parent, XmdReplicantState *state);
/* XmdReplicantOpen opens a replicant from the file located at path. Replicant
files hold state and point to shared object files containing their code.
Replicant shared objects are searched for in $XMD_REPLICANT_PATH. Here is an
example file that describes a calculator replicant:
[Calculator]
display=90
history=1 + 2 = 3;9 * 10 = 90;
mode=scientific
When a replicant's code is needed, it is automatically loaded by libXmd and
stays resident until all replicants using it have been freed. A system of
reference counting is used to accomplish this. =
Replicants must implement these symbols, where NAME is the base name of the
replicant's shared object file (case sensitive, and excluding the .so
extention):
int NAME_XmdReplicantVersion ();
Version must return the value of XmdREPLICANT_VERSION. This is used to detect
the API version that the replicant was compiled with, and applications with a
different API version will refuse to load it.
Widget NAME_XmdReplicantCreate (Widget parent, XmdReplicantState *state);
Create instantiates a new widget representing the replicant given by state.
*/
Widget XmdReplicantOpen (Widget parent, ConstString path);
/* XmdReplicantResolveName returns the file path of the given replicant shared
object name according to $XMD_REPLICANT_PATH. The returned string must be
freed using XtFree(). */
String XmdReplicantResolveName (ConstString name);
/* XmdReplicantStateQuery queries the replicant's state file for a named value.
The resulting string must be free'd using XtFree(). NULL is returned if there
is no value associated with the given name. This may perform a read from
disk. */
String XmdReplicantStateQuery (
XmdReplicantState *state,
ConstString name);
/* XmdReplicantStateStore stores a named value in the replicant's state file.
This may perform a write to disk. */
void XmdReplicantStateStore (
XmdReplicantState *state,
ConstString name, ConstString value);
#endif

View File

@@ -0,0 +1,6 @@
#ifndef _XmdString_h
#define _XmdString_h
typedef const char *ConstString;
#endif

View File

@@ -2,6 +2,7 @@
#define _XmdStringMap_h
#include <X11/Intrinsic.h>
#include <Xmd/String.h>
/* XmdStringMap is a hash map that is keyed by a string and can store any type
of element. */
@@ -9,13 +10,15 @@ typedef struct _XmdStringMap XmdStringMap;
/* XmdStringMapIterator is a function that can iterate over a string map. */
typedef Bool (*XmdStringMapIterator) (
XmdStringMap *map, String key, void *value);
XmdStringMap *map,
ConstString key, void *value,
void *clientData);
/* XmdStringMapNew creates a new map.*/
XmdStringMap *XmdStringMapNew ();
/* XmdStringMapGet retrieves a value from a map. */
void *XmdStringMapGet (XmdStringMap *map, String key);
void *XmdStringMapGet (XmdStringMap *map, ConstString key);
/* XmdStringMapSet sets a value in a map. The previous value associated with the
key, if it exists, is overwritten by the new value. If the value is set to
@@ -23,10 +26,12 @@ void *XmdStringMapGet (XmdStringMap *map, String key);
returns the previous value associated with the key so it can be free'd if
necessary.
*/
void *XmdStringMapSet (XmdStringMap *map, String key, void *value);
void *XmdStringMapSet (XmdStringMap *map, ConstString key, void *value);
/* XmdStringMapIterate calls iterator for each key/value pair in a map. */
void XmdStringMapIterate (XmdStringMap *map, XmdStringMapIterator iterator);
void XmdStringMapIterate (
XmdStringMap *map, XmdStringMapIterator iterator,
void *clientData);
/* XmdStringMapLength returns the number of key/value entries stored in a map.
*/