Index: branches/2.0/drmaa2_utils/configure.ac
===================================================================
--- branches/2.0/drmaa2_utils/configure.ac	(revision 78)
+++ branches/2.0/drmaa2_utils/configure.ac	(revision 81)
@@ -86,7 +86,4 @@
 fi
 
-if test x$GCC = xyes; then
-	CFLAGS="-pedantic -ansi ${CFLAGS}"
-fi
 AM_CONDITIONAL([GCC], [test x$GCC = xyes])
 
Index: branches/2.0/drmaa2_utils/drmaa_utils/common.h
===================================================================
--- branches/2.0/drmaa2_utils/drmaa_utils/common.h	(revision 77)
+++ branches/2.0/drmaa2_utils/drmaa_utils/common.h	(revision 81)
@@ -29,4 +29,6 @@
 #include <drmaa_utils/logging.h>
 #include <drmaa_utils/xmalloc.h>
+#include <drmaa_utils/drmaa2.h>
+
 
 #define FSD_SAFE_STR(str) ( str != NULL ? str : "(null)" )
@@ -45,5 +47,8 @@
 /* DRMAA structures */
 typedef struct fsd_drmaa_singletone_s  fsd_drmaa_singletone_t;
-typedef struct fsd_drmaa_session_s     fsd_drmaa_session_t;
+typedef struct fsd_drmaa_jsession_s     fsd_drmaa_jsession_t;
+typedef struct fsd_drmaa_rsession_s     fsd_drmaa_rsession_t;
+typedef struct fsd_drmaa_msession_s     fsd_drmaa_msession_t;
+
 typedef struct fsd_job_set_s           fsd_job_set_t;
 typedef struct fsd_job_s               fsd_job_t;
