svn commit: samba r8635 - in branches/SAMBA_4_0/source: build/pidl/Parse/Pidl/Samba scripting/ejs

tridge at samba.org tridge at samba.org
Wed Jul 20 06:20:37 GMT 2005


Author: tridge
Date: 2005-07-20 06:20:36 +0000 (Wed, 20 Jul 2005)
New Revision: 8635

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=8635

Log:
make object inheritance with the builtin objects easy by allowing
callers to optionally supply an existing object to add the properties
to. So you can do:

 var rpc = samr_init();
 lsa_init(rpc);

and you end up with 'rpc' having both the samr and lsa functions and
constants available.

Modified:
   branches/SAMBA_4_0/source/build/pidl/Parse/Pidl/Samba/EJS.pm
   branches/SAMBA_4_0/source/scripting/ejs/mprutil.c
   branches/SAMBA_4_0/source/scripting/ejs/smbcalls_ldb.c
   branches/SAMBA_4_0/source/scripting/ejs/smbcalls_nss.c
   branches/SAMBA_4_0/source/scripting/ejs/smbcalls_sys.c


Changeset:
Modified: branches/SAMBA_4_0/source/build/pidl/Parse/Pidl/Samba/EJS.pm
===================================================================
--- branches/SAMBA_4_0/source/build/pidl/Parse/Pidl/Samba/EJS.pm	2005-07-20 05:49:49 UTC (rev 8634)
+++ branches/SAMBA_4_0/source/build/pidl/Parse/Pidl/Samba/EJS.pm	2005-07-20 06:20:36 UTC (rev 8635)
@@ -692,19 +692,18 @@
 	pidl "static int ejs_$name\_init(int eid, int argc, struct MprVar **argv)";
 	pidl "{";
 	indent;
-	pidl "struct MprVar obj = mprObject(\"$name\");";
+	pidl "struct MprVar *obj = mprInitObject(eid, \"$name\", argc, argv);";
 	foreach (@fns) {
-		pidl "mprSetCFunction(&obj, \"$_\", ejs_$_);";
+		pidl "mprSetCFunction(obj, \"$_\", ejs_$_);";
 	}
 	foreach my $v (keys %constants) {
 		my $value = $constants{$v};
 		if (substr($value, 0, 1) eq "\"") {
-			pidl "mprSetVar(&obj, \"$v\", mprString($value));";
+			pidl "mprSetVar(obj, \"$v\", mprString($value));";
 		} else {
-			pidl "mprSetVar(&obj, \"$v\", mprCreateNumberVar($value));";
+			pidl "mprSetVar(obj, \"$v\", mprCreateNumberVar($value));";
 		}
 	}
-	pidl "mpr_Return(eid, obj);";
 	pidl "return 0;";
 	deindent;
 	pidl "}\n";

Modified: branches/SAMBA_4_0/source/scripting/ejs/mprutil.c
===================================================================
--- branches/SAMBA_4_0/source/scripting/ejs/mprutil.c	2005-07-20 05:49:49 UTC (rev 8634)
+++ branches/SAMBA_4_0/source/scripting/ejs/mprutil.c	2005-07-20 06:20:36 UTC (rev 8635)
@@ -403,3 +403,17 @@
 	struct MprVar *this = mprGetProperty(ejsGetLocalObject(eid), "this", 0);
 	mprSetPtrChild(this, name, ptr);
 }
+
+/*
+  used by object xxx_init() routines to allow for the caller
+  to supply a pre-existing object to add properties to,
+  or create a new object. This makes inheritance easy
+*/
+struct MprVar *mprInitObject(int eid, const char *name, int argc, struct MprVar **argv)
+{
+	if (argc > 0 && mprVarIsObject(argv[0]->type)) {
+		return argv[0];
+	}
+	mpr_Return(eid, mprObject(name));
+	return ejsGetReturnValue(eid);
+}

Modified: branches/SAMBA_4_0/source/scripting/ejs/smbcalls_ldb.c
===================================================================
--- branches/SAMBA_4_0/source/scripting/ejs/smbcalls_ldb.c	2005-07-20 05:49:49 UTC (rev 8634)
+++ branches/SAMBA_4_0/source/scripting/ejs/smbcalls_ldb.c	2005-07-20 06:20:36 UTC (rev 8635)
@@ -273,7 +273,7 @@
 
 	dbfile = argv[0];
 
-	ldb = ldb_wrap_connect(mprMemCtx(), dbfile, 0, argv+1);
+	ldb = ldb_wrap_connect(mprMemCtx(), dbfile, 0, (const char **)(argv+1));
 	if (ldb == NULL) {
 		ejsSetErrorMsg(eid, "ldb.connect failed to open %s", dbfile);
 	}
@@ -289,11 +289,8 @@
 */
 static int ejs_ldb_init(MprVarHandle eid, int argc, struct MprVar **argv)
 {
-	struct MprVar *ldb;
-	mpr_Return(eid, mprObject("ldb"));
+	struct MprVar *ldb = mprInitObject(eid, "ldb", argc, argv);
 
-	ldb  = ejsGetReturnValue(eid);
-
 	mprSetStringCFunction(ldb, "connect", ejs_ldbConnect);
 	mprSetCFunction(ldb, "search", ejs_ldbSearch);
 	mprSetCFunction(ldb, "add", ejs_ldbAdd);

Modified: branches/SAMBA_4_0/source/scripting/ejs/smbcalls_nss.c
===================================================================
--- branches/SAMBA_4_0/source/scripting/ejs/smbcalls_nss.c	2005-07-20 05:49:49 UTC (rev 8634)
+++ branches/SAMBA_4_0/source/scripting/ejs/smbcalls_nss.c	2005-07-20 06:20:36 UTC (rev 8635)
@@ -141,11 +141,8 @@
 */
 static int ejs_nss_init(MprVarHandle eid, int argc, struct MprVar **argv)
 {
-	struct MprVar *nss;
-	mpr_Return(eid, mprObject("nss"));
+	struct MprVar *nss = mprInitObject(eid, "nss", argc, argv);
 
-	nss  = ejsGetReturnValue(eid);
-
 	mprSetCFunction(nss, "getpwnam", ejs_getpwnam);
 	mprSetCFunction(nss, "getpwuid", ejs_getpwuid);
 	mprSetCFunction(nss, "getgrnam", ejs_getgrnam);

Modified: branches/SAMBA_4_0/source/scripting/ejs/smbcalls_sys.c
===================================================================
--- branches/SAMBA_4_0/source/scripting/ejs/smbcalls_sys.c	2005-07-20 05:49:49 UTC (rev 8634)
+++ branches/SAMBA_4_0/source/scripting/ejs/smbcalls_sys.c	2005-07-20 06:20:36 UTC (rev 8635)
@@ -193,19 +193,18 @@
 */
 static int ejs_sys_init(MprVarHandle eid, int argc, struct MprVar **argv)
 {
-	struct MprVar obj = mprObject("sys");
+	struct MprVar *obj = mprInitObject(eid, "sys", argc, argv);
 
-	mprSetCFunction(&obj, "interfaces", ejs_sys_interfaces);
-	mprSetCFunction(&obj, "hostname", ejs_sys_hostname);
-	mprSetCFunction(&obj, "nttime", ejs_sys_nttime);
-	mprSetCFunction(&obj, "gmtime", ejs_sys_gmtime);
-	mprSetCFunction(&obj, "ldaptime", ejs_sys_ldaptime);
-	mprSetCFunction(&obj, "httptime", ejs_sys_httptime);
-	mprSetStringCFunction(&obj, "unlink", ejs_sys_unlink);
-	mprSetStringCFunction(&obj, "file_load", ejs_sys_file_load);
-	mprSetStringCFunction(&obj, "file_save", ejs_sys_file_save);
+	mprSetCFunction(obj, "interfaces", ejs_sys_interfaces);
+	mprSetCFunction(obj, "hostname", ejs_sys_hostname);
+	mprSetCFunction(obj, "nttime", ejs_sys_nttime);
+	mprSetCFunction(obj, "gmtime", ejs_sys_gmtime);
+	mprSetCFunction(obj, "ldaptime", ejs_sys_ldaptime);
+	mprSetCFunction(obj, "httptime", ejs_sys_httptime);
+	mprSetStringCFunction(obj, "unlink", ejs_sys_unlink);
+	mprSetStringCFunction(obj, "file_load", ejs_sys_file_load);
+	mprSetStringCFunction(obj, "file_save", ejs_sys_file_save);
 
-	mpr_Return(eid, obj);
 	return 0;
 }
 



More information about the samba-cvs mailing list