Beispiel #1
0
static void Initialize(SFeatProcessor *self, const SMap* features, s_erc *error)
{
	S_CLR_ERR(error);

	SPhraseTypeFeatProc *castSelf = S_CAST(self, SPhraseTypeFeatProc, error);
	if (S_CHK_ERR(error, S_CONTERR,
		      "Initialize",
		      "Call to S_CAST failed"))
		goto quit_error;

	castSelf->symbols =  S_CAST( SMapGetObject(features , "list definitions", error),
								SMap, error);
	if (S_CHK_ERR(error, S_CONTERR,
			  "Initialize",
			  "Call to \"SMapGetObject\" failed"))
		goto quit_error;

	castSelf->symbols = SMapCopy ( NULL , castSelf->symbols , error);
	if (S_CHK_ERR(error, S_CONTERR,
			  "Initialize",
			  "Call to \"SMapCopy\" failed"))
		goto quit_error;

	/* Get the iterator for the SMap */
	SIterator *itrList = S_ITERATOR_GET(castSelf->symbols, error);
	if (S_CHK_ERR(error, S_CONTERR,
		      "Initialize",
		      "Call to \"S_ITERATOR_GET\" failed"))
		goto quit_error;

	while( itrList != NULL ) {

		const char *curStr = SIteratorKey(itrList, error);
		if (S_CHK_ERR(error, S_CONTERR,
			      "Initialize",
			      "Call to \"SIteratorKey\" failed"))
			goto quit_error;

		SList *valueList;
		valueList = S_CAST(SMapGetObject(castSelf->symbols, curStr, error), SList, error);
		if (S_CHK_ERR(error, S_CONTERR,
				  "Initialize",
				  "Call to \"SMapGetObject\" failed"))
			goto quit_error;

		/* Initializing a new SMap */
		SMap *newCastMap= S_MAP(S_NEW(SMapHashTable, error));

		SIterator *itrValueList = S_ITERATOR_GET(valueList, error);
		if (S_CHK_ERR(error, S_CONTERR,
				  "Initialize",
				  "Call to \"S_ITERATOR_GET\" failed"))
			goto quit_error;

		while(itrValueList != NULL) {
			const SObject *curValueObj = SIteratorObject(itrValueList, error);
			if (S_CHK_ERR(error, S_CONTERR,
					  "Initialize",
					  "Call to \"SIteratorObject\" failed"))
				goto quit_error;

			const char *curValueStr = SObjectGetString(curValueObj, error);
			if (S_CHK_ERR(error, S_CONTERR,
					  "Initialize",
					  "Call to \"SObjectGetString\" failed"))
				goto quit_error;

			/* Insert the string inside the map */
			SMapSetString(newCastMap, curValueStr, curValueStr, error);
			if (S_CHK_ERR(error, S_CONTERR,
					  "Initialize",
					  "Call to \"SMapSetObject\" failed"))
				goto quit_error;

			itrValueList = SIteratorNext(itrValueList);
		}

		/* Insertion of the SMap inside the SMap */
		SMapSetObject(castSelf->symbols, curStr, (SObject *) newCastMap, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "Initialize",
					  "Call to \"SMapSetObject\" failed"))
				goto quit_error;
		itrList = SIteratorNext(itrList);
	}

	/* error cleanup */
	quit_error:
		return;
}
Beispiel #2
0
static void DestroyVoice(void *obj, s_erc *error)
{
	SVoice *self = obj;
	SIterator *itr;
	const char *data_name;


	S_CLR_ERR(error);
	s_mutex_lock(&self->voice_mutex);

	free_voice_info(self->info);

	if (self->features != NULL)
		S_DELETE(self->features, "DestroyVoice", error);

	if (self->featProcessors != NULL)
		S_DELETE(self->featProcessors, "DestroyVoice", error);

	if (self->uttProcessors != NULL)
		S_DELETE(self->uttProcessors, "DestroyVoice", error);

	if (self->uttTypes != NULL)
		S_DELETE(self->uttTypes, "DestroyVoice", error);

	if (self->plugins != NULL)
	{
		unload_voice_plugins(self->plugins, error);
		S_CHK_ERR(error, S_CONTERR,
				  "DestroyVoice",
				  "Call to \"unload_voice_plugins\" failed");
	}

	if (self->data != NULL)
	{
		/*
		 * now iterate through data config and delete everything
		 */
		itr = S_ITERATOR_GET(self->data->dataObjects, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "DestroyVoice",
					  "Call to \"S_ITERATOR_GET\" failed"))
		{
			S_DELETE(itr, "DestroyVoice", error);

			/*
			 * leave data objects, this will probably cause
			 * memory leaks, but at the risk of deleting
			 * shared data.
			 */
			S_FREE(self->data);
			s_mutex_unlock(&self->voice_mutex);
			s_mutex_destroy(&self->voice_mutex);
			return;
		}

		while (itr)
		{
			data_name = SIteratorKey(itr, error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "DestroyVoice",
						  "Call to \"SIteratorKey\" failed"))
			{
				S_DELETE(itr, "DestroyVoice", error);

				/*
				 * leave data objects, this will probably cause
				 * memory leaks, but at the risk of deleting
				 * shared data.
				 */
				S_FREE(self->data);
				s_mutex_unlock(&self->voice_mutex);
				s_mutex_destroy(&self->voice_mutex);
				return;
			}

			unload_data_entry(self, data_name, error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "DestroyVoice",
						  "Call to \"unload_data_entry\" failed"))
			{
				S_DELETE(itr, "DestroyVoice", error);

				/*
				 * leave data objects, this will probably cause
				 * memory leaks, but at the risk of deleting
				 * shared data.
				 */
				S_FREE(self->data);
				s_mutex_unlock(&self->voice_mutex);
				s_mutex_destroy(&self->voice_mutex);
				return;
			}

			itr = SIteratorNext(itr);
		}

		S_DELETE(self->data->dataObjects, "DestroyVoice", error);
		S_FREE(self->data);
	}

	s_mutex_unlock(&self->voice_mutex);
	s_mutex_destroy(&self->voice_mutex);
}
Beispiel #3
0
S_LOCAL void _s_load_voice_utterance_processors(const SMap *voiceConfig, SVoice *voice, s_erc *error)
{
	SMap *uttProcessors;
	const SObject *tmp;
	const SMap *voiceConfigUttProcessors;
	s_bool key_present;
	SIterator *itr;
	const char *uttproc_name;
	const char *uttproc_class;
	const char *uttproc_plugin;
	const SMap *uttProcInfo;
	const SMap *uttProcFeats;
	SUttProcessor *uProcessor;
	SPlugin *plugin;
	SList *uttProcPlugins;


	S_CLR_ERR(error);

	/* create a map container for utterance-processors */
	uttProcessors = S_MAP(S_NEW(SMapList, error));
	if (S_CHK_ERR(error, S_CONTERR,
				  "_s_load_voice_utterance_processors",
				  "Failed to create new map for voice utterance-processors"))
		return;

	/* look for "utterance-processors" key in voiceConfig map */
	key_present = SMapObjectPresent(voiceConfig, "utterance-processors", error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "_s_load_voice_utterance_processors",
				  "Call to \"SMapObjectPresent\" failed for \'utterance-processors\' key"))
	{
		S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error);
		return;
	}

	if (!key_present)
	{
		/* no defined utterance-processors  */
		voice->uttProcessors = uttProcessors;
		return;
	}

	/* get utterance-processors from voiceConfig */
	tmp = SMapGetObject(voiceConfig, "utterance-processors", error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "_s_load_voice_utterance_processors",
				  "Call to \"SMapGetObject\" failed"))
	{
		S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error);
		return;
	}

	voiceConfigUttProcessors = S_CAST(tmp, SMap, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "_s_load_voice_utterance_processors",
				  "Call to \"S_CAST (SMap)\" failed for \'utterance-processors\' object"))
	{
		S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error);
		return;
	}

	/*
	 * iterate through the voiceConfigUttProcessors, create the
	 * utterance-processors and add their features (if any), and add
	 * them to the uttProcessors map
	 */
	itr = S_ITERATOR_GET(voiceConfigUttProcessors, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "_s_load_voice_utterance_processors",
				  "Call to \"S_ITERATOR_GET\" failed"))
	{
		S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error);
		return;
	}

	if (itr)
	{
		/* create a plug-in list */
		uttProcPlugins = S_LIST(S_NEW(SListList, error));
		if (S_CHK_ERR(error, S_CONTERR,
					  "_s_load_voice_utterance_processors",
					  "Failed to create new list for voice utterance-processor plug-ins"))
		{
			S_DELETE(itr, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error);
			return;
		}
	}
	else
		uttProcPlugins = NULL;

	while (itr)
	{
		/* the utterance-processor name */
		uttproc_name = SIteratorKey(itr, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "_s_load_voice_utterance_processors",
					  "Call to \"SIteratorKey\" failed"))
		{
			S_DELETE(itr, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcPlugins, "_s_load_voice_utterance_processors", error);
			return;
		}

		/* the utterance-processor info (SMap) */
		tmp = SIteratorObject(itr, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "_s_load_voice_utterance_processors",
					  "Call to \"SIteratorObject\" failed"))
		{
			S_DELETE(itr, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcPlugins, "_s_load_voice_utterance_processors", error);
			return;
		}

		uttProcInfo = S_CAST(tmp, SMap, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "_s_load_voice_utterance_processors",
					  "Call to \"S_CAST (SMap)\" failed for utterance-processor \'%s\'",
					  uttproc_name))
		{
			S_DELETE(itr, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcPlugins, "_s_load_voice_utterance_processors", error);
			return;
		}

		/*
		 * uttProcInfo must have "class" and "plug-in" and
		 * optionally "features"
		 */
		uttproc_class = SMapGetString(uttProcInfo, "class", error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "_s_load_voice_utterance_processors",
					  "Call to \"SMapGetString\" failed for \'class\' name of utterance-processor \'%s\'",
					  uttproc_name))
		{
			S_DELETE(itr, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcPlugins, "_s_load_voice_utterance_processors", error);
			return;
		}

		uttproc_plugin = SMapGetString(uttProcInfo, "plug-in", error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "_s_load_voice_utterance_processors",
					  "Call to \"SMapGetString\" failed for \'plug-in\' name of utterance-processor \'%s\'",
					  uttproc_name))
		{
			S_DELETE(itr, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcPlugins, "_s_load_voice_utterance_processors", error);
			return;
		}

		/*
		 * load the plug-in, add it to the list of utterance-processor plug-ins and create
		 * the utterance-processor object
		 */
		plugin = s_pm_load_plugin(uttproc_plugin, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "_s_load_voice_utterance_processors",
					  "Call to \"s_pm_load_plugin\" failed for utterance-processor \'%s\'",
					  uttproc_name))
		{
			S_DELETE(itr, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcPlugins, "_s_load_voice_utterance_processors", error);
			return;
		}

		SListPush(uttProcPlugins, S_OBJECT(plugin), error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "_s_load_voice_utterance_processors",
					  "Call to \"SListPush\" failed for utterance-processor plug-ins"))
		{
			S_DELETE(plugin, "_s_load_voice_utterance_processors", error);
			S_DELETE(itr, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcPlugins, "_s_load_voice_utterance_processors", error);
			return;
		}

		uProcessor = S_UTTPROCESSOR(S_NEW_FROM_NAME(uttproc_class, error));
		if (S_CHK_ERR(error, S_CONTERR,
					  "_s_load_voice_utterance_processors",
					  "Failed to create new utterance-processor of class \'%s\'",
					  uttproc_class))
		{
			S_DELETE(itr, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcPlugins, "_s_load_voice_utterance_processors", error);
			return;
		}

		/* add the utterance-processor to the map of utterance-processors */
		SMapSetObject(uttProcessors, uttproc_name, S_OBJECT(uProcessor), error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "_s_load_voice_utterance_processors",
					  "Call to \"SMapSetObject\" failed"))
		{
			S_DELETE(uProcessor, "_s_load_voice_utterance_processors", error);
			S_DELETE(itr, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcPlugins, "_s_load_voice_utterance_processors", error);
			return;
		}

		/* Check if this utterance-processor has any defined features */
		key_present = SMapObjectPresent(uttProcInfo, "features", error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "_s_load_voice_utterance_processors",
					  "Call to \"SMapObjectPresent\" failed for \'features\' key of utterance-processor \'%s\'",
					  uttproc_name))
		{
			S_DELETE(itr, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcPlugins, "_s_load_voice_utterance_processors", error);
			return;
		}

		if (key_present)
		{
			/* get utterance-processors "features" */
			tmp = SMapGetObject(uttProcInfo, "features", error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "_s_load_voice_utterance_processors",
						  "Call to \"SMapGetObject\" failed for \'features\' of utterance-processor \'%s\'",
						  uttproc_name))
			{
				S_DELETE(itr, "_s_load_voice_utterance_processors", error);
				S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error);
				S_DELETE(uttProcPlugins, "_s_load_voice_utterance_processors", error);
				return;
			}

			uttProcFeats = S_CAST(tmp, SMap, error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "_s_load_voice_utterance_processors",
						  "Call to \"S_CAST (SMap)\" failed for \'features\' of utterance-processor \'%s\'",
						  uttproc_name))
			{
				S_DELETE(itr, "_s_load_voice_utterance_processors", error);
				S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error);
				S_DELETE(uttProcPlugins, "_s_load_voice_utterance_processors", error);
				return;
			}

			/* copy them to the utterance-processor */
			SMapCopy(uProcessor->features, uttProcFeats, error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "_s_load_voice_utterance_processors",
						  "Call to \"SMapCopy\" failed for \'features\' of utterance-processor \'%s\'",
						  uttproc_name))
			{
				S_DELETE(itr, "_s_load_voice_utterance_processors", error);
				S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error);
				S_DELETE(uttProcPlugins, "_s_load_voice_utterance_processors", error);
				return;
			}
		}

		/* initialize the utterance processor */
		SUttProcessorInit(&uProcessor, voice, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "_s_load_voice_utterance_processors",
					  "Call to \"SUttProcessorInit\" failed for utterance-processor of class \'%s\'",
					  uttproc_class))
		{
			S_DELETE(itr, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcPlugins, "_s_load_voice_utterance_processors", error);
			return;
		}

		itr = SIteratorNext(itr);
	}

	if (uttProcPlugins != NULL)
	{
		SListMerge(voice->plugins, uttProcPlugins, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "_s_load_voice_utterance_processors",
					  "Call to \"SListMerge\" failed"))
		{
			S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error);
			S_DELETE(uttProcPlugins, "_s_load_voice_utterance_processors", error);
			return;
		}

		S_DELETE(uttProcPlugins, "_s_load_voice_utterance_processors", error);
	}

	voice->uttProcessors = uttProcessors;
}
Beispiel #4
0
S_LOCAL void _s_voice_load_data(SVoice *self, const SMap *dataConfig, s_erc *error)
{
	SIterator *itr;
	const char *data_name;
	const SObject *loaded;
	const SMap *dataObjectMap;
	s_data_info *data_info;
	const SObject *vcfgObject;
	char *voice_base_path;


	S_CLR_ERR(error);

	if (self == NULL)
	{
		S_CTX_ERR(error, S_ARGERROR,
				  "_s_voice_load_data",
				  "Argument \"self\" is NULL");
		return;
	}

	/* get voice base path */
	vcfgObject = SVoiceGetFeature(self, "config_file", error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "_s_voice_load_data",
				  "Call to \"SVoiceGetFeature\" failed, failed to get voice config file"))
		return;

	voice_base_path = s_get_base_path(SObjectGetString(vcfgObject, error), error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "_s_voice_load_data",
				  "Call to \"s_get_base_path/SObjectGetString\" failed"))
		return;

	/*
	 * now iterate through data config and load everything
	 */
	itr = S_ITERATOR_GET(dataConfig, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "_s_voice_load_data",
				  "Call to \"S_ITERATOR_GET\" failed"))
	{
		S_DELETE(itr, "_s_voice_load_data", error);
		S_FREE(voice_base_path);
		return;
	}

	while (itr)
	{
		char *combined_path;


		data_name = SIteratorKey(itr, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "_s_voice_load_data",
					  "Call to \"SIteratorKey\" failed"))
		{
			S_DELETE(itr, "_s_voice_load_data", error);
			S_FREE(voice_base_path);
			return;
		}

		/*
		 * We have already checked this cast in
		 * _s_voice_load_dataConfig (_s_load_voice_data_config)
		 */
		dataObjectMap = (const SMap*)SMapGetObjectDef(dataConfig, data_name, NULL, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "_s_voice_load_data",
					  "Call to \"SMapGetObjectDef\" for data '%s' failed",
					  data_name))
		{
			S_DELETE(itr, "_s_voice_load_data", error);
			S_FREE(voice_base_path);
			return;
		}

		if (dataObjectMap == NULL)
		{
			S_CTX_ERR(error, S_CONTERR,
					  "_s_voice_load_data",
					  "Data object map for data '%s' in data config in NULL",
					  data_name);
			S_DELETE(itr, "_s_voice_load_data", error);
			S_FREE(voice_base_path);
			return;
		}

		data_info = get_data_info(dataObjectMap, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "_s_voice_load_data",
					  "Call to \"get_data_info\" for data '%s' in data config failed",
					  data_name))
		{
			S_DELETE(itr, "_s_voice_load_data", error);
			S_FREE(voice_base_path);
			return;
		}

		/* get data path, the one in the config file may be relative
		 * to the voice base path
		 */
		combined_path = s_path_combine(voice_base_path, data_info->path,
									   error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "_s_voice_load_data",
					  "Call to \"s_path_combine\" failed"))
		{
			S_DELETE(itr, "_s_voice_load_data", error);
			S_FREE(voice_base_path);
			return;
		}

		loaded = _s_vm_load_data(data_info->plugin, combined_path,
								 data_info->format, error);
		S_FREE(combined_path);
		if (S_CHK_ERR(error, S_CONTERR,
					  "_s_voice_load_data",
					  "Call to \"_s_vm_load_data\" for data '%s' in data config failed",
					  data_name))
		{
			S_FREE(data_info);
			S_DELETE(itr, "_s_voice_load_data", error);
			S_FREE(voice_base_path);
			return;
		}

		S_FREE(data_info);

		SMapSetObject(self->data->dataObjects, data_name, loaded, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "_s_voice_load_data",
					  "Call to \"SMapSetObject\" for data '%s' in data config failed",
					  data_name))
		{
			s_erc local_err = S_SUCCESS;


			S_FREE(voice_base_path);
			S_DELETE(itr, "_s_voice_load_data", error);
			_s_vm_unload_data((SObject*)loaded, &local_err); /* error is already set */
			return;
		}

		itr = SIteratorNext(itr);
	}

	S_FREE(voice_base_path);
}