Beispiel #1
0
bool DistributedServer::loadModuleEx(std::string alias, NSCAPI::moduleLoadMode mode) {
	std::wstring host, suffix, server_mode;
	unsigned int thread_count;
	try {
		sh::settings_registry settings(get_settings_proxy());
		settings.set_alias(_T("distributed"), alias, _T("server"));

		settings.alias().add_path_to_settings()
			(_T("DISTRIBUTED NSCP SERVER SECTION"), _T("Section for Distributed NSCP (DistributedServer) (check_nscp) protocol options."))
			;

		settings.alias().add_key_to_settings()
			(_T("host"), sh::wstring_key(&host, _T("tcp://*:5555")),
			_T("HOST TO BIND/CONNECT TO"), _T("The host to bind/connect to"))

			(_T("suffix"), sh::wstring_key(&suffix, _T("ncsp.dist")),
			_T("SUFFIX FOR INTERNAL CHANNELS"), _T("Has to be uniq on each server"))

			(_T("worker pool size"), sh::uint_key(&thread_count, 10),
			_T("WORKER POOL SIZE"), _T("Number of threads to spawn for the worker pool"))

			(_T("mode"), sh::wstring_key(&server_mode, _T("master")),
			_T("OPERATION MODE"), _T("Mode of operation can only be master now but will add more later on (such as slave)"))
			;

		settings.register_all();
		settings.notify();

		if (mode == NSCAPI::normalStart) {
			context = new zmq::context_t(2);

			zeromq_queue::connection_info queue_info(to_string(host), to_string(suffix));
			zeromq_queue::queue_manager queue;
			queue.start(context, threads, queue_info);

			zeromq_worker::connection_info worker_info(queue_info.get_backend(), to_string(suffix), thread_count);
			zeromq_worker::worker_manager workers;
			workers.start(context, threads, worker_info);
		}

	} catch (std::exception &e) {
		NSC_LOG_ERROR_STD(_T("Exception caught: ") + to_wstring(e.what()));
		return false;
	} catch (...) {
		NSC_LOG_ERROR_STD(_T("Exception caught: <UNKNOWN EXCEPTION>"));
		return false;
	}
	return true;
}
Beispiel #2
0
/*
 * Randomly shuffle the entire play queue
 *
 * Moves the entrie queue into an array of play_queue pointers.
 * Shuffles the array, and relink the pointers from the array
 * as the play_queue.
 */
void queue_shuffle()
{
	struct play_queue *shuffle_array[queue_entry->size-1];
	int cnt = 0;

	struct play_queue *current = queue_entry->head;
    if(current == NULL || current->next == NULL) {
        //printf("Not enough tracks in queue to shuffle\n");
        return;
    }

	while(cnt < queue_entry->size) {
		shuffle_array[cnt] = current;
		current = current->next;
		cnt++;
	}

	int i = queue_entry->size-1;
	struct play_queue *tmp;

	for(i = queue_entry->size-1; i > 0; i--) {
		int rand = rand_lim(i);
		tmp = shuffle_array[rand];
		shuffle_array[rand] = shuffle_array[i];
		shuffle_array[i] = tmp;
	}

	cnt = 0;
    queue_entry->head = shuffle_array[0];
	current = queue_entry->head;
    cnt++;

	while(cnt < queue_entry->size-1) {
		current->next = shuffle_array[cnt];
		current = current->next;
		cnt++;
	}

    current->next = shuffle_array[cnt];
    current = current->next;
    queue_entry->tail = current;
    current->next = NULL;

    queue_info();
}