#include <http.h>
Inheritance diagram for HttpInvalCache:


Public Member Functions | |
| virtual int | command (int argc, const char *const *argv) |
| void | log (const char *fmt,...) |
| int | id () const |
| virtual void | process_data (int size, AppData *d) |
| virtual AppData * | get_data (int &, AppData *) |
| Process *& | target () |
| virtual void | send_data (int size, AppData *data=0) |
Protected Member Functions | |
| int | add_cnc (HttpApp *client, TcpApp *agt) |
| void | delete_cnc (HttpApp *client) |
| TcpApp * | lookup_cnc (HttpApp *client) |
| void | set_pagepool (ClientPagePool *pp) |
Protected Attributes | |
| Tcl_HashTable * | tpa_ |
| int | id_ |
| ClientPagePool * | pool_ |
| Tcl_Channel | log_ |
| Process * | target_ |
|
||||||||||||
|
Definition at line 69 of file http.cc. References client, and HttpApp::tpa_. Referenced by HttpApp::command().
00070 {
00071 int newEntry = 1;
00072 Tcl_HashEntry *he = Tcl_CreateHashEntry(tpa_,
00073 (const char *)client->id(),
00074 &newEntry);
00075 if (he == NULL)
00076 return -1;
00077 if (newEntry)
00078 Tcl_SetHashValue(he, (ClientData)agt);
00079 return 0;
00080 }
|
|
||||||||||||
|
Reimplemented from Process. Reimplemented in HttpYucInvalServer, HttpMInvalCache, HttpPercInvalCache, MediaCache, MediaClient, and MediaServer. Definition at line 102 of file http.cc. References HttpApp::add_cnc(), client, Scheduler::clock(), HttpApp::delete_cnc(), ClientPagePool::enter_page(), ClientPagePool::exist_page(), ClientPagePool::get_age(), ClientPagePool::get_etime(), ClientPagePool::get_mtime(), ClientPagePool::get_page(), ClientPagePool::get_pageinfo(), ClientPagePool::get_size(), HTML, HttpApp::id_, Scheduler::instance(), ClientPage::is_valid(), HttpApp::log_, HttpApp::lookup_cnc(), MEDIA, MediaPage::num_layer(), HttpApp::pool_, BaseTrace::round(), TcpApp::send(), ClientPagePool::set_etime(), ClientPagePool::set_mtime(), Process::target(), TIME_FORMAT, MediaPage::type(), and ClientPage::type(). Referenced by MediaServer::command(), MediaClient::command(), MediaCache::command(), HttpMInvalCache::command(), and HttpYucInvalServer::command().
00103 {
00104 Tcl& tcl = Tcl::instance();
00105
00106 if (argc == 2) {
00107 if (strcmp(argv[1], "id") == 0) {
00108 if (argc == 3) {
00109 id_ = atoi(argv[2]);
00110 tcl.resultf("%d", id_);
00111 } else
00112 tcl.resultf("%d", id_);
00113 return TCL_OK;
00114 } else if (strcmp(argv[1], "log") == 0) {
00115 // Return the name of the log channel
00116 if (log_ != NULL)
00117 tcl.resultf("%s", Tcl_GetChannelName(log_));
00118 else
00119 tcl.result("");
00120 return TCL_OK;
00121 }
00122 } else if (argc == 3) {
00123 if (strcmp(argv[1], "get-modtime") == 0) {
00124 double mt;
00125 if (pool_->get_mtime(argv[2], mt) != -1) {
00126 tcl.resultf("%.17g", mt);
00127 return TCL_OK;
00128 } else
00129 return TCL_ERROR;
00130 } else if (strcmp(argv[1], "exist-page") == 0) {
00131 tcl.resultf("%d", pool_->exist_page(argv[2]));
00132 return TCL_OK;
00133 } else if (strcmp(argv[1], "get-size") == 0) {
00134 int size;
00135 if (pool_->get_size(argv[2], size) != -1) {
00136 tcl.resultf("%d", size);
00137 return TCL_OK;
00138 } else
00139 return TCL_ERROR;
00140 } else if (strcmp(argv[1], "get-age") == 0) {
00141 double age;
00142 if (pool_->get_age(argv[2], age) != -1) {
00143 tcl.resultf("%.17g", age);
00144 return TCL_OK;
00145 } else
00146 return TCL_ERROR;
00147 } else if (strcmp(argv[1], "get-cachetime") == 0) {
00148 double et;
00149 if (pool_->get_etime(argv[2], et) != -1) {
00150 tcl.resultf("%.17g", et);
00151 return TCL_OK;
00152 } else
00153 return TCL_ERROR;
00154 } else if (strcmp(argv[1], "get-page") == 0) {
00155 char buf[4096];
00156 if (pool_->get_pageinfo(argv[2], buf) != -1) {
00157 tcl.resultf("%s", buf);
00158 return TCL_OK;
00159 } else
00160 return TCL_ERROR;
00161 } else if (strcmp(argv[1], "get-cnc") == 0) {
00162 /*
00163 * <http> get-cnc <client>
00164 *
00165 * Given the communication party, get the tcp agent
00166 * connected to it.
00167 */
00168 HttpApp *client =
00169 (HttpApp *)TclObject::lookup(argv[2]);
00170 TcpApp *cnc = (TcpApp *)lookup_cnc(client);
00171 if (cnc == NULL)
00172 tcl.result("");
00173 else
00174 tcl.resultf("%s", cnc->name());
00175 return TCL_OK;
00176
00177 } else if (strcmp(argv[1], "set-pagepool") == 0) {
00178 pool_ = (ClientPagePool*)TclObject::lookup(argv[2]);
00179 if (pool_ != NULL)
00180 return TCL_OK;
00181 else
00182 return TCL_ERROR;
00183 } else if (strcmp(argv[1], "is-connected") == 0) {
00184 /*
00185 * <http> is-connected <server>
00186 */
00187 HttpApp *a = (HttpApp*)TclObject::lookup(argv[2]);
00188 TcpApp *cnc = (TcpApp*)lookup_cnc(a);
00189 if (cnc == NULL)
00190 tcl.result("0");
00191 else
00192 tcl.result("1");
00193 return TCL_OK;
00194 } else if (strcmp(argv[1], "is-valid") == 0) {
00195 ClientPage *pg =
00196 (ClientPage *)pool_->get_page(argv[2]);
00197 if (pg == NULL) {
00198 tcl.resultf("%d is-valid: No page %s",
00199 id_, argv[2]);
00200 return TCL_ERROR;
00201 }
00202 tcl.resultf("%d", pg->is_valid());
00203 return TCL_OK;
00204 } else if (strcmp(argv[1], "log") == 0) {
00205 int mode;
00206 log_ = Tcl_GetChannel(tcl.interp(),
00207 (char*)argv[2], &mode);
00208 if (log_ == 0) {
00209 tcl.resultf("%d: invalid log file handle %s\n",
00210 id_, argv[2]);
00211 return TCL_ERROR;
00212 }
00213 return TCL_OK;
00214 } else if (strcmp(argv[1], "disconnect") == 0) {
00215 /*
00216 * <http> disconnect <client>
00217 * Delete the association of source and sink TCP.
00218 */
00219 HttpApp *client =
00220 (HttpApp *)TclObject::lookup(argv[2]);
00221 delete_cnc(client);
00222 return TCL_OK;
00223 } else if (strcmp(argv[1], "get-pagetype") == 0) {
00224 /*
00225 * <http> get-pagetype <pageid>
00226 * return the page type
00227 */
00228 ClientPage *pg =
00229 (ClientPage*)pool_->get_page(argv[2]);
00230 if (pg == NULL) {
00231 tcl.resultf("%d get-pagetype: No page %s",
00232 id_, argv[2]);
00233 return TCL_ERROR;
00234 }
00235 switch (pg->type()) {
00236 case HTML:
00237 tcl.result("HTML");
00238 break;
00239 case MEDIA:
00240 tcl.result("MEDIA");
00241 break;
00242 default:
00243 fprintf(stderr, "Unknown page type %d",
00244 pg->type());
00245 return TCL_ERROR;
00246 }
00247 return TCL_OK;
00248 } else if (strcmp(argv[1], "get-layer") == 0) {
00249 // Assume the page is a MediaPage
00250 MediaPage *pg = (MediaPage *)pool_->get_page(argv[2]);
00251 if (pg == NULL) {
00252 tcl.resultf("%d get-layer: No page %s",
00253 id_, argv[2]);
00254 return TCL_ERROR;
00255 }
00256 if (pg->type() != MEDIA) {
00257 tcl.resultf("%d get-layer %s not a media page",
00258 id_, argv[2]);
00259 return TCL_ERROR;
00260 }
00261 tcl.resultf("%d", pg->num_layer());
00262 return TCL_OK;
00263 }
00264 } else if (argc == 4) {
00265 if (strcmp(argv[1], "connect") == 0) {
00266 /*
00267 * <http> connect <client> <ts>
00268 *
00269 * Associate a TCP agent with the given client.
00270 * <ts> is the agent used to send packets out.
00271 * We assume two-way TCP connection, therefore we
00272 * only need one agent.
00273 */
00274 HttpApp *client =
00275 (HttpApp *)TclObject::lookup(argv[2]);
00276 TcpApp *cnc = (TcpApp *)TclObject::lookup(argv[3]);
00277 if (add_cnc(client, cnc)) {
00278 tcl.resultf("%s: failed to connect to %s",
00279 name_, argv[2]);
00280 return TCL_ERROR;
00281 }
00282 // Set data delivery target
00283 cnc->target() = (Process*)this;
00284 return TCL_OK;
00285 } else if (strcmp(argv[1], "set-modtime") == 0) {
00286 double mt = strtod(argv[3], NULL);
00287 if (pool_->set_mtime(argv[2], mt) != -1)
00288 return TCL_OK;
00289 else
00290 return TCL_ERROR;
00291 } else if (strcmp(argv[1], "set-cachetime") == 0) {
00292 double et = Scheduler::instance().clock();
00293 if (pool_->set_etime(argv[2], et) != -1)
00294 return TCL_OK;
00295 else
00296 return TCL_ERROR;
00297 }
00298 } else {
00299 if (strcmp(argv[1], "send") == 0) {
00300 /*
00301 * <http> send <client> <bytes> <callback>
00302 */
00303 HttpApp *client =
00304 (HttpApp *)TclObject::lookup(argv[2]);
00305 if (client == NULL) {
00306 tcl.add_errorf("%s: bad client name %s",
00307 name_, argv[2]);
00308 return TCL_ERROR;
00309 }
00310 int bytes = atoi(argv[3]);
00311 TcpApp *cnc = (TcpApp *)lookup_cnc(client);
00312 if (cnc == NULL) {
00313 //tcl.resultf("%s: no connection to client %s",
00314 // name_, argv[2]);
00315 // Tolerate it
00316 return TCL_OK;
00317 }
00318 char *buf = strdup(argv[4]);
00319 HttpNormalData *d =
00320 new HttpNormalData(id_, bytes, buf);
00321 cnc->send(bytes, d);
00322 // delete d;
00323 free(buf);
00324 return TCL_OK;
00325
00326 } else if (strcmp(argv[1], "enter-page") == 0) {
00327 ClientPage* pg = pool_->enter_page(argc, argv);
00328 if (pg == NULL)
00329 return TCL_ERROR;
00330 else
00331 return TCL_OK;
00332
00333 } else if (strcmp(argv[1], "evTrace") == 0) {
00334 char buf[1024], *p;
00335 if (log_ != 0) {
00336 sprintf(buf, TIME_FORMAT" i %d ",
00337 BaseTrace::round(Scheduler::instance().clock()),
00338 id_);
00339 p = &(buf[strlen(buf)]);
00340 for (int i = 2; i < argc; i++) {
00341 strcpy(p, argv[i]);
00342 p += strlen(argv[i]);
00343 *(p++) = ' ';
00344 }
00345 // Stick in a newline.
00346 *(p++) = '\n', *p = 0;
00347 Tcl_Write(log_, buf, p-buf);
00348 }
00349 return TCL_OK;
00350 }
00351 }
00352
00353 return TclObject::command(argc, argv);
00354 }
|
Here is the call graph for this function:

