Ejemplo n.º 1
0
FSTATIC char *
_childprocess_toString(gconstpointer aself)
{
	const ChildProcess*	self = CASTTOCONSTCLASS(ChildProcess, aself);
	ConfigContext*	cfg = configcontext_new(0);
	char*		ret;

	cfg->setint(cfg, "child_pid", self->child_pid);
	cfg->setint(cfg, "timeout", self->timeout);
	cfg->setint(cfg, "timeoutsrc_id", self->timeoutsrc_id);
	cfg->setint(cfg, "childsrc_id", self->childsrc_id);
	cfg->setint(cfg, "child_state", self->child_state);
	cfg->setstring(cfg, "loggingname", self->loggingname);
	ret = cfg->baseclass.toString(&cfg->baseclass);
	UNREF(cfg);
	return ret;
}
Ejemplo n.º 2
0
/// Send JSON that we discovered to the CMA - with some caching going on
FSTATIC void
_discovery_sendjson(Discovery* self,	///< Our discovery object
		    char * jsonout,	///< malloced JSON output - which we free (!)
		    gsize jsonlen)	///< length of jsonout
{
	FrameSet*	fs;
	CstringFrame*	jsf;
	IntFrame*	intf;
	Frame*		fsf;
	ConfigContext*	cfg = self->_config;
	NetGSource*	io = self->_iosource;
	NetAddr*	cma;
	const char *	basename = self->instancename(self);
	ConfigContext*	jsonobject;

	g_return_if_fail(cfg != NULL && io != NULL);

	if (NULL == (jsonobject = configcontext_new_JSON_string(jsonout))) {
		g_warning("%s.%d: JSON Discovery is not legal JSON [%s]"
		,	__FUNCTION__, __LINE__, jsonout);
		return;
	}
	g_free(jsonout);
	
	jsonobject->setstring(jsonobject, CONFIGNAME_INSTANCE, basename);
	jsonout = jsonobject->baseclass.toString(&jsonobject->baseclass);
	jsonlen = strlen(jsonout);
	UNREF(jsonobject);
	
	DEBUGMSG2("%s.%d: discovering %s: _sentyet == %d"
	,	__FUNCTION__, __LINE__, basename, self->_sentyet);
	
	
	// Primitive caching - don't send what we've already sent.
	if (self->_sentyet) {
		const char *	oldvalue = cfg->getstring(cfg, basename);
		if (oldvalue != NULL && strcmp(jsonout, oldvalue) == 0) {
			DEBUGMSG2("%s.%d: %s sent this value - don't send again."
			,	__FUNCTION__, __LINE__, basename);
			g_free(jsonout);
			return;
		}
		DEBUGMSG2("%s.%d: %s this value is different from previous value"
		,	__FUNCTION__, __LINE__, basename);
	}
	DEBUGMSG2("%s.%d: Sending %"G_GSIZE_FORMAT" bytes of JSON text"
	,	__FUNCTION__, __LINE__, jsonlen);
	cfg->setstring(cfg, basename, jsonout);
	cma = cfg->getaddr(cfg, CONFIGNAME_CMADISCOVER);
	if (cma == NULL) {
	        DEBUGMSG2("%s.%d: %s address is unknown - skipping send"
		,	__FUNCTION__, __LINE__, CONFIGNAME_CMADISCOVER);
		g_free(jsonout);
		return;
	}
	self->_sentyet = TRUE;

	fs = frameset_new(FRAMESETTYPE_JSDISCOVERY);
	intf = intframe_new(FRAMETYPE_WALLCLOCK, 8);
	intf->setint(intf, self->starttime);
	frameset_append_frame(fs, &intf->baseclass);
	UNREF2(intf);
	jsf = cstringframe_new(FRAMETYPE_JSDISCOVER, 0);
	fsf = &jsf->baseclass;	// base class object of jsf
	fsf->setvalue(fsf, jsonout, jsonlen+1, frame_default_valuefinalize); // jsonlen is strlen(jsonout)
	frameset_append_frame(fs, fsf);
	DEBUGMSG2("%s.%d: Sending a %"G_GSIZE_FORMAT" bytes JSON frameset"
	,	__FUNCTION__, __LINE__, jsonlen);
	io->_netio->sendareliablefs(io->_netio, cma, DEFAULT_FSP_QID, fs);
	++ self->reportcount;
	UNREF(fsf);
	UNREF(fs);
}