Annotation of parser3/src/main/pa_charset_manager.C, revision 1.9
1.1 parser 1: /** @file
2: Parser: sql driver manager implementation.
3:
4: Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
1.6 paf 5: Author: Alexander Petrosyan <paf@design.ru> (http://paf.design.ru)
1.1 parser 6:
1.9 ! paf 7: $Id: pa_charset_manager.C,v 1.8 2001/11/08 14:47:32 paf Exp $
1.1 parser 8: */
9: #include "pa_config_includes.h"
10:
11: #include "pa_charset_manager.h"
12: #include "ltdl.h"
13: #include "pa_exception.h"
14: #include "pa_common.h"
15: #include "pa_threads.h"
1.4 paf 16: #include "pa_vhash.h"
1.5 paf 17: #include "pa_vtable.h"
1.1 parser 18:
19: // globals
20:
21: Charset_manager *charset_manager;
22:
23: // consts
24:
25:
26: // Charset_manager
27:
1.8 paf 28: Charset_manager::Charset_manager(Pool& apool) : Cache_manager(apool),
1.4 paf 29: cache(apool) {
30: }
31:
32:
1.1 parser 33: Charset_connection& Charset_manager::get_connection(const String& request_name, const String& request_file_spec) {
34: Pool& pool=request_name.pool(); // request pool
35:
36: // first trying to get cached
37: Charset_connection *result=get_connection_from_cache(request_file_spec);
38: if(!result) {
39: // then just construct it
40:
41: // make global_name C-string on global pool
42: const char *request_name_cstr=request_name.cstr(String::UL_FILE_SPEC);
43: char *global_name_cstr=(char *)malloc(strlen(request_name_cstr)+1);
44: strcpy(global_name_cstr, request_name_cstr);
45: // make global_name string on global pool
46: String& global_name=*new(this->pool()) String(this->pool(), global_name_cstr);
47:
48: // make global_file_spec C-string on global pool
49: const char *request_file_spec_cstr=request_file_spec.cstr(String::UL_FILE_SPEC);
50: char *global_file_spec_cstr=(char *)malloc(strlen(request_file_spec_cstr)+1);
51: strcpy(global_file_spec_cstr, request_file_spec_cstr);
52: // make global_file_spec string on global pool
53: String& global_file_spec=*new(this->pool()) String(this->pool(), global_file_spec_cstr);
54:
55: // construct result
56: result=new(this->pool()) Charset_connection(this->pool(), global_name, global_file_spec);
57: // cache it
58: put_connection_to_cache(global_file_spec, *result);
59: }
60: // preload file, need to make addEncoding for xml
61: result->up_to_date(pool);
62: // return it
63: return *result;
64: }
65:
66: // cache
67: Charset_connection *Charset_manager::get_connection_from_cache(const String& file_spec) {
68: SYNCHRONIZED;
69:
70: return (Charset_connection *)cache.get(file_spec);
71: }
72: void Charset_manager::put_connection_to_cache(const String& file_spec,
73: Charset_connection& connection) {
74: SYNCHRONIZED;
75:
76: cache.put(file_spec, &connection);
1.4 paf 77: }
78:
1.5 paf 79: static void add_connection_to_status_cache_table(const Hash::Key& key, Hash::Val *value, void *info) {
80: Charset_connection& connection=*static_cast<Charset_connection *>(value);
81: Table& table=*static_cast<Table *>(info);
82:
83: Pool& pool=table.pool();
1.6 paf 84: Array& row=*new(pool) Array(pool);
1.5 paf 85:
1.6 paf 86: // file
1.5 paf 87: row+=&connection.get_file_spec();
88:
89: table+=&row;
90: }
1.4 paf 91: Value& Charset_manager::get_status(Pool& pool, const String *source) {
92: VHash& result=*new(pool) VHash(pool);
1.5 paf 93:
1.4 paf 94: // cache
95: {
1.6 paf 96: Array& columns=*new(pool) Array(pool);
1.5 paf 97: columns+=new(pool) String(pool, "file");
98: Table& table=*new(pool) Table(pool, 0, &columns, cache.size());
1.4 paf 99:
1.5 paf 100: cache.for_each(add_connection_to_status_cache_table, &table);
1.4 paf 101:
102: result.hash(source).put(*new(pool) String(pool, "cache"), new(pool) VTable(pool, &table));
103: }
1.5 paf 104:
1.4 paf 105: return result;
1.1 parser 106: }
E-mail: