Annotation of parser3/src/main/pa_charset_manager.C, revision 1.4

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.4     ! paf         7:        $Id: pa_charset_manager.C,v 1.3 2001/10/02 17:12:53 parser 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.1       parser     17: 
                     18: // globals
                     19: 
                     20: Charset_manager *charset_manager;
                     21: 
                     22: // consts
                     23: 
                     24: 
                     25: // Charset_manager
                     26: 
1.4     ! paf        27: Charset_manager::Charset_manager(Pool& apool) : Pooled(apool),
        !            28:        cache(apool) {
        !            29: 
        !            30:        status_providers->put(*NEW String(pool(), "charset"), this);
        !            31: }
        !            32: 
        !            33: 
1.1       parser     34: Charset_connection& Charset_manager::get_connection(const String& request_name, const String& request_file_spec) {
                     35:        Pool& pool=request_name.pool(); // request pool                                                                                    
                     36: 
                     37:        // first trying to get cached
                     38:        Charset_connection *result=get_connection_from_cache(request_file_spec);
                     39:        if(!result) {
                     40:                // then just construct it
                     41: 
                     42:                // make global_name C-string on global pool
                     43:                const char *request_name_cstr=request_name.cstr(String::UL_FILE_SPEC);
                     44:                char *global_name_cstr=(char *)malloc(strlen(request_name_cstr)+1);
                     45:                strcpy(global_name_cstr, request_name_cstr);
                     46:                // make global_name string on global pool
                     47:                String& global_name=*new(this->pool()) String(this->pool(), global_name_cstr);
                     48: 
                     49:                // make global_file_spec C-string on global pool
                     50:                const char *request_file_spec_cstr=request_file_spec.cstr(String::UL_FILE_SPEC);
                     51:                char *global_file_spec_cstr=(char *)malloc(strlen(request_file_spec_cstr)+1);
                     52:                strcpy(global_file_spec_cstr, request_file_spec_cstr);
                     53:                // make global_file_spec string on global pool
                     54:                String& global_file_spec=*new(this->pool()) String(this->pool(), global_file_spec_cstr);
                     55:                
                     56:                // construct result
                     57:                result=new(this->pool()) Charset_connection(this->pool(), global_name, global_file_spec);
                     58:                // cache it
                     59:                put_connection_to_cache(global_file_spec, *result);
                     60:        }
                     61:        // preload file, need to make addEncoding for xml
                     62:        result->up_to_date(pool); 
                     63:        // return it
                     64:        return *result;
                     65: }
                     66: 
                     67: //  cache
                     68: Charset_connection *Charset_manager::get_connection_from_cache(const String& file_spec) { 
                     69:        SYNCHRONIZED;
                     70: 
                     71:        return (Charset_connection *)cache.get(file_spec);
                     72: }
                     73: 
                     74: void Charset_manager::put_connection_to_cache(const String& file_spec, 
                     75:                                                                                                 Charset_connection& connection) { 
                     76:        SYNCHRONIZED;
                     77: 
                     78:        cache.put(file_spec, &connection);
1.4     ! paf        79: }
        !            80: 
        !            81: Value& Charset_manager::get_status(Pool& pool, const String *source) {
        !            82:        VHash& result=*new(pool) VHash(pool);
        !            83: /*     
        !            84:        // cache
        !            85:        {
        !            86:                Array& columns=*new(pool) Array(pool, 3);
        !            87:                columns+=new(pool) String(pool, "protocol");
        !            88:                columns+=new(pool) String(pool, "time");
        !            89:                columns+=new(pool) String(pool, "times");
        !            90:                Table& table=*new(pool) Table(pool, 0, &columns, connection_cache.size());
        !            91: 
        !            92:                connection_cache.for_each(add_connections_to_status_cache_table, &table);
        !            93: 
        !            94:                result.hash(source).put(*new(pool) String(pool, "cache"), new(pool) VTable(pool, &table));
        !            95:        }
        !            96: */
        !            97:        return result;
1.1       parser     98: }

E-mail: