Annotation of parser3/src/main/pa_charset_manager.C, revision 1.2
1.1 parser 1: /** @file
2: Parser: sql driver manager implementation.
3:
4: Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
5: Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
6:
1.2 ! parser 7: $Id: pa_charset_manager.C,v 1.1 2001/10/01 10:53:16 parser Exp $
1.1 parser 8: */
9: #include "pa_config_includes.h"
10:
11: #include "pa_charset_manager.h"
12: #include "pa_stylesheet_connection.h"
13: #include "ltdl.h"
14: #include "pa_exception.h"
15: #include "pa_common.h"
16: #include "pa_threads.h"
17:
18: // globals
19:
20: Charset_manager *charset_manager;
21:
22: // consts
23:
24:
25: // Charset_manager
26:
27: Charset_connection& Charset_manager::get_connection(const String& request_name, const String& request_file_spec) {
28: Pool& pool=request_name.pool(); // request pool
29:
30: // first trying to get cached
31: Charset_connection *result=get_connection_from_cache(request_file_spec);
32: if(!result) {
33: // then just construct it
34:
35: // make global_name C-string on global pool
36: const char *request_name_cstr=request_name.cstr(String::UL_FILE_SPEC);
37: char *global_name_cstr=(char *)malloc(strlen(request_name_cstr)+1);
38: strcpy(global_name_cstr, request_name_cstr);
39: // make global_name string on global pool
40: String& global_name=*new(this->pool()) String(this->pool(), global_name_cstr);
41:
42: // make global_file_spec C-string on global pool
43: const char *request_file_spec_cstr=request_file_spec.cstr(String::UL_FILE_SPEC);
44: char *global_file_spec_cstr=(char *)malloc(strlen(request_file_spec_cstr)+1);
45: strcpy(global_file_spec_cstr, request_file_spec_cstr);
46: // make global_file_spec string on global pool
47: String& global_file_spec=*new(this->pool()) String(this->pool(), global_file_spec_cstr);
48:
49: // construct result
50: result=new(this->pool()) Charset_connection(this->pool(), global_name, global_file_spec);
51: // cache it
52: put_connection_to_cache(global_file_spec, *result);
53: }
54: // preload file, need to make addEncoding for xml
55: result->up_to_date(pool);
56: // return it
57: return *result;
58: }
59:
60: // cache
61: Charset_connection *Charset_manager::get_connection_from_cache(const String& file_spec) {
62: SYNCHRONIZED;
63:
64: return (Charset_connection *)cache.get(file_spec);
65: }
66:
67: void Charset_manager::put_connection_to_cache(const String& file_spec,
68: Charset_connection& connection) {
69: SYNCHRONIZED;
70:
71: cache.put(file_spec, &connection);
72: }
E-mail: