Skip to content
Snippets Groups Projects
js_system.c 53.7 KiB
Newer Older
deuce's avatar
deuce committed
		if(!JS_DefineProperty(cx, obj, "node_list", OBJECT_TO_JSVAL(newobj)
			, NULL, NULL, JSPROP_ENUMERATE))
			return(JS_FALSE);
deuce's avatar
deuce committed
		for(i=0;i<cfg->sys_nodes && i<cfg->sys_lastnode;i++) {
deuce's avatar
deuce committed
			nodeobj = JS_NewObject(cx, &js_node_class, NULL, newobj);

			if(nodeobj==NULL)
				return(JS_FALSE);

			/* Store node number */
			/* We have to shift it to make it look like a pointer to JS. :-( */
			if(!JS_SetPrivate(cx, nodeobj, (char*)((i+1)<<1)))
				return(JS_FALSE);
deuce's avatar
deuce committed
	#ifdef BUILD_JSDOCS
			if(i==0) {
				js_DescribeSyncObject(cx,nodeobj,"BBS node listing",310);
				js_CreateArrayOfStrings(cx, nodeobj, "_property_desc_list", node_prop_desc, JSPROP_READONLY);
			}
	#endif

			val=OBJECT_TO_JSVAL(nodeobj);
			if(!JS_SetElement(cx, newobj, i, &val))
				return(JS_FALSE);
		}
		if(name) return(JS_TRUE);
deuce's avatar
deuce committed
	return(js_SyncResolve(cx, obj, name, js_system_properties, js_system_functions, NULL, 0));
}
deuce's avatar
deuce committed
static JSBool js_system_enumerate(JSContext *cx, JSObject *obj)
{
	return(js_node_resolve(cx, obj, JSVAL_NULL));
}
deuce's avatar
deuce committed
static JSClass js_system_class = {
     "System"				/* name			*/
    ,JSCLASS_HAS_PRIVATE	/* flags		*/
	,JS_PropertyStub		/* addProperty	*/
	,JS_PropertyStub		/* delProperty	*/
	,js_system_get			/* getProperty	*/
	,js_system_set			/* setProperty	*/
	,js_system_enumerate	/* enumerate	*/
	,js_system_resolve		/* resolve		*/
	,JS_ConvertStub			/* convert		*/
	,JS_FinalizeStub		/* finalize		*/
};
deuce's avatar
deuce committed
JSObject* DLLCALL js_CreateSystemObject(JSContext* cx, JSObject* parent
										,scfg_t* cfg, time_t uptime, char* host_name, char* socklib_desc)
{
	jsval		val;
	JSObject*	sysobj;
	JSString*	js_str;
	char		str[256];
deuce's avatar
deuce committed
	sysobj = JS_DefineObject(cx, parent, "system", &js_system_class, NULL
		,JSPROP_ENUMERATE|JSPROP_READONLY);
deuce's avatar
deuce committed
	if(sysobj==NULL)
deuce's avatar
deuce committed
	if(!JS_SetPrivate(cx, sysobj, cfg))	/* Store a pointer to scfg_t */
deuce's avatar
deuce committed
	/****************************/
	/* static string properties */
	if((js_str=JS_NewStringCopyZ(cx, host_name))==NULL)
		return(NULL);
	val = STRING_TO_JSVAL(js_str);
	if(!JS_SetProperty(cx, sysobj, "host_name", &val))
		return(NULL);
deuce's avatar
deuce committed
	if((js_str=JS_NewStringCopyZ(cx, socklib_version(str, socklib_desc)))==NULL)
		return(NULL);
	val = STRING_TO_JSVAL(js_str);
	if(!JS_SetProperty(cx, sysobj, "socket_lib", &val))
		return(NULL);
deuce's avatar
deuce committed
	/***********************/
deuce's avatar
deuce committed
	JS_NewNumberValue(cx,uptime,&val);
	if(!JS_SetProperty(cx, sysobj, "uptime", &val))
		return(NULL);
deuce's avatar
deuce committed
	js_DescribeSyncObject(cx,sysobj,"Global system-related properties and methods",310);
	js_CreateArrayOfStrings(cx, sysobj, "_property_desc_list", sys_prop_desc, JSPROP_READONLY);
deuce's avatar
deuce committed
#ifdef BUILD_JSDOCS
rswindell's avatar
rswindell committed
	{
		JSObject*	statsobj;

		js_DescribeSyncObject(cx,statsobj,"System statistics",310);
		js_CreateArrayOfStrings(cx, statsobj, "_property_desc_list", sysstat_prop_desc, JSPROP_READONLY);
	}
deuce's avatar
deuce committed
#endif
#endif	/* JAVSCRIPT */