|
|
Definition at line 82 of file http.cc. References client, and HttpApp::tpa_. Referenced by HttpApp::command().
|
|
||||||||||||
|
Reimplemented from Process. Reimplemented in MediaCache, and MediaServer. Definition at line 47 of file http.h. References abort(). Referenced by MediaCache::get_data().
00047 {
00048 // Do not support it
00049 abort();
00050 return NULL;
00051 }
|
Here is the call graph for this function:

|
|
Definition at line 44 of file http.h. References HttpApp::id_. Referenced by HttpMInvalCache::add_cache(), HttpMInvalCache::add_nbr(), HttpMInvalCache::command(), MediaServer::get_piq(), ClientPagePool::invalidate_server(), and HttpMInvalCache::process_inv().
00044 { return id_; }
|
|
||||||||||||
|
Definition at line 356 of file http.cc. References HttpApp::id_, Scheduler::instance(), HttpApp::log_, BaseTrace::round(), and TIME_FORMAT. Referenced by MediaClient::command(), MediaCache::command(), HttpMInvalCache::command(), HttpYucInvalServer::command(), MediaClient::process_data(), MediaCache::process_data(), HttpMInvalCache::process_inv(), and HttpMInvalCache::recv_upd().
00357 {
00358 // Don't do anything if we don't have a log file.
00359 if (log_ == 0)
00360 return;
00361
00362 char buf[10240], *p;
00363 sprintf(buf, TIME_FORMAT" i %d ",
00364 BaseTrace::round(Scheduler::instance().clock()), id_);
00365 p = &(buf[strlen(buf)]);
00366 va_list ap;
00367 va_start(ap, fmt);
00368 vsprintf(p, fmt, ap);
00369 Tcl_Write(log_, buf, strlen(buf));
00370 }
|
Here is the call graph for this function:

