taskrambler  0.1.9
Web server and task management solution.
worker.c File Reference
#include <stdarg.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <stdio.h>
#include <search.h>
#include "class.h"
#include "stream.h"
#include "hash.h"
#include "queue.h"
#include "http/worker.h"
#include "http/parser.h"
#include "http/writer.h"
#include "utils/memory.h"
#include "interface/subject.h"
#include "interface/observer.h"
+ Include dependency graph for worker.c:

Go to the source code of this file.

Macros

#define _GNU_SOURCE
 

Functions

static int httpWorkerCtor (void *_this, va_list *params)
 
static void httpWorkerDtor (void *_this)
 
static void httpWorkerClone (void *_this, void *_base)
 
ssize_t httpWorkerProcess (void *, Stream)
 
ssize_t httpWorkerWrite (void *, Stream)
 
static void httpWorkerDetach (void *_this, void *adapter)
 
static void httpWorkerAttach (void *_this, void *adapter)
 
static void httpWorkerNotify (void *_this)
 
 INIT_IFACE (Class, httpWorkerCtor, httpWorkerDtor, httpWorkerClone)
 
 INIT_IFACE (StreamReader, httpWorkerProcess)
 
 INIT_IFACE (StreamWriter, httpWorkerWrite)
 
 INIT_IFACE (Subject, httpWorkerAttach, httpWorkerDetach, httpWorkerNotify)
 
 CREATE_CLASS (HttpWorker, NULL, IFACE(Class), IFACE(StreamReader), IFACE(StreamWriter), IFACE(Subject))
 

Detailed Description

Author
Georg Hopp

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/.

Definition in file worker.c.

Macro Definition Documentation

#define _GNU_SOURCE

Definition at line 23 of file worker.c.

Function Documentation

CREATE_CLASS ( HttpWorker  ,
NULL  ,
IFACE(Class)  ,
IFACE(StreamReader)  ,
IFACE(StreamWriter)  ,
IFACE(Subject)   
)
static void httpWorkerAttach ( void *  _this,
void *  adapter 
)
static

Definition at line 139 of file worker.c.

References httpWorkerDetach().

140 {
141  HttpWorker this = (HttpWorker)_this;
142 
143  /*
144  * right now only one adapter is allowed and the last
145  * added will be used....all others will be deleted in
146  * assumption that no other handle does exist anymore
147  * (because it was added as an adapter and thus is good
148  * for nothing else.)
149  */
150  httpWorkerDetach(_this, adapter);
151 
152  this->application_adapter = adapter;
153 }
static void httpWorkerDetach(void *_this, void *adapter)
Definition: worker.c:128

+ Here is the call graph for this function:

static void httpWorkerClone ( void *  _this,
void *  _base 
)
static

Definition at line 90 of file worker.c.

References asset_pool.

91 {
92  HttpWorker this = _this;
93  HttpWorker base = _base;
94 
95  this->asset_pool = base->asset_pool;
96  this->application_adapter = base->application_adapter;
97 
98  this->additional_headers = new(Queue);
99 
100  this->parser = new(HttpParser, base->pbuf);
101  /*
102  * I am pretty sure that it is not neccessary to have a
103  * separeate writer for each connection...
104  * Right now I leave it that way.
105  * TODO check this.
106  * OK some facts:
107  * - the stream as well as the worker are associated
108  * to the filehandle within the server.
109  * - the response queue is located within the writer.
110  * (this might be wrong...the response queue should
111  * be part of the worker. That way I could give it
112  * into the writer when writing. That way only one
113  * instance of the writer might be possible...)
114  * NO, the previous statement is wrong...this would
115  * involve much more organization overhead within
116  * the writer...queue change and such...
117  * At the end I think it might be best to leave it as
118  * it is.
119  */
120  this->writer = new(HttpWriter);
121 }
Hash asset_pool
Definition: pool.c:32
static int httpWorkerCtor ( void *  _this,
va_list *  params 
)
static

Definition at line 47 of file worker.c.

References asset_pool, memMalloc(), and PARSER_MAX_BUF.

48 {
49  HttpWorker this = _this;
50  char * id = va_arg(*params, char *);
51  char cbuf_id[100];
52 
53  this->id = memMalloc(strlen(id) + 1);
54  strcpy(this->id, id);
55 
56  this->asset_pool = new(Hash);
57 
58  sprintf(cbuf_id, "%s_%s", "parser", id);
59  this->pbuf = new(Cbuf, cbuf_id, PARSER_MAX_BUF);
60 
61  this->additional_headers = new(Queue);
62 
63  this->parser = new(HttpParser, this->pbuf);
64  this->writer = new(HttpWriter);
65 
66  return 0;
67 }
void * memMalloc(size_t)
Definition: memory.c:783
Hash asset_pool
Definition: pool.c:32
#define PARSER_MAX_BUF
Definition: parser.h:35

+ Here is the call graph for this function:

static void httpWorkerDetach ( void *  _this,
void *  adapter 
)
static

Definition at line 128 of file worker.c.

Referenced by httpWorkerAttach().

129 {
130  HttpWorker this = (HttpWorker)_this;
131 
132  if (NULL != this->application_adapter) {
133  delete(this->application_adapter);
134  }
135 }

+ Here is the caller graph for this function:

static void httpWorkerDtor ( void *  _this)
static

< cloned workers have NULL, so delete won't do anything

Definition at line 71 of file worker.c.

References asset_pool, and MEM_FREE.

72 {
73  HttpWorker this = _this;
74 
75  MEM_FREE(this->id);
76 
77  delete(this->additional_headers);
78 
79  delete(this->parser);
80  delete(this->writer);
81 
82  if (NULL != this->pbuf) {
83  delete(this->asset_pool);
84  delete(this->pbuf); //!< cloned workers have NULL, so delete won't do anything
85  }
86 }
#define MEM_FREE(seg)
Definition: memory.h:28
Hash asset_pool
Definition: pool.c:32
static void httpWorkerNotify ( void *  _this)
static

Definition at line 157 of file worker.c.

References observerUpdate().

158 {
159  HttpWorker this = (HttpWorker)_this;
160 
161  observerUpdate(this->application_adapter, _this);
162 }
void observerUpdate(void *, void *)
Definition: observer.c:32

+ Here is the call graph for this function:

ssize_t httpWorkerProcess ( void *  ,
Stream   
)
ssize_t httpWorkerWrite ( void *  ,
Stream   
)
INIT_IFACE ( Class  ,
httpWorkerCtor  ,
httpWorkerDtor  ,
httpWorkerClone   
)
INIT_IFACE ( StreamReader  ,
httpWorkerProcess   
)
INIT_IFACE ( StreamWriter  ,
httpWorkerWrite   
)
INIT_IFACE ( Subject  ,
httpWorkerAttach  ,
httpWorkerDetach  ,
httpWorkerNotify   
)