Permalink
Browse files

fiuteksy do widgetow

  • Loading branch information...
1 parent 24c3bd8 commit 0b6f6fd590563be82e369215938507d3a85a1497 gladky committed Jun 6, 2012
Showing with 36 additions and 5 deletions.
  1. +17 −2 Skunk.hpp
  2. +19 −3 skunk_test.cpp
View
@@ -3,6 +3,7 @@
#include <string>
#include <vector>
#include <map>
+#include <pthread.h>
#include "csgi.hpp"
@@ -32,7 +33,14 @@ namespace Skunk {
struct Widget {
virtual std::string GET() = 0;
virtual void POST(std::string&) = 0;
- int id_;
+ int id_, rc;
+ pthread_mutex_t mutex;
+ void blockWidget(pthread_mutex_t mutex){
+ rc = pthread_mutex_lock(&mutex);
+ }
+ void unlockWidget(pthread_mutex_t mutex){
+ rc = pthread_mutex_unlock(&mutex);
+ }
};
@@ -90,6 +98,7 @@ struct TextField : Widget {
virtual std::string GET() {
std::stringstream id_str;
id_str << this->id_;
+ blockWidget(mutex);
std::string html = "";
html.append("<input type='text' name='id");
@@ -107,12 +116,14 @@ struct TextField : Widget {
html.append(id_str.str());
html.append("_changed'");
html.append(" value='false'/>\n");
-
+ unlockWidget(mutex);
return html;
}
virtual void POST(std::string& s) {
+ blockWidget(mutex);
this->setValue(s);
+ unlockWidget(mutex);
}
};
@@ -160,6 +171,7 @@ struct RadioButton : Widget {
std::stringstream i_str;
std::stringstream count;
+ blockWidget(mutex);
count << this->getElemsNum();
id_str << this ->id_;
std::string html = "";
@@ -200,11 +212,14 @@ struct RadioButton : Widget {
html.append("_changed'");
html.append(" value='false'/>\n");
}
+ unlockWidget(mutex);
return html;
}
virtual void POST(std::string& s) {
+ blockWidget(mutex);
this->setValue(atoi(s.c_str()));
+ unlockWidget(mutex);
}
};
View
@@ -59,9 +59,11 @@ class WielkiNapis : public Skunk::Widget {
* */
int main(void) {
Skunk::Server *srv = new Skunk::Server();
+ PoleTekstowe *pt1 = new PoleTekstowe("text1");
+ PoleTekstowe *pt2 = new PoleTekstowe("text2");
srv->addWidget(new WielkiNapis());
- srv->addWidget(new PoleTekstowe("text1"));
- srv->addWidget(new PoleTekstowe("text2"));
+ srv->addWidget(pt1);
+ srv->addWidget(pt2);
PoleRadiowe *pr = new PoleRadiowe();
srv->addWidget(pr);
pr->setTitle("Preferencje");
@@ -75,5 +77,19 @@ int main(void) {
srv->setAuth(auth);
- srv->run(false);
+ printf("running server\n");
+ srv->run(true);
+
+ int i=0;
+ std::string napis = "kurwa";
+ std::string tmp;
+ for(;;){
+ sleep(10);
+ //pt1->blockWidget();
+ std::cout << pt1->getValue() << std::endl;
+ tmp = pt1->getValue() + itoa(i++);
+ pt1->setValue(tmp);
+ //pt1->unlockWidget();
+ //printf("%s: \n",pt1->getValue());
+ }
}

0 comments on commit 0b6f6fd

Please sign in to comment.