Index: branches/2.0/drmaa2_utils/drmaa_utils/jsession.h
===================================================================
--- branches/2.0/drmaa2_utils/drmaa_utils/jsession.h	(revision 81)
+++ branches/2.0/drmaa2_utils/drmaa_utils/jsession.h	(revision 81)
@@ -0,0 +1,332 @@
+/* $Id: session.h 13 2011-04-20 15:41:43Z mmamonski $ */
+/*
+ *  PSNC DRMAA 2.0 utilities library
+ *  Copyright (C) 2012  Poznan Supercomputing and Networking Center
+ *
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ * @file session.h
+ * DRMAA session.
+ */
+
+#ifndef __DRMAA_UTILS__SESSION_H
+#define __DRMAA_UTILS__SESSION_H
+
+#include <sys/time.h>
+
+#include <drmaa_utils/common.h>
+#include <drmaa_utils/thread.h>
+
+/** Creates new DRMAA session. */
+fsd_drmaa_jsession_t *
+fsd_drmaa_jsession_new( const char *contact );
+
+/**
+ * Get current (global) DRMAA session
+ * and increase it's reference count.
+ */
+fsd_drmaa_jsession_t *
+fsd_drmaa_jsession_get(void);
+
+/**
+ * An action to be taken when job is missing from queue.
+ */
+typedef enum {
+	/**
+	 * Always raise #FSD_ERRNO_INTERNAL_ERROR (one per job)
+	 * in drmaa_wait() or drmaa_synchronize()
+	 * when job disappearance is spotted.
+	 */
+	FSD_REVEAL_MISSING_JOBS,
+	/**
+	 * Treat missing jobs as terminated with status
+	 * depending on last known state and action (drmaa_control()).
+	 */
+	FSD_IGNORE_MISSING_JOBS,
+	/**
+	 * Treat missing jobs as terminated
+	 * but only before they enter into running state.
+	 */
+	FSD_IGNORE_QUEUED_MISSING_JOBS
+} fsd_missing_jobs_behaviour_t;
+
+
+/** DRMAA JobSession data. */
+struct fsd_drmaa_jsession_s {
+	drmaa2_string (*get_contact)(fsd_drmaa_jsession_t *self);
+
+	drmaa2_string (*get_session_name)(fsd_drmaa_jsession_t *self);
+
+	drmaa2_string_list (*get_job_categories)(fsd_drmaa_jsession_t *self);
+
+	drmaa2_j_list (*get_jobs)(fsd_drmaa_jsession_t *self);
+
+	drmaa2_jarray (*get_job_array)(fsd_drmaa_jsession_t *self);
+
+	drmaa2_j (*run_job)(fsd_drmaa_jsession_t *self);
+
+	drmaa2_jarray (*run_bulk_jobs)(fsd_drmaa_jsession_t *self);
+
+	drmaa2_j (*wait_any_started)(fsd_drmaa_jsession_t *self, const drmaa2_j_list l, const time_t timeout);
+
+	drmaa2_j (*wait_any_terminated)(fsd_drmaa_jsession_t *self, const drmaa2_j_list l, const time_t timeout);
+
+
+	void (*destroy)(fsd_drmaa_jsession_t *self);
+
+	void (*close)(fsd_drmaa_jsession_t *self);
+
+	drmaa2_string contact;
+	drmaa2_string session_name;
+
+#if 0
+
+	/**
+	 * Destroy session without waiting for releasing references.
+	 */
+	void (*
+	destroy_nowait)( fsd_drmaa_jsession_t *self );
+
+
+	/** Implements drmaa_run_job(). */
+	char* (*
+	run_job)(
+			fsd_drmaa_jsession_t *self,
+			const fsd_template_t *jt
+			);
+
+	/** Implements drmaa_run_bulk_jobs(). */
+	fsd_iter_t* (*
+	run_bulk)(
+			fsd_drmaa_jsession_t *self,
+			const fsd_template_t *jt,
+			int start, int end, int incr
+			);
+
+	/** Implements drmaa_control(). */
+	void (*
+	control_job)(
+			fsd_drmaa_jsession_t *self,
+			const char *job_id, int action
+			);
+
+	/** Implements drmaa_job_ps(). */
+	void (*
+	job_ps)(
+			fsd_drmaa_jsession_t *self,
+			const char *job_id, int *remote_ps
+			);
+
+	/** Implements drmaa_synchronize(). */
+	void (*
+	synchronize)(
+			fsd_drmaa_jsession_t *self,
+			const char **input_job_ids, const struct timespec *timeout,
+			bool dispose
+			);
+
+	/**
+	 * Implements drmaa_wait() call.
+	 * @param self     DRMAA session.
+	 * @param job_id   Job identifer to wait for or #DRMAA_JOB_IDS_SESSION_ANY
+	 * @param timeout  Timeout after which call shall raise
+	 *   #FSD_DRMAA_ERRNO_EXIT_TIMEOUT if job not terminated or \c NULL.
+	 * @param status   Terminated job status (output only).
+	 * @param rusage   Job resource usage (output only).
+	 * @see drmaa_wait()
+	 * @see #wait_for_single_job  #wait_for_any_job
+	 */
+	char* (*
+	wait)(
+			fsd_drmaa_jsession_t *self,
+			const char *job_id, const struct timespec *timeout,
+			int *status, fsd_iter_t **rusage
+			);
+
+	/**
+	 * Construct new job object.
+	 * @return Reference to newly created job.
+	 */
+	fsd_job_t* (*
+	new_job)( fsd_drmaa_jsession_t *self, const char *job_id );
+
+	char* (*
+	run_impl)(
+			fsd_drmaa_jsession_t *self,
+			const fsd_template_t *jt, int bulk_incr
+			);
+
+	/**
+	 * Wait until given job terminates (either successfuly or not).
+	 * @param self     DRMAA session.
+	 * @param job_id   Identifier of job to wait for.
+	 * @param timeout  If not \c NULL and job does not terminate
+	 *   in given amount of time function returns and
+	 *   #FSD_DRMAA_ERRNO_EXIT_TIMEOUT is raised.
+	 * @param status   If not \c NULL job status code is stored here.
+	 * @param rusage   If not \c NULL list of used resources is returned.
+	 * @param dispose  If \c true job information is removed from session
+	 *   at the end of call and further accesses to this job_id will
+	 *   raise #FSD_DRMAA_ERRNO_INVALID_JOB.  Otherwise job data is held.
+	 * @see #wait_for_any_job #wait
+	 */
+	void (*
+	wait_for_single_job)(
+			fsd_drmaa_jsession_t *self,
+			const char *job_id, const struct timespec *timeout,
+			int *status, fsd_iter_t **rusage, bool dispose
+			);
+
+	/**
+	 * Wait until and job left in session terminates.
+	 * @return  Identifier of waited job.
+	 *   Freeing responsobility is left to the callee.
+	 * @see #wait_for_single_job #wait
+	 */
+	char* (*
+	wait_for_any_job)(
+			fsd_drmaa_jsession_t *self,
+			const struct timespec *timeout,
+			int *status, fsd_iter_t **rusage,
+			bool dispose
+			);
+
+	void (*
+	wait_for_job_status_change)(
+			fsd_drmaa_jsession_t *self,
+			fsd_cond_t *wait_condition,
+			fsd_mutex_t *mutex,
+			const struct timespec *timeout
+			);
+
+	void* (*
+	wait_thread)( fsd_drmaa_jsession_t *self );
+
+	void (*
+	stop_wait_thread)( fsd_drmaa_jsession_t *self );
+
+	/**
+	 * Make status of all jobs held in session up to date.
+	 */
+	void (*
+	update_all_jobs_status)( fsd_drmaa_jsession_t *self );
+
+	/** Return list of all jobs within session. */
+	char** (*
+	get_submited_job_ids)(
+			fsd_drmaa_jsession_t *self
+			);
+
+	/**
+	 * Get job with given identifier.
+	 * @return New reference to job or \c NULL
+	 *   if no job found.
+	 */
+	fsd_job_t* (*
+	get_job)(
+			fsd_drmaa_jsession_t *self, const char *job_id
+			);
+
+	/**
+	 * Tries to load configuration from following locations in order
+	 * (configuration settings from later locations override
+	 * those from earlier):
+	 * /etc/basename.conf, ~/.basename.conf, $basename_CONF.
+	 */
+	void (*
+	load_configuration)(
+			fsd_drmaa_jsession_t *self, const char *basename
+			);
+
+	void (*
+	read_configuration)(
+			fsd_drmaa_jsession_t *self,
+			const char *filename, bool must_exist,
+			const char *configuration, size_t config_len
+			);
+
+	void (*
+	apply_configuration)(
+			fsd_drmaa_jsession_t *self
+			);
+
+	/** Reference counter. */
+	int ref_cnt;
+
+	/**
+	 * Whether #destroy was called and waits for releasing
+	 * references.  If set pending #wait calls shall
+	 * return with #FSD_DRMAA_ERRNO_NO_ACTIVE_SESSION error.
+	 */
+	bool destroy_requested;
+
+
+
+	/**
+	 * Jobs submitted within this DRMAA session
+	 * and not disposed yet.
+	 */
+	fsd_job_set_t *jobs;
+
+	/** DRMAA configuration. */
+	fsd_conf_dict_t *configuration;
+
+	/** Queue pooling delay (time delta). */
+	struct timespec pool_delay;
+
+	/**
+	 * Cache job state for number of seconds.
+	 * If positive drmaa_job_ps() returns remembered state without
+	 * communicating with DRM for \a cache_job_state seconds since last
+	 * update.
+	 */
+	int cache_job_state;
+
+	/** Whether to wait for jobs in separate thread. */
+	bool enable_wait_thread;
+
+	/**
+	 * Configuration dictionary which maps
+	 * job categories to native specification.
+	 */
+	fsd_conf_dict_t *job_categories;
+
+	/**
+	 * How to behave when submitted job disappears from DRM queue.
+	 */
+	fsd_missing_jobs_behaviour_t missing_jobs;
+
+	fsd_mutex_t mutex; /**< Mutex for accessing session data. */
+	fsd_cond_t wait_condition;  /**< Conditional for drmaa_wait() */
+	fsd_cond_t destroy_condition;  /**< Conditional for ref_cnt==1 */
+
+	/**
+	 * Mutex for accessing connection to DRM.
+	 *
+	 * To prevent deadlocks #mutex should be acquired first
+	 * when both session data and DRM connection are needed.
+	 */
+	fsd_mutex_t drm_connection_mutex;
+
+	fsd_thread_t wait_thread_handle;
+	bool wait_thread_started;
+	bool wait_thread_run_flag;
+#endif
+};
+
+
+#endif /* __DRMAA_UTILS__SESSION_H */
+
Index: branches/2.0/drmaa2_utils/drmaa_utils/drmaa_base.c
===================================================================
--- branches/2.0/drmaa2_utils/drmaa_utils/drmaa_base.c	(revision 77)
+++ branches/2.0/drmaa2_utils/drmaa_utils/drmaa_base.c	(revision 81)
@@ -83,4 +83,10 @@
 
 
+/*
+ * 109 functions in total
+ *
+ * implemented so far:
+ * 14/10/2012 - 0
+ */
 
 void drmaa2_string_free(drmaa2_string *ptr)
Index: branches/2.0/drmaa2_utils/drmaa_utils/drmaa_base.h
===================================================================
--- branches/2.0/drmaa2_utils/drmaa_utils/drmaa_base.h	(revision 77)
+++ branches/2.0/drmaa2_utils/drmaa_utils/drmaa_base.h	(revision 81)
@@ -26,53 +26,21 @@
 
 #include <drmaa_utils/common.h>
-#include <drmaa_utils/thread.h>
+#include <drmaa_utils/drmaa2.h>
 
-#if 0
+
 struct fsd_drmaa_singletone_s {
-	/** Global session object */
-	fsd_drmaa_session_t *session;
-	fsd_mutex_t session_mutex;
 
-	fsd_drmaa_session_t *(*new_session)(
-			fsd_drmaa_singletone_t *self,
-			const char *contact
-			);
+	fsd_drmaa_jsession_t *(*new_jsession)(fsd_drmaa_singletone_t *self, const char *contact);
+	fsd_drmaa_rsession_t *(*new_rsession)(fsd_drmaa_singletone_t *self, const char *contact);
+	fsd_drmaa_msession_t *(*new_msession)(fsd_drmaa_singletone_t *self, const char *contact);
 
-	fsd_template_t *(*new_job_template)(
-			fsd_drmaa_singletone_t *self
-			);
-
-	const char* (*get_contact)( fsd_drmaa_singletone_t *self );
-	void (*get_version)(
-			fsd_drmaa_singletone_t *self,
-			unsigned *major, unsigned *minor
-			);
-	const char* (*get_DRM_system)( fsd_drmaa_singletone_t *self );
-	const char* (*get_DRMAA_implementation)( fsd_drmaa_singletone_t *self );
-
-	fsd_iter_t * (*
-	get_attribute_names)(
-		fsd_drmaa_singletone_t *self );
-
-	fsd_iter_t * (*
-	get_vector_attribute_names)(
-		fsd_drmaa_singletone_t *self );
-
-	int (*wifexited)( int *exited, int stat,
-		char *error_diagnosis, size_t error_diag_len );
-	int (*wexitstatus)( int *exit_status, int stat,
-		char *error_diagnosis, size_t error_diag_len );
-	int (*wifsignaled)( int *signaled, int stat,
-		char *error_diagnosis, size_t error_diag_len );
-	int (*wtermsig)( char *signal, size_t signal_len, int stat,
-		char *error_diagnosis, size_t error_diag_len );
-	int (*wcoredump)( int *core_dumped, int stat,
-		char *error_diagnosis, size_t error_diag_len );
-	int (*wifaborted)( int *aborted, int stat,
-		char *error_diagnosis, size_t error_diag_len );
+	drmaa2_string (*get_drms_name)(void);
+	drmaa2_version (*get_drms_version)(void);
+	drmaa2_string (*get_drmaa_name)(void);
+	drmaa2_version (*get_drmaa_version)(void);
+	drmaa2_bool (*drmaa2_supports)(const drmaa2_capability c);
 };
 
 extern fsd_drmaa_singletone_t _fsd_drmaa_singletone;
-#endif
 
 #endif /* __DRMAA_UTILS__DRMAA_BASE_H */
Index: branches/2.0/drmaa2_utils/drmaa_utils/Makefile.am
===================================================================
--- branches/2.0/drmaa2_utils/drmaa_utils/Makefile.am	(revision 77)
+++ branches/2.0/drmaa2_utils/drmaa_utils/Makefile.am	(revision 81)
@@ -33,5 +33,6 @@
  lookup3.c lookup.h \
  thread.h thread.c \
- xmalloc.h xmalloc.c
+ xmalloc.h xmalloc.c \
+ jsession.h fsd_jsession.c
 # job.h fsd_job.c \
 # session.h fsd_session.c \
Index: branches/2.0/drmaa2_utils/drmaa_utils/fsd_jsession.c
===================================================================
--- branches/2.0/drmaa2_utils/drmaa_utils/fsd_jsession.c	(revision 81)
+++ branches/2.0/drmaa2_utils/drmaa_utils/fsd_jsession.c	(revision 81)
@@ -0,0 +1,1035 @@
+/* $Id: fsd_session.c 28 2011-10-29 21:31:46Z mmamonski $ */
+/*
+ *  PSNC DRMAA 2.0 utilities library
+ *  Copyright (C) 2012  Poznan Supercomputing and Networking Center
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <ctype.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <drmaa_utils/conf.h>
+#include <drmaa_utils/iter.h>
+#include <drmaa_utils/jsession.h>
+
+#ifndef lint
+static char rcsid[]
+#	ifdef __GNUC__
+		__attribute__ ((unused))
+#	endif
+	= "$Id: fsd_session.c 28 2011-10-29 21:31:46Z mmamonski $";
+#endif
+
+
+#if 0
+
+static void
+fsd_drmaa_session_release( fsd_drmaa_session_t *self );
+
+static void
+fsd_drmaa_session_destroy(
+		fsd_drmaa_session_t *self );
+
+static void
+fsd_drmaa_session_destroy_nowait( fsd_drmaa_session_t *self );
+
+static char*
+fsd_drmaa_session_run_job(
+		fsd_drmaa_session_t *self,
+		const fsd_template_t *jt
+		);
+
+static fsd_iter_t*
+fsd_drmaa_session_run_bulk(
+		fsd_drmaa_session_t *self,
+		const fsd_template_t *jt,
+		int start, int end, int incr
+		);
+
+static void
+fsd_drmaa_session_control_job(
+		fsd_drmaa_session_t *self,
+		const char *job_id, int action
+		);
+
+static void
+fsd_drmaa_session_job_ps(
+		fsd_drmaa_session_t *self,
+		const char *job_id, int *remote_ps
+		);
+
+static void
+fsd_drmaa_session_synchronize(
+		fsd_drmaa_session_t *self,
+		const char **input_job_ids, const struct timespec *timeout,
+		bool dispose
+		);
+
+static char*
+fsd_drmaa_session_wait(
+		fsd_drmaa_session_t *self,
+		const char *job_id, const struct timespec *timeout,
+		int *status, fsd_iter_t **rusage
+		);
+
+static fsd_job_t *
+fsd_drmaa_session_new_job(
+		fsd_drmaa_session_t *self,
+		const char *job_id
+		);
+
+static char*
+fsd_drmaa_session_run_impl(
+		fsd_drmaa_session_t *self,
+		const fsd_template_t *jt, int bulk_incr
+		);
+
+static void
+fsd_drmaa_session_wait_for_single_job(
+		fsd_drmaa_session_t *self,
+		const char *job_id, const struct timespec *timeout,
+		int *status, fsd_iter_t **rusage, bool dispose
+		);
+
+static char*
+fsd_drmaa_session_wait_for_any_job(
+		fsd_drmaa_session_t *self,
+		const struct timespec *timeout,
+		int *status, fsd_iter_t **rusage,
+		bool dispose
+		);
+
+static void
+fsd_drmaa_session_wait_for_job_status_change(
+		fsd_drmaa_session_t *self,
+		fsd_cond_t *wait_condition,
+		fsd_mutex_t *mutex,
+		const struct timespec *timeout
+		);
+
+static void*
+fsd_drmaa_session_wait_thread( fsd_drmaa_session_t *self );
+
+static void
+fsd_drmaa_session_stop_wait_thread( fsd_drmaa_session_t *self );
+
+static void
+fsd_drmaa_session_update_all_jobs_status( fsd_drmaa_session_t *self );
+
+static char**
+fsd_drmaa_session_get_submited_job_ids(
+		fsd_drmaa_session_t *self
+		);
+
+static fsd_job_t*
+fsd_drmaa_session_get_job(
+		fsd_drmaa_session_t *self, const char *job_id
+		);
+
+static void
+fsd_drmaa_session_load_configuration(
+		fsd_drmaa_session_t *self, const char *basename
+		);
+
+static void
+fsd_drmaa_session_read_configuration(
+		fsd_drmaa_session_t *self,
+		const char *filename, bool must_exist,
+		const char *configuration, size_t config_len
+		);
+
+static void
+fsd_drmaa_session_apply_configuration(
+		fsd_drmaa_session_t *self
+		);
+
+
+
+fsd_drmaa_session_t *
+fsd_drmaa_session_new( const char *contact )
+{
+	fsd_drmaa_session_t *volatile self = NULL;
+
+	fsd_log_enter(( "(%s)", contact ));
+	TRY
+	 {
+		fsd_malloc( self, fsd_drmaa_session_t );
+
+		self->release = fsd_drmaa_session_release;
+		self->destroy = fsd_drmaa_session_destroy;
+		self->destroy_nowait = fsd_drmaa_session_destroy_nowait;
+		self->run_job = fsd_drmaa_session_run_job;
+		self->run_bulk = fsd_drmaa_session_run_bulk;
+		self->control_job = fsd_drmaa_session_control_job;
+		self->job_ps = fsd_drmaa_session_job_ps;
+		self->synchronize = fsd_drmaa_session_synchronize;
+		self->wait = fsd_drmaa_session_wait;
+		self->new_job = fsd_drmaa_session_new_job;
+		self->run_impl = fsd_drmaa_session_run_impl;
+		self->wait_for_single_job = fsd_drmaa_session_wait_for_single_job;
+		self->wait_for_any_job = fsd_drmaa_session_wait_for_any_job;
+		self->wait_for_job_status_change =
+			fsd_drmaa_session_wait_for_job_status_change;
+		self->wait_thread = fsd_drmaa_session_wait_thread;
+		self->stop_wait_thread = fsd_drmaa_session_stop_wait_thread;
+		self->update_all_jobs_status = fsd_drmaa_session_update_all_jobs_status;
+		self->get_submited_job_ids = fsd_drmaa_session_get_submited_job_ids;
+		self->get_job = fsd_drmaa_session_get_job;
+		self->load_configuration = fsd_drmaa_session_load_configuration;
+		self->read_configuration = fsd_drmaa_session_read_configuration;
+		self->apply_configuration = fsd_drmaa_session_apply_configuration;
+
+		self->ref_cnt = 1;
+		self->destroy_requested = false;
+		self->contact = NULL;
+		self->jobs = NULL;
+		self->configuration = NULL;
+		self->pool_delay.tv_sec = 10;
+		self->pool_delay.tv_nsec = 0;
+		self->cache_job_state = 0;
+		self->enable_wait_thread = false;
+		self->job_categories = NULL;
+		self->missing_jobs = FSD_REVEAL_MISSING_JOBS;
+		self->wait_thread_started = false;
+		self->wait_thread_run_flag = false;
+
+		fsd_mutex_init( &self->mutex );
+		fsd_cond_init( &self->wait_condition );
+		fsd_cond_init( &self->destroy_condition );
+		fsd_mutex_init( &self->drm_connection_mutex );
+		self->jobs = fsd_job_set_new();
+		self->contact = fsd_strdup( contact );
+		
+	 }
+	EXCEPT_DEFAULT
+	 {
+		if( self != NULL )
+			self->destroy( self );
+		fsd_exc_reraise();
+	 }
+	END_TRY
+
+	return self;
+}
+
+
+void
+fsd_drmaa_session_release( fsd_drmaa_session_t *self )
+{
+	fsd_mutex_lock( &self->mutex );
+	self->ref_cnt--;
+	fsd_assert( self->ref_cnt > 0 );
+	if( self->ref_cnt == 1 )
+		fsd_cond_broadcast( &self->destroy_condition );
+	fsd_mutex_unlock( &self->mutex );
+}
+
+
+void
+fsd_drmaa_session_destroy( fsd_drmaa_session_t *self )
+{
+	bool already_destroying = false;
+
+	fsd_log_enter(( "" ));
+	fsd_mutex_lock( &self->mutex );
+	TRY
+	 {
+		if( self->destroy_requested )
+			already_destroying = true;
+		else
+		 {
+			self->destroy_requested = true;
+			fsd_cond_broadcast( &self->wait_condition );
+		 }
+	 }
+	FINALLY
+	 { fsd_mutex_unlock( &self->mutex ); }
+	END_TRY
+
+	if( already_destroying )
+	 { /* XXX: actually it can not happen in current implementation
+				when using DRMAA API */
+		self->release( self );
+		fsd_exc_raise_code( FSD_DRMAA_ERRNO_NO_ACTIVE_SESSION );
+	 }
+
+	self->jobs->signal_all( self->jobs );
+
+	fsd_mutex_lock( &self->mutex );
+	TRY
+	 {
+		while( self->ref_cnt > 1 )
+			fsd_cond_wait( &self->destroy_condition, &self->mutex );
+		fsd_log_debug(("started = %d  run_flag = %d", self->wait_thread_started, self->wait_thread_run_flag ));
+		if( self->wait_thread_started )
+			self->stop_wait_thread( self );
+	 }
+	FINALLY
+	 { fsd_mutex_unlock( &self->mutex ); }
+	END_TRY
+
+	self->destroy_nowait( self );
+	fsd_log_return(( "" ));
+}
+
+
+void
+fsd_drmaa_session_destroy_nowait( fsd_drmaa_session_t *self )
+{
+	fsd_log_enter(( "" ));
+	fsd_conf_dict_destroy( self->configuration );
+	fsd_free( self->contact );
+
+	if( self->jobs )
+		self->jobs->destroy( self->jobs );
+
+	fsd_mutex_destroy( &self->mutex );
+	fsd_cond_destroy( &self->wait_condition );
+	fsd_cond_destroy( &self->destroy_condition );
+	fsd_mutex_destroy( &self->drm_connection_mutex );
+
+	fsd_free( self );
+	fsd_log_return(( "" ));
+}
+
+
+char *
+fsd_drmaa_session_run_job(
+		fsd_drmaa_session_t *self,
+		const fsd_template_t *jt )
+{
+	return self->run_impl( self, jt, -1 );
+}
+
+
+fsd_iter_t *
+fsd_drmaa_session_run_bulk(
+		fsd_drmaa_session_t *self,
+		const fsd_template_t *jt,
+		int start, int end, int incr )
+{
+	volatile unsigned n_jobs;
+	char **volatile result = NULL;
+
+	if( incr > 0 )
+		n_jobs = (end-start) / incr + 1;
+	else
+		n_jobs = (start-end) / -incr + 1;
+
+	TRY
+	 {
+		unsigned i;
+		int idx;
+		fsd_calloc( result, n_jobs + 1, char* );
+		for( i=0, idx=start;  i < n_jobs;  i++, idx+=incr )
+			result[i] = self->run_impl( self, jt, idx );
+	 }
+	EXCEPT_DEFAULT
+	 {
+		if( result )
+			fsd_free_vector( result );
+		fsd_exc_reraise();
+	 }
+	END_TRY
+
+	return fsd_iter_new( result, -1 );
+}
+
+
+void
+fsd_drmaa_session_control_job(
+		fsd_drmaa_session_t *self,
+		const char *job_id, int action )
+{
+	char **job_ids = NULL;
+	char **i;
+
+	TRY
+	 {
+		if( !strcmp( job_id, DRMAA_JOB_IDS_SESSION_ALL ) )
+			job_ids = self->get_submited_job_ids( self );
+		else
+		 {
+			fsd_calloc( job_ids, 2, char* );
+			job_ids[0] = fsd_strdup( job_id );
+		 }
+
+		for( i = job_ids;  *i != NULL;  i++ )
+		 {
+			fsd_job_t *job = NULL;
+			TRY
+			 {
+				job = self->get_job( self, *i );
+				if( job == NULL )
+				 {
+					if( !strcmp( job_id, DRMAA_JOB_IDS_SESSION_ALL ) )
+					 { /* job was just removed from session */ }
+					else
+						job = self->new_job( self, *i );
+				 }
+				if( job )
+					job->control( job, action );
+			 }
+			FINALLY
+			 {
+				if ( job )
+				 job->release( job );
+			 }
+			END_TRY
+		 }
+	 }
+	FINALLY
+	 {
+		fsd_free_vector( job_ids );
+	 }
+	END_TRY
+}
+
+
+void
+fsd_drmaa_session_job_ps(
+		fsd_drmaa_session_t *self, const char *job_id, int *remote_ps )
+{
+	fsd_job_t *volatile job = NULL;
+	TRY
+	 {
+		job = self->get_job( self, job_id );
+		if( job == NULL )
+		 {
+			fsd_log_info(( "job_ps: recreating job object: %s", job_id ));
+			job = self->new_job( self, job_id );
+		 }
+		fsd_log_debug((" job->last_update_time = %u",  (unsigned int)job->last_update_time));
+		if( time(NULL) - job->last_update_time >= self->cache_job_state
+				|| job->state == DRMAA_PS_UNDETERMINED ) 
+		  {
+			fsd_log_debug(("updating status of job: %s ", job_id));
+			job->update_status( job );
+			job->last_update_time = time(NULL);
+		  }
+		*remote_ps = job->state;
+	 }
+	FINALLY
+	 {
+		if( job )
+			job->release( job );
+	 }
+	END_TRY
+}
+
+
+void
+fsd_drmaa_session_synchronize(
+		fsd_drmaa_session_t *self,
+		const char **input_job_ids, const struct timespec *timeout,
+		bool dispose
+		)
+{
+	volatile bool wait_for_all = false;
+	char **volatile job_ids_buf = NULL;
+	const char **job_ids = NULL;
+	const char **i;
+
+	fsd_log_enter(( "(job_ids={...}, timeout=..., dispose=%d)",
+			(int)dispose ));
+
+	if( input_job_ids == NULL )
+		fsd_exc_raise_code( FSD_ERRNO_INVALID_ARGUMENT );
+
+	TRY
+	 {
+		for( i = input_job_ids;  *i != NULL;  i++ )
+			if( !strcmp(*i, DRMAA_JOB_IDS_SESSION_ALL) )
+				wait_for_all = true;
+
+		if( wait_for_all )
+		 {
+			job_ids_buf = self->get_submited_job_ids( self );
+			job_ids = (const char**)job_ids_buf;
+		 }
+		else
+			job_ids = input_job_ids;
+
+		for( i = job_ids;  *i != NULL;  i++ )
+			TRY
+			 {
+				self->wait_for_single_job( self, *i, timeout, NULL, NULL, dispose );
+			 }
+			EXCEPT( FSD_DRMAA_ERRNO_INVALID_JOB )
+			 { /* job was ripped by another thread */ }
+			END_TRY
+	 }
+	FINALLY
+	 {
+		fsd_free_vector( job_ids_buf );
+	 }
+	END_TRY
+}
+
+
+char *
+fsd_drmaa_session_wait(
+		fsd_drmaa_session_t *self,
+		const char *job_id, const struct timespec *timeout,
+		int *stat, fsd_iter_t **rusage
+		)
+{
+	if( 0==strcmp(job_id, DRMAA_JOB_IDS_SESSION_ANY) )
+		return self->wait_for_any_job( self, timeout, stat, rusage, true );
+	else
+	 {
+		self->wait_for_single_job( self, job_id, timeout, stat, rusage, true );
+		return fsd_strdup( job_id );
+	 }
+}
+
+
+fsd_job_t *
+fsd_drmaa_session_new_job( fsd_drmaa_session_t *self, const char *job_id )
+{
+	fsd_job_t *job;
+	job = fsd_job_new( fsd_strdup(job_id) );
+	job->session = self;
+	return job;
+}
+
+
+char *
+fsd_drmaa_session_run_impl(
+		fsd_drmaa_session_t *self,
+		const fsd_template_t *jt, int bulk_incr )
+{
+	fsd_exc_raise_code( FSD_ERRNO_NOT_IMPLEMENTED );
+}
+
+
+void
+fsd_drmaa_session_wait_for_single_job(
+		fsd_drmaa_session_t *self,
+		const char *job_id, const struct timespec *timeout,
+		int *status, fsd_iter_t **rusage,
+		bool dispose
+		)
+{
+	fsd_job_t *volatile job = NULL;
+	volatile bool locked = false;
+
+	fsd_log_enter(( "(%s)", job_id ));
+	TRY
+	 {
+		job = self->get_job( self, job_id );
+		if( job == NULL )
+			fsd_exc_raise_fmt( FSD_DRMAA_ERRNO_INVALID_JOB,
+					"Job '%s' not found in DRMS queue", job_id );
+		job->update_status( job );
+		while( !self->destroy_requested  &&  job->state < DRMAA_PS_DONE )
+		 {
+			bool signaled = true;
+			fsd_log_debug(( "fsd_drmaa_session_wait_for_single_job: "
+						"waiting for %s to terminate", job_id ));
+			if( self->enable_wait_thread )
+			 {
+				if( timeout )
+					signaled = fsd_cond_timedwait(
+							&job->status_cond, &job->mutex, timeout );
+				else
+				 {
+					fsd_cond_wait( &job->status_cond, &job->mutex );
+				 }
+				if( !signaled )
+					fsd_exc_raise_code( FSD_DRMAA_ERRNO_EXIT_TIMEOUT );
+			 }
+			else
+			 {
+				self->wait_for_job_status_change(
+						self, &job->status_cond, &job->mutex, timeout );
+			 }
+
+			fsd_log_debug(( "fsd_drmaa_session_wait_for_single_job: woken up" ));
+			if( !self->enable_wait_thread )
+				job->update_status( job );
+		 }
+
+		if( self->destroy_requested )
+			fsd_exc_raise_code( FSD_DRMAA_ERRNO_EXIT_TIMEOUT );
+
+		job->get_termination_status( job, status, rusage );
+		if( dispose )
+		 {
+			job->release( job ); /*release mutex in order to ensure proper order of locking: first job_set mutex then job mutex */
+
+			locked = fsd_mutex_lock( &self->mutex );
+
+			job = self->get_job( self, job_id );
+			if (job != NULL)
+			 {
+				self->jobs->remove( self->jobs, job );
+				job->flags |= FSD_JOB_DISPOSED;
+			 }
+			else
+			 {
+				fsd_log_error(("Some other thread has already reaped job %s", job_id ));
+			 }
+
+			locked = fsd_mutex_unlock( &self->mutex );
+		 }
+	 }
+	FINALLY
+	 {
+		if ( job )
+			job->release( job );
+		if ( locked )
+			fsd_mutex_unlock( &self->mutex );
+	 }
+	END_TRY
+	fsd_log_return((""));
+}
+
+
+char *
+fsd_drmaa_session_wait_for_any_job(
+		fsd_drmaa_session_t *self,
+		const struct timespec *timeout,
+		int *status, fsd_iter_t **rusage,
+		bool dispose
+		)
+{
+	fsd_job_set_t *set = self->jobs;
+	fsd_job_t *volatile job = NULL;
+	char *volatile job_id = NULL;
+	volatile bool locked = false;
+
+	fsd_log_enter(( "" ));
+
+	TRY
+	 {
+		while( job == NULL )
+		 {
+			bool signaled = true;
+
+			if( self->destroy_requested )
+				fsd_exc_raise_code( FSD_DRMAA_ERRNO_NO_ACTIVE_SESSION );
+
+			if( !self->enable_wait_thread )
+				self->update_all_jobs_status( self );
+
+			locked = fsd_mutex_lock( &self->mutex );
+			if( set->empty( set ) )
+				fsd_exc_raise_msg( FSD_DRMAA_ERRNO_INVALID_JOB,
+						"No job found to be waited for" );
+
+			if( (job = set->find_terminated( set )) != NULL )
+				break;
+
+			if( self->destroy_requested )
+				fsd_exc_raise_code( FSD_DRMAA_ERRNO_NO_ACTIVE_SESSION );
+			if( self->enable_wait_thread )
+			 {
+				fsd_log_debug(( "wait_for_any_job: waiting for wait thread" ));
+				if( timeout )
+					signaled = fsd_cond_timedwait(
+							&self->wait_condition, &self->mutex, timeout );
+				else
+					fsd_cond_wait( &self->wait_condition, &self->mutex );
+			 }
+			else
+			 {
+				fsd_log_debug(( "wait_for_any_job: waiting for next check" ));
+				self->wait_for_job_status_change( self,
+						&self->wait_condition, &self->mutex, timeout );
+			 }
+			locked = fsd_mutex_unlock( &self->mutex );
+			fsd_log_debug((
+						"wait_for_any_job: woken up; signaled=%d", signaled ));
+
+			if( !signaled )
+				fsd_exc_raise_code( FSD_DRMAA_ERRNO_EXIT_TIMEOUT );
+
+		 }
+		fsd_log_debug(( "wait_for_any_job: waiting finished" ));
+
+		job_id = fsd_strdup( job->job_id );
+		job->get_termination_status( job, status, rusage );
+	 }
+	EXCEPT_DEFAULT
+	 {
+		if( job_id )
+			fsd_free( job_id );
+		fsd_exc_reraise();
+	 }
+	FINALLY
+	 {
+		if( job )
+		 {
+			if( fsd_exc_get() == NULL  &&  dispose )
+			 {
+				set->remove( set, job );
+				job->flags |= FSD_JOB_DISPOSED;
+			 }
+			job->release( job );
+		 }
+		if( locked )
+			fsd_mutex_unlock( &self->mutex );
+	 }
+	END_TRY
+
+	fsd_log_return(( " =%s", job_id ));
+	return job_id;
+}
+
+
+void
+fsd_drmaa_session_wait_for_job_status_change(
+		fsd_drmaa_session_t *self,
+		fsd_cond_t *wait_condition,
+		fsd_mutex_t *mutex,
+		const struct timespec *timeout
+		)
+{
+	struct timespec ts, *next_check = &ts;
+	bool status_changed;
+
+	if( timeout )
+		fsd_log_enter((
+					"(timeout=%ld.%09ld)",
+					timeout->tv_sec, timeout->tv_nsec ));
+	else
+		fsd_log_enter(( "(timeout=(null))" ));
+	fsd_get_time( next_check );
+	fsd_ts_add( next_check, &self->pool_delay );
+	if( timeout  &&  fsd_ts_cmp( timeout, next_check ) < 0 )
+		next_check = (struct timespec*)timeout;
+	fsd_log_debug(( "wait_for_job_status_change: waiting untill %ld.%09ld",
+				next_check->tv_sec, next_check->tv_nsec ));
+	status_changed = fsd_cond_timedwait(wait_condition, mutex,(const struct timespec *) next_check );
+	if( !status_changed  &&  next_check == timeout )
+		fsd_exc_raise_code( FSD_DRMAA_ERRNO_EXIT_TIMEOUT );
+
+	fsd_log_return(( ": next_check=%ld.%09ld, status_changed=%d",
+				next_check->tv_sec, next_check->tv_nsec,
+				(int)status_changed
+				));
+}
+
+
+void *
+fsd_drmaa_session_wait_thread( fsd_drmaa_session_t *self )
+{
+	struct timespec ts, *next_check = &ts;
+	bool volatile locked = false;
+
+	fsd_log_enter(( "" ));
+	locked = fsd_mutex_lock( &self->mutex );
+	TRY
+	 {
+		while( self->wait_thread_run_flag )
+			TRY
+			 {
+				fsd_log_debug(( "wait thread: next iteration" ));
+				self->update_all_jobs_status( self );
+				fsd_cond_broadcast( &self->wait_condition );
+				
+				fsd_get_time( next_check );
+				fsd_ts_add( next_check, &self->pool_delay );
+				fsd_cond_timedwait( &self->wait_condition, &self->mutex, (const struct timespec *) next_check );
+				
+			 }
+			EXCEPT_DEFAULT
+			 {
+				const fsd_exc_t *e = fsd_exc_get();
+				fsd_log_error(( "wait thread: <%d:%s>", e->code(e), e->message(e) ));
+			 }
+			END_TRY
+	 }
+	FINALLY
+	 { 
+		if (locked)
+			fsd_mutex_unlock( &self->mutex ); 
+	 }
+	END_TRY
+
+	fsd_log_return(( " =NULL" ));
+	return NULL;
+}
+
+
+void
+fsd_drmaa_session_stop_wait_thread( fsd_drmaa_session_t *self )
+{
+	volatile int lock_count = 0;
+	fsd_log_enter(( "" ));
+	fsd_mutex_lock( &self->mutex );
+	TRY
+	 {
+		fsd_log_debug(("started = %d  run_flag = %d", self->wait_thread_started, self->wait_thread_run_flag ));
+		if( self->wait_thread_started )
+		 {
+			self->wait_thread_run_flag = false;
+			fsd_log_debug(("started = %d  run_flag = %d", self->wait_thread_started, self->wait_thread_run_flag ));
+			fsd_cond_broadcast( &self->wait_condition );
+			TRY
+			 {
+				lock_count = fsd_mutex_unlock_times( &self->mutex );
+				fsd_thread_join( self->wait_thread_handle, NULL );
+			 }
+			FINALLY
+			 {
+				int i;
+				for( i = 0;  i < lock_count;  i++ )
+					fsd_mutex_lock( &self->mutex );
+			 }
+			END_TRY
+			self->wait_thread_started = false;
+		 }
+
+	 }
+	FINALLY
+	 { fsd_mutex_unlock( &self->mutex ); }
+	END_TRY
+	fsd_log_return(( "" ));
+}
+
+
+void
+fsd_drmaa_session_update_all_jobs_status(
+		fsd_drmaa_session_t *self )
+{
+	char **volatile job_ids = NULL;
+	fsd_log_enter(( "" ));
+	TRY
+	 {
+		const char **i;
+		fsd_job_t *volatile job = NULL;
+		job_ids = self->get_submited_job_ids( self );
+		for( i = (const char **)job_ids;  *i;  i++ )
+			TRY
+			 {
+				job = self->get_job( self, *i );
+				if( job )
+					job->update_status( job );
+			 }
+			FINALLY
+			 {
+				if( job )
+					job->release( job );
+			 }
+			END_TRY
+	 }
+	FINALLY
+	 {
+		fsd_free_vector( job_ids );
+	 }
+	END_TRY
+	fsd_log_return(( "" ));
+}
+
+
+char **
+fsd_drmaa_session_get_submited_job_ids( fsd_drmaa_session_t *self )
+{
+	return self->jobs->get_all_job_ids( self->jobs );
+}
+
+
+fsd_job_t *
+fsd_drmaa_session_get_job( fsd_drmaa_session_t *self, const char *job_id )
+{
+	return self->jobs->get( self->jobs, job_id );
+}
+
+
+void
+fsd_drmaa_session_load_configuration(
+		fsd_drmaa_session_t *self, const char *basename
+		)
+{
+	char *volatile system_conf = NULL;
+	char *volatile user_conf = NULL;
+	char *volatile varname = NULL;
+	TRY
+	 {
+		const char *home;
+		const char *envvalue;
+		char *i;
+
+		system_conf = fsd_asprintf( DRMAA_DIR_SYSCONF"/%s.conf", basename );
+
+		home = getenv( "HOME" );
+		if( home == NULL )
+		 { home = "."; }
+		user_conf = fsd_asprintf( "%s/.%s.conf", home, basename );
+
+		varname = fsd_asprintf( "%s_CONF", basename );
+		for( i = varname;  *i;  i++ )
+			*i = toupper( *(unsigned char*)i );
+		envvalue = getenv( varname );
+
+		self->configuration = fsd_conf_read(
+			 self->configuration, system_conf, false, NULL, 0 );
+		self->configuration = fsd_conf_read(
+			 self->configuration, user_conf, false, NULL, 0 );
+		if( envvalue )
+			self->configuration = fsd_conf_read(
+				 self->configuration, envvalue, true, NULL, 0 );
+		self->apply_configuration( self );
+	 }
+	FINALLY
+	 {
+		fsd_free( system_conf );
+		fsd_free( user_conf );
+		fsd_free( varname );
+	 }
+	END_TRY
+}
+
+
+void
+fsd_drmaa_session_read_configuration(
+		fsd_drmaa_session_t *self,
+		const char *filename, bool must_exist,
+		const char *configuration, size_t configuration_len
+		)
+{
+	self->configuration = fsd_conf_read(
+		 self->configuration,
+		 filename, must_exist,
+		 configuration, configuration_len );
+	self->apply_configuration( self );
+}
+
+
+void
+fsd_drmaa_session_apply_configuration( fsd_drmaa_session_t *self )
+{
+	fsd_conf_option_t *pool_delay = NULL;
+	fsd_conf_option_t *cache_job_state = NULL;
+	fsd_conf_option_t *wait_thread = NULL;
+	fsd_conf_option_t *job_categories = NULL;
+	fsd_conf_option_t *missing_jobs = NULL;
+
+	fsd_log_enter((""));
+	if( self->configuration  !=  NULL ) {
+
+		pool_delay = fsd_conf_dict_get(
+				self->configuration, "pool_delay" );
+		cache_job_state = fsd_conf_dict_get(
+				self->configuration, "cache_job_state" );
+		wait_thread = fsd_conf_dict_get(
+				self->configuration, "wait_thread" );
+		job_categories = fsd_conf_dict_get(
+				self->configuration, "job_categories" );
+		missing_jobs = fsd_conf_dict_get(
+				self->configuration, "missing_jobs" );
+	}
+
+	if( pool_delay )
+	 {
+		if( pool_delay->type == FSD_CONF_INTEGER
+				&&  pool_delay->val.integer > 0 )
+		 {
+			fsd_log_debug(("pool_delay=%d", pool_delay->val.integer));
+			self->pool_delay.tv_sec = pool_delay->val.integer;
+		 }
+		else
+			fsd_exc_raise_msg(
+					FSD_ERRNO_INTERNAL_ERROR,
+					"configuration: 'pool_delay' must be positive integer"
+					);
+	 }
+	if( cache_job_state )
+	 {
+		if( cache_job_state->type == FSD_CONF_INTEGER
+				&&   cache_job_state->val.integer >= 0 )
+		 {
+			fsd_log_debug(("cache_job_state=%d", cache_job_state->val.integer));
+			self->cache_job_state = cache_job_state->val.integer;
+		 }
+		else
+			fsd_exc_raise_msg(
+					FSD_ERRNO_INTERNAL_ERROR,
+					"configuration: 'cache_job_state' must be nonnegative integer"
+					);
+	 }
+	if( wait_thread )
+	 {
+		if( wait_thread->type == FSD_CONF_INTEGER )
+		 {
+
+			fsd_log_info(("wait_thread=%d", wait_thread->val.integer));
+			self->enable_wait_thread = (wait_thread->val.integer != 0 );
+		 }
+		else
+			fsd_exc_raise_msg(
+					FSD_ERRNO_INTERNAL_ERROR,
+					"configuration: 'wait_thread' should be 0 or 1"
+					);
+	 }
+	if( job_categories )
+	 {
+		if( job_categories->type == FSD_CONF_DICT )
+			self->job_categories = job_categories->val.dict;
+		else
+			fsd_exc_raise_msg(
+					FSD_ERRNO_INTERNAL_ERROR,
+					"configuration: 'job_categories' should be dictionary"
+					);
+	 }
+	if( missing_jobs )
+	 {
+		bool ok = true;
+		if( missing_jobs->type != FSD_CONF_STRING )
+		 {
+			const char *value = missing_jobs->val.string;
+			if( !strcmp( value, "ignore" ) )
+				self->missing_jobs = FSD_IGNORE_MISSING_JOBS;
+			else if( !strcmp( value, "ignore-queued" ) )
+				self->missing_jobs = FSD_IGNORE_QUEUED_MISSING_JOBS;
+			else if( !strcmp( value, "reveal" ) )
+				self->missing_jobs = FSD_REVEAL_MISSING_JOBS;
+			else
+				ok = false;
+		 }
+		else
+			ok = false;
+
+		if( !ok )
+			fsd_exc_raise_msg(
+					FSD_ERRNO_INTERNAL_ERROR,
+					"configuration: 'missing_jobs' should be one of: "
+					"'ignore', 'ignore-queued' or 'reveal'"
+					);
+	 }
+
+	if( self->enable_wait_thread  &&  !self->wait_thread_started )
+	 {
+		fsd_log_debug(("Starting wait thread"));
+		self->wait_thread_run_flag = true;
+		fsd_thread_create( &self->wait_thread_handle,
+				(void*(*)(void*))self->wait_thread, self );
+		self->wait_thread_started = true;
+		fsd_log_debug(( "wait thread started" ));
+	 }
+	else if( !self->enable_wait_thread  &&  self->wait_thread_started )
+	 {
+		fsd_log_debug(("Stopping wait thread"));
+		self->stop_wait_thread( self );
+	 }
+
+	fsd_log_return((""));
+}
+
+#endif
+
Index: branches/2.0/pbs_drmaa/drmaa.c
===================================================================
--- branches/2.0/pbs_drmaa/drmaa.c	(revision 12)
+++ branches/2.0/pbs_drmaa/drmaa.c	(revision 81)
@@ -1,6 +1,6 @@
 /* $Id$ */
 /*
- *  FedStage DRMAA for PBS Pro
- *  Copyright (C) 2006-2007  FedStage Systems
+ *  PSNC DRMAA 2.0 for Torque/PBS Pro
+ *  Copyright (C) 2012  Poznan Supercomputing and Networking Center
  *
  *  This program is free software: you can redistribute it and/or modify
@@ -22,14 +22,9 @@
 #endif
 
-#include <signal.h>
 #include <drmaa_utils/drmaa_base.h>
-#include <drmaa_utils/session.h>
-#include <drmaa_utils/template.h>
-#include <drmaa_utils/drmaa_attrib.h>
-#include <drmaa_utils/iter.h>
-#include <drmaa_utils/logging.h>
-#include <pbs_drmaa/session.h>
-
-
+
+
+
+#if 0
 static fsd_drmaa_session_t *
 pbsdrmaa_new_session( fsd_drmaa_singletone_t *self, const char *contact )
@@ -225,2 +220,3 @@
 };
 
+#endif
Index: branches/2.0/pbs_drmaa/Makefile.am
===================================================================
--- branches/2.0/pbs_drmaa/Makefile.am	(revision 12)
+++ branches/2.0/pbs_drmaa/Makefile.am	(revision 81)
@@ -1,6 +1,6 @@
 # $Id$
 # 
-# FedStage DRMAA for PBS Professional
-# Copyright (C) 2006-2009  FedStage Systems
+# DRMAA for Torque/PBS Professional
+# Copyright (C) 2012  Poznan Supercomputing and Networking Center
 #
 # This program is free software: you can redistribute it and/or modify
@@ -20,20 +20,20 @@
 GPERF       = @GPERF@
 GPERFFLAGS  = --readonly-tables
-AM_CPPFLAGS = @PBS_INCLUDES@ -I$(top_srcdir)/drmaa_utils -fPIC
+AM_CPPFLAGS = @PBS_INCLUDES@ -I$(top_srcdir)/drmaa2_utils -fPIC
 
 lib_LTLIBRARIES = libdrmaa.la
 
 libdrmaa_la_SOURCES = \
- drmaa.c \
- job.c job.h \
- pbs_attrib.gperf pbs_attrib.h \
- session.c session.h \
- submit.c submit.h \
- util.c util.h \
- log_reader.c log_reader.h 
+ drmaa.c 
+# job.c job.h \
+# pbs_attrib.gperf pbs_attrib.h \
+# session.c session.h \
+# submit.c submit.h \
+# util.c util.h \
+# log_reader.c log_reader.h 
 BUILT_SOURCES       = pbs_attrib.c
 EXTRA_DIST          = pbs_attrib.c
 dist_sysconf_DATA   = pbs_drmaa.conf.example
-libdrmaa_la_LIBADD  = ../drmaa_utils/drmaa_utils/libdrmaa_utils.la @PBS_LIBS@
+libdrmaa_la_LIBADD  = ../drmaa2_utils/drmaa_utils/libdrmaa_utils.la @PBS_LIBS@
 libdrmaa_la_LDFLAGS = @PBS_LDFLAGS@ -version-info @PBS_DRMAA_VERSION_INFO@
 
Index: branches/2.0/.svnignore
===================================================================
--- branches/2.0/.svnignore	(revision 12)
+++ branches/2.0/.svnignore	(revision 81)
@@ -33,2 +33,11 @@
 readme.aux
 readme.log
+libtool.m4
+lt~obsolete.m4
+ltsugar.m4
+ltversion.m4
+ltoptions.m4
+.project
+.cproject
+drmaa_example1
+drmaa_example2
Index: branches/2.0/configure.ac
===================================================================
--- branches/2.0/configure.ac	(revision 77)
+++ branches/2.0/configure.ac	(revision 81)
@@ -58,7 +58,4 @@
 fi
 
-if test x$GCC = xyes; then
-	CFLAGS="-pedantic -ansi ${CFLAGS}"
-fi
 AM_CONDITIONAL([GCC], [test x$GCC = xyes])
 
@@ -168,4 +165,5 @@
 	Makefile
 	pbs_drmaa/Makefile
+  drmaa2_testsuite/Makefile
 ])
 AC_CONFIG_HEADERS([config.h])
Index: branches/2.0/Makefile.am
===================================================================
--- branches/2.0/Makefile.am	(revision 77)
+++ branches/2.0/Makefile.am	(revision 81)
@@ -1,6 +1,6 @@
 # $Id$
 #
-# FedStage DRMAA for PBS Pro
-# Copyright (C) 2006-2009  FedStage Systems
+# DRMAA for Torque/PBS Professional
+# Copyright (C) 2012  Poznan Supercomputing and Networking Center
 #
 # This program is free software: you can redistribute it and/or modify
@@ -24,3 +24,3 @@
  m4/missing-dev-prog.sh
 
-SUBDIRS = drmaa2_utils pbs_drmaa
+SUBDIRS = drmaa2_utils drmaa2_testsuite pbs_drmaa
