Ejemplo n.º 1
0
bool Sensor::stop () {

	ssi_msg (SSI_LOG_LEVEL_BASIC, "stop '%s'", _sensor->getName ());	

	if (!_connected) {
		ssi_wrn ("not connected '%s'", _sensor->getName ());
		return false;
	}	

	if (!_sensor->stop ()) {
		ssi_wrn ("stop failed '%s'", _sensor->getName ());
		return false;
	}

	ssi_msg (SSI_LOG_LEVEL_BASIC, "disconnect '%s'", _sensor->getName ());	

	_connected = !_sensor->disconnect ();

	if (_connected) {
		ssi_wrn ("could not disconnect '%s'", _sensor->getName ());
		return false;
	}

	return true;

}
Ejemplo n.º 2
0
bool FileStreamIn::close () { 

	ssi_msg (SSI_LOG_LEVEL_DETAIL, "close stream file '%s'", _path);

	if (!_file_data->close ()) {
		ssi_wrn ("could not close data file '%s'", _path);
		return false;
	}

	if (!_file_info->close ()) {
		ssi_wrn ("could not close info file '%s'", _file_info->getPath ());
		return false;
	}

	delete _file_data; _file_data = 0;
	delete _file_info; _file_info = 0;
	delete[] _path; _path = 0;
	delete[] _samples; _samples = 0;
	delete[] _time; _time = 0;
	delete[] _bytes; _bytes = 0;
	_n_chunks = 0;
	_n_samples = 0;
	_next_chunk = 0;

	return true;
};
Ejemplo n.º 3
0
bool FileReader::connect () {

	if (!_provider) {
		ssi_wrn ("provider not set");
		return false;
	}

	if (!prepare_file ()) {
		ssi_err ("an error occured while reading file (%s)", _file_stream_in.getDataFile ()->getPath ());
	}

	_stopped = false;
	// set providing=true to read first chunk
	_is_providing = true;

	ssi_msg (SSI_LOG_LEVEL_BASIC, "start 'path=%s'", _options.path);
	if (ssi_log_level >= SSI_LOG_LEVEL_BASIC) {
		ssi_print ("             sample rate\t= %.2lf Hz\n\
             sample dim\t\t= %u\n\
             sample bytes\t= %u\n\
             sample number\t= %u\n\
             stream length\t= %.2fs\n",
		_stream.sr, 
		_stream.dim, 
		_stream.byte,
		_sample_number_total,
		_sample_number_total/_stream.sr);
	}
Ejemplo n.º 4
0
void MyEventSender::consume_flush(ssi_size_t stream_in_num,
	ssi_stream_t stream_in[]) {

	ssi_event_destroy(_event);

	ssi_msg(SSI_LOG_LEVEL_BASIC, "flush()..ok");
}
Ejemplo n.º 5
0
void MyConsumer::consume_flush(ssi_size_t stream_in_num,
	ssi_stream_t stream_in[]) {

	delete _file; _file = 0;

	ssi_msg(SSI_LOG_LEVEL_BASIC, "flush()..ok");
}
Ejemplo n.º 6
0
void MyFilter::transform_flush(ssi_stream_t &stream_in,
	ssi_stream_t &stream_out,
	ssi_size_t xtra_stream_in_num,
	ssi_stream_t xtra_stream_in[]) {

	ssi_msg(SSI_LOG_LEVEL_BASIC, "flush()..ok");
}
Ejemplo n.º 7
0
void MyEventSender::consume_enter(ssi_size_t stream_in_num,
	ssi_stream_t stream_in[]) {

	ssi_event_adjust(_event, stream_in[0].dim * sizeof(ssi_real_t));

	ssi_msg(SSI_LOG_LEVEL_BASIC, "enter()..ok");
}
Ejemplo n.º 8
0
bool Chain::parseFeature (TiXmlElement *element) {

	int n_features = 0;
	element->QueryIntAttribute ("size", &n_features);

	ssi_msg (SSI_LOG_LEVEL_DETAIL, "found %u feature", n_features); 

	if (n_features > 0) {
		_n_features = n_features;
		_features = new IFeature *[_n_features];
		for (ssi_size_t i = 0; i < _n_features; i++) {
			_features[i] = 0;
		}
		TiXmlElement *item = 0;
		for (ssi_size_t i = 0; i < _n_features; i++) {
			if (i == 0) {
				item = element->FirstChildElement ("item");	
			} else {
				item = item->NextSiblingElement ("item");
			}
			if (!item) {
				ssi_wrn ("feature: failed parsing '%u'th <item> tag", i);
				return false;
			}
			IObject *object = _xmlpipe->parseObject (item, false);
			if (!object) {
				ssi_wrn ("filter: class not found");
				return false;
			}
			if (object->getType () != SSI_FEATURE) {
				ssi_wrn ("feature: class is not a feature");
				return false;
			}
			IFeature *feature = ssi_pcast (IFeature, object);
			if (!feature) {
				ssi_wrn ("feature: failed loading feature object");
				return false;
			}

			ssi_msg (SSI_LOG_LEVEL_DETAIL, "load %u. feature '%s'", i+1, object->getName ()); 

			_features[i] = feature;
		}
	}

	return true;
}
Ejemplo n.º 9
0
void CheckBox::set(bool checked) {

	_checked = checked;

	::SendMessage(_hCheckBox, (UINT)BM_SETCHECK, (WPARAM) (_checked ? BST_CHECKED : BST_UNCHECKED), (LPARAM)0);

	ssi_msg(SSI_LOG_LEVEL_DETAIL, _checked ? "checked" : "unchecked");
}
Ejemplo n.º 10
0
void MyFilter2::transform_flush(ssi_stream_t &stream_in,
	ssi_stream_t &stream_out,
	ssi_size_t xtra_stream_in_num,
	ssi_stream_t xtra_stream_in[]) {

	delete[] _hist; _hist = 0;
	ssi_msg(SSI_LOG_LEVEL_BASIC, "flush()..ok");
}
Ejemplo n.º 11
0
void FileReader::run () {
	
	if (_stopped) {
		::Sleep (100);
		return;
	}

	if (_is_providing) {
		if (_file_stream_in.read (_stream) == FileStreamIn::READ_ERROR) {
			ssi_err ("an error occured while reading file (%s)", _file_stream_in.getDataFile ()->getPath ());
		}
	}

	_is_providing = _provider->provide (_stream.ptr, _stream.num);
	if (!_is_providing) {
		::Sleep (100);
		return;
	}
	SSI_DBG (SSI_LOG_LEVEL_DEBUG, "read %u samples", _stream.num);

	if (!_timer) {
		_timer = new Timer (_options.block);
	}

	if (++_step_counter >= _max_steps)
	{
		if (_options.loop) 
		{
			if (!prepare_file ()) {
				ssi_err ("an error occured while reading file (%s)", _file_stream_in.getDataFile ()->getPath ());
			}
			ssi_msg (SSI_LOG_LEVEL_DETAIL, "loop 'path=%s'", _options.path);
		}
		else
		{
			ssi_msg (SSI_LOG_LEVEL_DETAIL, "release 'path=%s'", _options.path);
			_stopped = true;
			_interrupted = false;
			_event.release ();
		}
	
	}
	
	_timer->wait ();
}
Ejemplo n.º 12
0
void MyConsumer::consume_enter(ssi_size_t stream_in_num,
	ssi_stream_t stream_in[]) {

	_file = File::Create(File::ASCII, File::WRITE, 0);
	_file->setFormat(" ", "6.2");
	_file->setType(stream_in[0].type);

	ssi_msg(SSI_LOG_LEVEL_BASIC, "enter()..ok");
}
Ejemplo n.º 13
0
void SocketEventReader::flush () {
	
	delete _socket; _socket = 0;
	delete _socket_osc; _socket_osc = 0;
	delete[] _buffer; _buffer = 0;

	ssi_char_t string[SSI_MAX_CHAR];
	ssi_sprint(string, "%s@%u", _options.host, _options.port);
	ssi_msg(SSI_LOG_LEVEL_BASIC, "stopped'%s'", string);
}
Ejemplo n.º 14
0
void EventConsumer::clear () {

	ssi_msg (SSI_LOG_LEVEL_DETAIL, "detach all consumer");

	for (ssi_size_t i = 0; i < _consumer_count; i++) {
		delete _consumer[i];
		_consumer[i] = 0;
	}
	_consumer_count = 0;	
}
Ejemplo n.º 15
0
bool FileReader::disconnect () {

	ssi_msg(SSI_LOG_LEVEL_BASIC, "stop reading from '%s'", _options.path);

	delete _timer; _timer = 0;
	ssi_stream_destroy(_stream);

	if (!_file_stream_in.close())
	{
		ssi_err("could not close stream '%s'", _options.path);
	}

	return true;
}
Ejemplo n.º 16
0
bool Sensor::start () {

	ssi_msg (SSI_LOG_LEVEL_BASIC, "connect '%s'", _sensor->getName ());

	if (_connected) {
		ssi_wrn ("already connected '%s'", _sensor->getName ());
		return false;
	}

	_connected = _sensor->connect ();

	if (!_connected) {
		ssi_wrn ("could not connect '%s'", _sensor->getName ());
		return false;
	}	

	ssi_msg (SSI_LOG_LEVEL_BASIC, "start '%s'", _sensor->getName ());

	if (!_sensor->start ()) {
		ssi_wrn ("start failed '%s'", _sensor->getName ());
	}

	return true;
}
Ejemplo n.º 17
0
bool EventConsumer::AddConsumer (ssi_size_t n_sources, ITransformable **sources, IConsumer *consumer, ITransformer **transformers) {

	if (_consumer_count < SSI_TRIGGER_MAX_CONSUMER) {
		int *buffer_ids = new int[n_sources];
		for (ssi_size_t i = 0; i < n_sources; i++) {
			buffer_ids[i] = sources[i]->getBufferId ();
		}
		_consumer[_consumer_count] = new ConsumerBase (n_sources, buffer_ids, consumer, 0, 0, transformers);
		delete[] buffer_ids;
		ssi_msg (SSI_LOG_LEVEL_DETAIL, "attached consumer '%s'", _consumer[_consumer_count]->_consumer->getName ());
		++_consumer_count;
		return true;
	}

	ssi_wrn ("max #consumer exceeded");

	return false;
}
Ejemplo n.º 18
0
bool FileSamplesIn::close () { 

	ssi_msg (SSI_LOG_LEVEL_DETAIL, "close samples file '%s'", _path);

	if (!_file_data->close ()) {
		ssi_wrn ("could not close data file '%s'", _path);
		return false;
	}

	if (!_file_info->close ()) {
		ssi_wrn ("could not close info file '%s'", _file_info->getPath ());
		return false;
	}

	if (_file_streams) {
		for (ssi_size_t i = 0; i < _n_streams; i++) {
			_file_streams[i].close ();
		}
	}

	delete _file_data; _file_data = 0;
	delete _file_info; _file_info = 0;
	delete[] _file_streams; _file_streams = 0;
	delete _path; _path = 0;
	delete[] _streams; _streams = 0;
	ssi_sample_destroy (_sample);
	for (ssi_size_t i = 0; i < _n_classes; i++) {
		delete[] _classes[i];
	}
	delete[] _n_per_class; _n_per_class = 0;
	delete[] _classes; _classes = 0;
	for (ssi_size_t i = 0; i < _n_users; i++) {
		delete[] _users[i];
	}
	delete[] _n_per_user; _n_per_user = 0;
	delete[] _users; _users = 0;
	_has_missing_data = false;
	_n_samples = 0;
	_sample_count = 0;
	_n_streams = 0;
	_n_users = 0;

	return true;
};
Ejemplo n.º 19
0
void PythonImageConsumer::setMetaData(ssi_size_t size, const void *meta) {

	if (sizeof(_format_in) != size) 
	{
		ssi_err("meta data does not describe image format");
	}

	if (!_helper)
	{
		initHelper();
	}
	
	memcpy(&_format_in, meta, size);
	_has_meta_data = true;

	ssi_msg(SSI_LOG_LEVEL_BASIC, "format of input image '%dx%dx%dx%d'", _format_in.widthInPixels, _format_in.heightInPixels, _format_in.numOfChannels, _format_in.depthInBitsPerChannel / 8)

	_helper->setImageFormatIn(_format_in);
};
Ejemplo n.º 20
0
void EventConsumer::consume (IConsumer::info info) {
	
	if (info.dur <= 0) {
		return;
	}

	ssi_msg (SSI_LOG_LEVEL_DETAIL, "update (%.2lf@%.2lf, status: %d)", info.dur, info.time, info.status);

	for (ssi_size_t i = 0; i < _consumer_count; i++) {

        SSI_DBG (SSI_LOG_LEVEL_DEBUG, "update '%s'", _consumer[i]->_consumer->getName ());

		int status = _consumer[i]->consume (info);	
#if __gnu_linux__
        if(_terminate)return;
#endif
		// check if operation was successful
		// otherwise try to handle the error
		switch (status) {
			case TimeBuffer::SUCCESS:
				// operation was successful!							
				break;
			case TimeBuffer::DATA_NOT_IN_BUFFER_YET:
				// not all _data is yet available
				// we return and hope that it will be available at next call..
				SSI_DBG (SSI_LOG_LEVEL_DEBUG, "data not in buffer yet '%s'", _consumer[i]->_consumer->getName ());
				break;
			case THEFRAMEWORK_ERROR:
				// framework error, probably framework is in idle mode
				// there is not much to do for us but wait..
				//SSI_DBG (SSI_LOG_LEVEL_DEBUG, "framework not running '%s'", _consumer[i]->getName ());
				break;
			default:
				// well, something critical happend, probably the requested _data is not available anymore				
				ssi_wrn ("requested data not available (%s) '%s'", TimeBuffer::STATUS_NAMES[status], _consumer[i]->_consumer->getName ());
				ssi_time_t frame_time = _frame->GetElapsedTime ();
				_consumer[i]->_consumer->consume_fail (info.time, frame_time - info.time, _consumer[i]->_stream_number, _consumer[i]->_streams);
				info.time = frame_time;
				break; 
		}
	}
}
Ejemplo n.º 21
0
void Transformer::enter () {

	if (_frame->IsInIdleMode ()) {
		_read_pos = 0;
	} else {
		_frame->GetCurrentWritePos (_buffer_id_in, _read_pos);
	}

	_transformer->transform_enter (_stream_in, _stream_out, _xtra_stream_num, _xtra_streams);

	ssi_stream_adjust (_stream_in, _sample_number_in);
	ssi_stream_adjust (_stream_out, _sample_number_out);

	ssi_time_t buffer_size;
	_frame->GetCapacity(_buffer_id_out, buffer_size);

	ssi_msg (SSI_LOG_LEVEL_BASIC, "start '%s:%s'", _transformer->getName (), Factory::GetObjectId(_transformer));
	if ( ssi_log_level >= SSI_LOG_LEVEL_BASIC) {
		ssi_print ("\
             frame[s]\t= %.2lf\n\
             delta[s]\t= %.2lf\n\
             id\t\t= %d -> %d\n\
             rate[hz]\t= %.2lf -> %.2lf\n\
             dim\t= %u -> %d\n\
             bytes\t= %u -> %d\n\
             type\t= %s -> %s\n\
             buffer[s]\t= %.2lf\n",			
			_frame_size,
			_delta_size,
			_buffer_id_in,
			_buffer_id_out,
			_stream_in.sr, 
			_stream_out.sr, 
			_stream_in.dim, 
			_stream_out.dim, 
			_stream_in.byte,
			_stream_out.byte,			
			SSI_TYPE_NAMES[_stream_in.type],
			SSI_TYPE_NAMES[_stream_out.type],
			buffer_size);
	}
Ejemplo n.º 22
0
LRESULT CALLBACK CheckBox::windowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {

	if (!_hWnd) {
		_hWnd = hWnd;
	}

	switch (msg) {

	case WM_CREATE: {
		create(hWnd, 0);
		return 0;
	}

	case WM_COMMAND: {

		bool result = ::SendMessage(_hCheckBox, (UINT)BM_GETCHECK, (WPARAM)0, (LPARAM)0) == BST_CHECKED;
		
		if (result) {
			::SendMessage(_hCheckBox, (UINT)BM_SETCHECK, (WPARAM)BST_UNCHECKED, (LPARAM)0);
			_checked = false;
		} else {
			::SendMessage(_hCheckBox, (UINT)BM_SETCHECK, (WPARAM)BST_CHECKED, (LPARAM)0);
			_checked = true;
		}

		if (_callback) {
			_callback->update(_checked);
		}

		ssi_msg(SSI_LOG_LEVEL_DETAIL, _checked ? "checked" : "unchecked");
	
		return 0;
		
	}

	}

	return DefWindowProc(hWnd, msg, wParam, lParam);
}
Ejemplo n.º 23
0
void SocketEventReader::enter () {

	_socket = Socket::CreateAndConnect (_options.type, Socket::SERVER, _options.port, _options.host);	
	if (_options.osc) {
		_socket_osc = new SocketOsc (*_socket, _options.size);
	} else {
		_buffer = new ssi_byte_t[_options.size];
	}
	
	if (!_socket) {
		ssi_wrn ("could not connect '%s@%u'", _options.host, _options.port);
	}

	_frame = Factory::GetFramework ();
	
	ssi_char_t string[SSI_MAX_CHAR];
	ssi_sprint (string, "SocketEventReader@'%s@%u'", _options.host, _options.port); 	
	Thread::setName (string);

	ssi_sprint(string, "%s@%u", _options.host, _options.port);
	ssi_msg(SSI_LOG_LEVEL_BASIC, "started '%s'", string);
}
Ejemplo n.º 24
0
// stops the thread
bool Thread::stop () {


	ssi_msg (SSI_LOG_LEVEL_DEFAULT, "terminate%s'%s'", _single_execution ? " single execution " : " ", _name);

	// if not single execution signal run method to terminate

	if (!_single_execution) {
		Lock lock (_mutex);
		_is_active = false;
	}
	// give user the chance to terminate run ()
	terminate ();

	// wait until thread has terminated
	#if hasCXX11threads
	bool success = true;

	//evil thread slaying has to be adapted for windows
	/*
    pthread_t phandle=_handle->native_handle();
    
    
    std::thread
    ( [](unsigned int* _timeout, unsigned int* phandle)
		{
			pthread_t* phandle_mine=(pthread_t*)phandle;
			std::chrono::milliseconds dura(*_timeout);
			std::this_thread::sleep_for( dura  );
			ssi_wrn ("time-out elapsed 'unknown'");
			pthread_cancel(*phandle);
		}, (unsigned int*)&_timeout, (unsigned int*)&phandle
    ).detach();;
    */
    
    
	_handle->join();



	//todo interruptible threads
	delete _handle;

	#else
    DWORD result;
	result = ::WaitForSingleObject((HANDLE) _handle, _timeout);


	bool success = true;
	if (result == WAIT_TIMEOUT) {
		ssi_wrn ("time-out elapsed '%s'", _name);
		success = false;
	} else if (result == WAIT_FAILED) {
		ssi_wrn ("WaitForSingleObject() failed - error=%lu - ", ::GetLastError (), _name);
		success = false;
	}
	// close _handle



	::CloseHandle ((HANDLE) _handle);
	#endif // hasCXX11threads


	ssi_char_t string[SSI_MAX_CHAR];
	_stop_time = ssi_time_ms ();
	ssi_time_sprint (_stop_time - _start_time, string);
	ssi_msg (SSI_LOG_LEVEL_DEFAULT, "stop%safter %s '%s'", _single_execution ? " single execution " : " ", string, _name);

	return success;
}
Ejemplo n.º 25
0
void MyEventListener::listen_enter() {

	ssi_msg(SSI_LOG_LEVEL_BASIC, "enter()..ok");
}
Ejemplo n.º 26
0
void MyEventListener::listen_flush() {

	ssi_msg(SSI_LOG_LEVEL_BASIC, "flush()..ok");
}
Ejemplo n.º 27
0
bool Chain::parse (const ssi_char_t *filepath) {

	release ();

	if (filepath == 0 || filepath[0] == '\0') {
		ssi_wrn ("file is empty");
		return false;
	}

	FilePath fp (filepath);
	ssi_char_t *filepath_with_ext = 0;
	if (strcmp (fp.getExtension (), SSI_FILE_TYPE_CHAIN) != 0) {
		filepath_with_ext = ssi_strcat (filepath, SSI_FILE_TYPE_CHAIN);
	} else {
		filepath_with_ext = ssi_strcpy (filepath);
	}

	if (!ssi_exists (filepath_with_ext)) {
		ssi_wrn ("file not found '%s", filepath_with_ext);
		return false;
	}

	ssi_msg (SSI_LOG_LEVEL_BASIC, "load '%s'", filepath_with_ext);

	TiXmlDocument doc;
	if (!doc.LoadFile (filepath_with_ext)) {
		ssi_wrn ("failed loading chain from file '%s'", filepath_with_ext);
		delete[] filepath_with_ext;
		return false;
	}

	TiXmlElement *body = doc.FirstChildElement();	
	if (!body || strcmp (body->Value (), "chain") != 0) {
		ssi_wrn ("tag <chain> missing");
		delete[] filepath_with_ext;
		return false;	
	}

	TiXmlElement *filter = body->FirstChildElement ("filter");
	if (filter) {
		if (!parseFilter (filter)) {
			ssi_wrn ("failed parsing <filter> tag");
			return false;
		}
	}

	TiXmlElement *feature = body->FirstChildElement ("feature");
	if (feature) {
		if (!parseFeature (feature)) {
			ssi_wrn ("failed parsing <feature> tag");
			return false;
		}
	}

	_parsed = feature || filter;
	if (!_parsed) {
		ssi_wrn ("parsing failed because no feature/filter were loaded");
	}

	return _parsed;
}
Ejemplo n.º 28
0
bool FileSamplesOut::open (ISamples &data,
	const ssi_char_t *path,
	File::TYPE type, 
	File::VERSION version) {

	ssi_msg (SSI_LOG_LEVEL_DETAIL, "open files '%s'", path);	

	_version = version;

	if (_version < File::V2) {
		ssi_wrn ("version < V2 not supported");
		return false;
	}

	if (_file_info || _file_data) {
		ssi_wrn ("samples already open");
		return false;
	}

	_n_users = data.getUserSize ();
	_users = new ssi_char_t *[_n_users];
	_n_per_user = new ssi_size_t[_n_users];
	for (ssi_size_t i = 0; i < _n_users; i++) {
		_users[i] = ssi_strcpy (data.getUserName (i));
		_n_per_user[i] = 0;
	}
	_n_classes = data.getClassSize ();
	_classes = new ssi_char_t *[_n_classes];
	_n_per_class = new ssi_size_t[_n_classes];
	for (ssi_size_t i = 0; i < _n_classes; i++) {
		_classes[i] = ssi_strcpy (data.getClassName (i));
		_n_per_class[i] = 0;
	}
	
	_n_streams = data.getStreamSize ();
	_streams = new ssi_stream_t[_n_streams];
	for (ssi_size_t i = 0; i < _n_streams; i++) {
		ssi_stream_t s = data.getStream (i);
		ssi_stream_init (_streams[i], 0, s.dim, s.byte, s.type, s.sr, 0);
	}

	_has_missing_data = false;

	if (path == 0 || path[0] == '\0') {
		_console = true;
	}

	if (_console) {
		
		_file_data = File::CreateAndOpen (type, File::WRITE, "");
		if (!_file_data) {
			ssi_wrn ("could not open console");
			return false;
		}

	} else {

		FilePath fp (path);
		ssi_char_t *path_info = 0;
		if (strcmp (fp.getExtension (), SSI_FILE_TYPE_SAMPLES) != 0) {
			path_info = ssi_strcat (path, SSI_FILE_TYPE_SAMPLES);
		} else {
			path_info = ssi_strcpy (path);
		}	
		_path = ssi_strcpy (path_info);

		_file_info = File::CreateAndOpen (File::ASCII, File::WRITE, path_info);
		if (!_file_info) {
			ssi_wrn ("could not open info file '%s'", path_info);
			return false;
		}

		ssi_sprint (_string, "<?xml version=\"1.0\" ?>\n<samples ssi-v=\"%d\">", version);
		_file_info->writeLine (_string);
	
		ssi_char_t *path_data = ssi_strcat (path_info, "~");			
		_file_data = File::CreateAndOpen (type, File::WRITE, path_data);
		if (!_file_data) {
			ssi_wrn ("could not open data file '%s'", path_data);
			return false;
		}

		if (_version == File::V3) {

			_file_streams = new FileStreamOut[_n_streams];
			ssi_char_t string[SSI_MAX_CHAR];
			for (ssi_size_t i = 0; i < _n_streams; i++) {
				ssi_sprint (string, "%s.#%u", path_info, i);
				_file_streams[i].open (_streams[i], string, type);				
			}

		}

		delete[] path_info;
		delete[] path_data;

	}

	return true;
};
Ejemplo n.º 29
0
bool FileSamplesOut::close () { 

	ssi_msg (SSI_LOG_LEVEL_DETAIL, "close files '%s'", _path);

	if (!_console) {

		if (!_file_data->close ()) {
			ssi_wrn ("could not close data file '%s'", _path);
			return false;
		}

		switch (_version) {
			
			case File::V2: {

				TiXmlElement info ("info" );	
				info.SetAttribute ("ftype", File::TYPE_NAMES[_file_data->getType ()]);
				info.SetAttribute ("size", _n_samples);
				info.SetAttribute ("missing", _has_missing_data ? 1 : 0);
				info.SetAttribute ("garbage", _n_garbage_class);

				TiXmlElement streams ("streams");
				for (ssi_size_t i = 0; i < _n_streams; i++) {
					TiXmlElement item ("item");
					item.SetDoubleAttribute ("sr", _streams[i].sr);
					item.SetAttribute ("dim", _streams[i].dim);
					item.SetAttribute ("byte", _streams[i].byte);
					item.SetAttribute ("type", SSI_TYPE_NAMES[_streams[i].type]);
					streams.InsertEndChild (item);
				}
				info.InsertEndChild (streams);

				TiXmlElement classes ("classes");
				for (ssi_size_t i = 0; i < _n_classes; i++) {
					TiXmlElement item ("item");			
					item.SetAttribute ("name", _classes[i]);			
					item.SetAttribute ("size", _n_per_class[i]);
					classes.InsertEndChild (item);
				}
				info.InsertEndChild (classes);

				TiXmlElement users ("users");
				for (ssi_size_t i = 0; i < _n_users; i++) {
					TiXmlElement item ("item");			
					item.SetAttribute ("name", _users[i]);			
					item.SetAttribute ("size", _n_per_user[i]);
					users.InsertEndChild (item);
				}
				info.InsertEndChild (users);

				info.Print (_file_info->getFile (), 1);
				_file_info->writeLine ("\n</samples>");

				if (!_file_info->close ()) {
					ssi_wrn ("could not close info file '%s'", _file_info->getPath ());
					return false;
				}

			}
			break;

			case File::V3: {

				TiXmlElement info ("info" );	
				info.SetAttribute ("ftype", File::TYPE_NAMES[_file_data->getType ()]);
				info.SetAttribute ("size", _n_samples);
				info.SetAttribute ("missing", _has_missing_data ? "true" : "false");
				info.SetAttribute ("garbage", _n_garbage_class);

				TiXmlElement streams ("streams");
				for (ssi_size_t i = 0; i < _n_streams; i++) {
					TiXmlElement item ("item");
					FilePath fp (_file_streams[i].getInfoFile ()->getPath ());
					item.SetAttribute ("path", fp.getName ());
					streams.InsertEndChild (item);
				}

				TiXmlElement classes ("classes");
				for (ssi_size_t i = 0; i < _n_classes; i++) {
					TiXmlElement item ("item");			
					item.SetAttribute ("name", _classes[i]);			
					item.SetAttribute ("size", _n_per_class[i]);
					classes.InsertEndChild (item);
				}

				TiXmlElement users ("users");
				for (ssi_size_t i = 0; i < _n_users; i++) {
					TiXmlElement item ("item");			
					item.SetAttribute ("name", _users[i]);			
					item.SetAttribute ("size", _n_per_user[i]);
					users.InsertEndChild (item);
				}

				info.Print (_file_info->getFile (), 1);
				_file_info->writeLine ("");
				streams.Print (_file_info->getFile (), 1);
				_file_info->writeLine ("");
				classes.Print (_file_info->getFile (), 1);
				_file_info->writeLine ("");
				users.Print (_file_info->getFile (), 1);
				_file_info->writeLine ("\n</samples>");

				if (!_file_info->close ()) {
					ssi_wrn ("could not close info file '%s'", _file_info->getPath ());
					return false;
				}
			}
		}
	}

	if (_file_streams) {
		for (ssi_size_t i = 0; i < _n_streams; i++) {			
			_file_streams[i].close ();
		}
	}

	delete _file_data; _file_data = 0;
	delete _file_info; _file_info = 0;
	delete[] _file_streams; _file_streams = 0;
	delete _path; _path = 0;

	for (ssi_size_t i = 0; i < _n_classes; i++) {
		delete[] _classes[i];
	}
	delete[] _classes; _classes = 0;
	delete[] _n_per_class; _n_per_class = 0;
	_n_garbage_class = 0;
	for (ssi_size_t i = 0; i < _n_users; i++) {
		delete[] _users[i];
	}
	delete[] _users; _users = 0;
	delete[] _n_per_user; _n_per_user = 0;	
	delete[] _streams; _streams = 0;

	_n_samples = 0;
	_n_classes = 0;
	_n_users = 0;	
	_n_streams = 0;

	return true;
};
Ejemplo n.º 30
0
void PythonObject::initHelper()
{
	_helper = new PythonHelper(_options.script, _options.optsfile, _options.optsstr, _options.syspath);

	ssi_msg(SSI_LOG_LEVEL_DETAIL, "python is ready");
}