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

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

E-mail: