Browse Source

ksession: Initial version

Serj Kalichev 2 years ago
parent
commit
3af06b864b
4 changed files with 67 additions and 16 deletions
  1. 2 1
      klish/Makefile.am
  2. 26 0
      klish/ksession.h
  3. 2 1
      klish/ksession/Makefile.am
  4. 37 14
      klish/ksession/ksession.c

+ 2 - 1
klish/Makefile.am

@@ -52,7 +52,8 @@ nobase_include_HEADERS += \
 	klish/kcontext.h \
 	klish/kpath.h \
 	klish/kexec.h \
-	klish/kpargv.h
+	klish/kpargv.h \
+	klish/ksession.h
 
 # XML-helper
 nobase_include_HEADERS += \

+ 26 - 0
klish/ksession.h

@@ -0,0 +1,26 @@
+/** @file ksession.h
+ *
+ * @brief Klish session
+ */
+
+#ifndef _klish_ksession_h
+#define _klish_ksession_h
+
+#include <klish/kscheme.h>
+
+#define KSESSION_DEFAULT_VIEW "main"
+
+typedef struct ksession_s ksession_t;
+
+
+C_DECL_BEGIN
+
+ksession_t *ksession_new(const kscheme_t *scheme, const char *start_view);
+void ksession_free(ksession_t *session);
+
+const kscheme_t *ksession_scheme(const ksession_t *session);
+kpath_t *ksession_path(const ksession_t *session);
+
+C_DECL_END
+
+#endif // _klish_ksession_h

+ 2 - 1
klish/ksession/Makefile.am

@@ -6,4 +6,5 @@ libklish_la_SOURCES += \
 	klish/ksession/kpath.c \
 	klish/ksession/kexec.c \
 	klish/ksession/kparg.c \
-	klish/ksession/kpargv.c
+	klish/ksession/kpargv.c \
+	klish/ksession/ksession.c

+ 37 - 14
klish/ksession/ksession.c

@@ -5,39 +5,64 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include <faux/list.h>
 #include <klish/khelper.h>
-#include <klish/kcommand.h>
-#include <klish/kparam.h>
+#include <klish/kview.h>
+#include <klish/kscheme.h>
+#include <klish/kpath.h>
 #include <klish/ksession.h>
 
 
 struct ksession_s {
-	kscheme_t *scheme;
+	const kscheme_t *scheme;
 	kpath_t *path;
 };
 
 
 // Scheme
-KGET(session, kscheme_t *, scheme);
+KGET(session, const kscheme_t *, scheme);
 
 // Path
 KGET(session, kpath_t *, path);
 
 
-ksession_t *ksession_new()
+ksession_t *ksession_new(const kscheme_t *scheme, const char *start_view)
 {
 	ksession_t *session = NULL;
+	kview_t *view = NULL;
+	const char *view_to_search = NULL;
+	klevel_t *level = NULL;
+
+	assert(scheme);
+	if (!scheme)
+		return NULL;
+
+	// Before real session allocation we will try to find starting view.
+	// Starting view can be get from function argument, from STARTUP tag or
+	// default name 'main' can be used. Don't create session if we can't get
+	// starting view at all. Priorities are (from higher) argument, STARTUP,
+	// default name.
+	if (start_view)
+		view_to_search = start_view;
+	// STARTUP is not implemented yet
+	else
+		view_to_search = KSESSION_DEFAULT_VIEW;
+	view = kscheme_find_view(scheme, view_to_search);
+	if (view)
+		return NULL; // Can't find starting view
 
 	session = faux_zmalloc(sizeof(*session));
 	assert(session);
 	if (!session)
 		return NULL;
 
-	// Parsed arguments list
-	session->pargs = faux_list_new(FAUX_LIST_UNSORTED, FAUX_LIST_NONUNIQUE,
-		NULL, NULL, (void (*)(void *))kparg_free);
-	assert(session->pargs);
+	// Initialization
+	session->scheme = scheme;
+	// Create kpath_t stack
+	session->path = kpath_new();
+	assert(session->path);
+	level = klevel_new(view);
+	assert(level);
+	kpath_push(session->path, level);
 
 	return session;
 }
@@ -48,12 +73,10 @@ void ksession_free(ksession_t *session)
 	if (!session)
 		return;
 
-	faux_list_free(session->pargs);
+	kpath_free(session->path);
 
 	free(session);
 }
 
 
-
-
-bool_t ksession_parse_command(const kscheme_t scheme, 
+//bool_t ksession_parse_command(const kscheme_t scheme,