Index: logic/trunk/src/init/buf.h
===================================================================
--- logic/trunk/src/init/buf.h	(revision 0)
+++ logic/trunk/src/init/buf.h	(revision 20)
@@ -0,0 +1,29 @@
+#ifndef BUF_H_INCLUDED
+#define BUF_H_INCLUDED
+
+typedef int element_t;
+
+//int *buf;
+
+typedef struct d_buffer
+{
+    // buffer pointers
+    int *start_p;
+    int *end_p;
+    // TODO (fix and remove this one?) pointer to the first element, had problems with malloc without it!
+    int *start_el;
+    // actual buffer
+    element_t *elements;
+    // attributes
+    int buffer_size;
+    int buffer_load;
+}d_bufr;
+
+void buf_put(element_t element, d_bufr *buf);
+int  buf_get(element_t *element, d_bufr *buf);
+void increase_start_p(d_bufr *buf);
+int  increase_end_p(d_bufr *buf);
+d_bufr *init_buf(int buf_size);
+int  get_buffer_load(d_bufr *buf);
+
+#endif // BUF_H_INCLUDED
Index: logic/trunk/src/init/scenarios.xml
===================================================================
--- logic/trunk/src/init/scenarios.xml	(revision 0)
+++ logic/trunk/src/init/scenarios.xml	(revision 20)
@@ -0,0 +1,26 @@
+<?xml version="1.0"?>
+<scenariotree>
+    <scenario id="ac_01">
+        <name nam="Air Conditioner"/>
+        <minvalue minval="18"/>
+        <maxvalue maxval="27"/>
+	<optimal_value optVal="23"/>
+	<idle_check_interval ici="600"/>
+	<active_check_interval aci="600"/>
+	<sensors chk_dev1="thermometer_01" chk_dev2="thermometer_01"/>
+	...
+	<reaction_function fr="linear"/>
+        <action act="testAction_1"/>
+        <param par="testParam_1"/>
+    </scenario>
+</scenariotree>
+
+name
+action path
+param
+idle check interval (s)
+active check interval (s)
+influence devices
+reaction values //treba razdelat
+function type //static (on - off), linear, log etc. (kako se spreminja moč na intervalu)
+
Index: logic/trunk/src/init/buf.c
===================================================================
--- logic/trunk/src/init/buf.c	(revision 0)
+++ logic/trunk/src/init/buf.c	(revision 20)
@@ -0,0 +1,120 @@
+#include "buf.h"
+#include <stdlib.h>
+
+d_bufr *init_buf(int buf_size)
+{
+    printf("-----------------\n");
+    printf("Creating buffer; size %d!\n", buf_size);
+
+    d_bufr *buf;
+    buf = (d_bufr *)malloc(sizeof(d_bufr));
+    //*
+    buf->buffer_size = buf_size;
+    // TODO should allocate (element_t *) type instead of (int *)?
+    // malloc(BUFFER_SIZE * sizeof (element_t));
+    buf->elements = malloc(buf_size * sizeof (element_t));
+
+    buf->start_p = &buf->elements;
+    buf->start_el= &buf->elements;
+    //buf->end_p = buf->start_p+buf->buffer_size-1;
+    buf->end_p   = &buf->elements;
+    buf->buffer_load = 0;
+
+    /*
+    // TODO just a bunch of tests for deletion
+    //printf("buf addr: %d\n", buf);
+    printf("buf start_p: %d\n", buf->start_p);
+    //printf("buf &start_p: %d\n", &buf->start_p);
+    //printf("buf *start_p: %d\n", *buf->start_p);
+    printf("buf end_p: %d\n", buf->end_p);
+    //printf("buf elements: %d\n", buf->elements);
+    printf("buf &elements: %d\n", &buf->elements);
+    //printf("buf size: %d\n", buf->buffer_size);
+    //printf("buf load %d\n", buf->buffer_load);
+
+    // TODO possilbe bug in buffer allocation! following sums should be the same
+    // buf start_p + buffer_size - buf start_p should be 4 * buffer_size
+    // in first case it is, but in second it is 2 times bigger!
+    printf("buf start_p+buffer_size: %d\n", buf->start_p+buf_size);
+    printf("&buf->elements+buf->buffer_size: %d\n", &buf->elements+buf->buffer_size);
+    printf("sizeof(buf->elements) %d\n", sizeof(buf->elements));
+    printf("sizeof(element_t) %d\n", sizeof(element_t));
+    /**/
+    return buf;
+}
+
+void increase_start_p(d_bufr *buf)
+{
+    /*
+    printf("pre buf->start_p \t%d\n",buf->start_p);
+    printf("pre buf->end_p \t\t%d\n",buf->end_p);
+    printf("limit address \t\t%d\n", buf->start_el + buf->buffer_size);
+    printf("-\n");
+    /**/
+    if((buf->start_p+1)!=(buf->start_el + buf->buffer_size)) // no loop
+    {
+        //pomakni se endp ce je isti naslov kot startp
+        //printf("no loop\n");
+        if((buf->start_p+1)==(buf->end_p))
+        {
+            //printf("lol fail\n");
+            increase_end_p(buf);
+        }
+        else
+        {
+            //printf("ok zakon\n");
+            buf->buffer_load++;
+        }
+        buf->start_p++;
+    }
+    else //loop
+    {
+        if(buf->end_p==buf->start_el)
+            increase_end_p(buf);
+        else
+            buf->buffer_load++;
+        buf->start_p = buf->start_el;
+    }
+    //printf("after buf->start_p \t%d\n",buf->start_p);
+}
+
+int increase_end_p(d_bufr *buf)
+{
+    //printf("pre buf->end_p \t\t%d\n",buf->end_p);
+    if((buf->end_p+1)!=(buf->start_el + buf->buffer_size)) // no loop
+    {
+        if((buf->end_p+1)==(buf->start_p)) //buffer empty
+            return 0;
+        buf->end_p++;
+    }
+    else //loop
+    {
+        if(buf->start_p==buf->elements) //buffer empty
+            return 0;
+        buf->end_p = buf->elements;
+    }
+    //printf("after buf->end_p \t%d\n",buf->end_p);
+    return 1;
+}
+
+void buf_put(element_t element, d_bufr *buf)
+{
+    *buf->start_p = element;
+    increase_start_p(buf);
+}
+
+int buf_get(element_t *element, d_bufr *buf)
+{
+    *element = *buf->end_p;
+    if(increase_end_p(buf)==1){
+        buf->buffer_load--;
+        return 1;
+    }
+    else //error
+        return 0;
+}
+
+int get_buffer_load(d_bufr *buf)
+{
+    return buf->buffer_load;
+}
