1/*
2 * aolstub.cpp --
3 *
4 * Adds interface for loading the extension into the AOLserver.
5 *
6 * Copyright (c) 2002 by Zoran Vasiljevic.
7 *
8 * See the file "license.terms" for information on usage and redistribution
9 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
10 *
11 * Rcsid: @(#)$Id: aolstub.cpp,v 1.4 2003/03/17 09:01:23 vasiljevic Exp $
12 * ---------------------------------------------------------------------------
13 */
14
15#ifdef NS_AOLSERVER
16#include <ns.h>
17
18int Ns_ModuleVersion = 1;
19
20/*
21 * Structure to pass to NsThread_Init. This holds the module
22 * and virtual server name for proper interp initializations.
23 */
24
25struct mydata {
26    char *modname;
27    char *server;
28};
29
30/*
31 *----------------------------------------------------------------------------
32 *
33 * NsThread_Init --
34 *
35 *    Loads the package for the first time, i.e. in the startup thread.
36 *
37 * Results:
38 *    Standard Tcl result
39 *
40 * Side effects:
41 *    Package initialized. Tcl commands created.
42 *
43 *----------------------------------------------------------------------------
44 */
45
46static int
47NsThread_Init (Tcl_Interp *interp, void *cd)
48{
49    struct mydata *md = (struct mydata*)cd;
50    int ret = Thread_Init(interp);
51
52    if (ret != TCL_OK) {
53        Ns_Log(Warning, "can't load module %s: %s", md->modname,
54               Tcl_GetStringResult(interp));
55        return TCL_ERROR;
56    }
57    Tcl_SetAssocData(interp, "thread:nsd", NULL, (ClientData)md);
58
59    return TCL_OK;
60}
61
62/*
63 *----------------------------------------------------------------------------
64 *
65 * Ns_ModuleInit --
66 *
67 *    Called by the AOLserver when loading shared object file.
68 *
69 * Results:
70 *    Standard AOLserver result
71 *
72 * Side effects:
73 *    Many. Depends on the package.
74 *
75 *----------------------------------------------------------------------------
76 */
77
78int
79Ns_ModuleInit(char *srv, char *mod)
80{
81    struct mydata *md = NULL;
82
83    md = (struct mydata*)ns_malloc(sizeof(struct mydata));
84    md->modname = strcpy(ns_malloc(strlen(mod)+1), mod);
85    md->server  = strcpy(ns_malloc(strlen(srv)+1), srv);
86
87    return (Ns_TclInitInterps(srv, NsThread_Init, (void*)md) == TCL_OK)
88        ? NS_OK : NS_ERROR;
89}
90
91#endif /* NS_AOLSERVER */
92
93/* EOF $RCSfile: aolstub.cpp,v $ */
94
95/* Emacs Setup Variables */
96/* Local Variables:      */
97/* mode: C               */
98/* indent-tabs-mode: nil */
99/* c-basic-offset: 4     */
100/* End:                  */
101