|
|
Definition at line 92 of file http.cc. References client, and HttpApp::tpa_. Referenced by HttpApp::command().
|
|
||||||||||||
|
Reimplemented from Process. Reimplemented in HttpMInvalCache, MediaCache, and MediaClient. Definition at line 372 of file http.cc. References abort(), HTTP_NORMAL, HttpNormalData::str(), and AppData::type(). Referenced by MediaClient::process_data(), MediaCache::process_data(), and HttpMInvalCache::process_data().
00373 {
00374 if (data == NULL)
00375 return;
00376
00377 switch (data->type()) {
00378 case HTTP_NORMAL: {
00379 HttpNormalData *tmp = (HttpNormalData*)data;
00380 Tcl::instance().eval(tmp->str());
00381 break;
00382 }
00383 default:
00384 fprintf(stderr, "Bad http invalidation data type %d\n",
00385 data->type());
00386 abort();
00387 break;
00388 }
00389 }
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 106 of file ns-process.h. References Process::process_data(), and Process::target_. Referenced by TcpApp::process_data(), and MediaApp::process_data().
00106 {
00107 if (target_)
00108 target_->process_data(size, data);
00109 }
|
Here is the call graph for this function:

|
|
Definition at line 58 of file http.h. References HttpApp::pool_.
00058 { pool_ = pp; }
|
|
|
Definition at line 97 of file ns-process.h. References Process::target_. Referenced by QA::check_availability(), Process::command(), HttpApp::command(), MediaApp::get_data(), QA::output(), and TcpApp::process_data().
00097 { return target_; }
|
|
|
|
Definition at line 63 of file http.h. Referenced by HttpApp::command(), and HttpApp::log(). |
|
|
|
Definition at line 113 of file ns-process.h. Referenced by HttpUInvalAgent::command(), Process::Process(), HttpUInvalAgent::process_data(), Process::send_data(), and Process::target(). |
|
|
Definition at line 60 of file http.h. Referenced by HttpApp::add_cnc(), HttpApp::delete_cnc(), HttpApp::HttpApp(), HttpApp::lookup_cnc(), and HttpApp::~HttpApp(). |
1.3.3