Skip to content

Commit

Permalink
fiuteksy do widgetow
Browse files Browse the repository at this point in the history
  • Loading branch information
gladky authored and gladky committed Jun 6, 2012
1 parent 24c3bd8 commit 0b6f6fd
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
19 changes: 17 additions & 2 deletions Skunk.hpp
Expand Up @@ -3,6 +3,7 @@
#include <string>
#include <vector>
#include <map>
#include <pthread.h>

#include "csgi.hpp"

Expand Down Expand Up @@ -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);
}
};


Expand Down Expand Up @@ -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");
Expand All @@ -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);
}
};

Expand Down Expand Up @@ -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 = "";
Expand Down Expand Up @@ -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);
}
};

Expand Down
22 changes: 19 additions & 3 deletions skunk_test.cpp
Expand Up @@ -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");
Expand All @@ -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.