/* * $Id: transaction.c,v 1.1.1.1 2004/08/25 19:21:57 jan Exp $ * * Copyright (c) 2002 Jan Algermissen * See the file "COPYING" for copying permission. * */ #include "tm.h" #include "tmtrace.h" #include "tmtable.h" #include "tmassert.h" #include "tmutil.h" #include "tmtk.h" /* #include "tmstack.h" #include "tmparams.h" #include "tmtopicset.h" */ #include #include typedef struct TMTransaction *TMTransaction; struct TMTransaction { TM tm; TMPool pool; time_t t_start; char *tag; TMTable symtab; }; TMTransaction tm_transaction_new(TMPool pool,TM tm,const char *tag) { TMPool mypool; TMTransaction self; mypool = tm_pool_new("transaction-pool",pool); TM_NEW(mypool,self); self->tm = tm; self->tag = tm_strdup(mypool,tag); self->symtab = tm_table_new(mypool,10,tm_strcmp_v,tm_strhash_v); self->pool = mypool; return self; } void tm_transaction_delete(TMTransaction *pself) { TMPool pool; assert(pself && *pself); pool = (*pself)->pool; /* FIXME: free keys in symtab*/ tm_table_apply( (*pself)->symtab , tm_free_keys , pool ); tm_table_delete( &((*pself)->symtab) ); TM_FREE(pool,(*pself)->tag); TM_FREE(pool,*pself); tm_pool_delete(&pool); } const char *tm_transaction_get_tag(TMTransaction self) { assert(self); return( self->tag ); } TMPool tm_transaction_get_pool(TMTransaction self) { assert(self); return self->pool; } void tm_transaction_store_topic(TMTransaction self,const char *sym, TMTopic topic) { TMTopic exist; char *sym_key = (char*)sym; assert(self); exist = (TMTopic)tm_table_get(self->symtab,sym); if( exist == 0) { /* table put will set key only on first insert, so * we make the key here! */ sym_key = tm_strdup(self->pool,sym); } else { TM_LOG(self->tm,TM_LOG_DEBUG, "[tm|%s] symbol %s exists for Topic %d, overwriting" _ self->tag _ sym_key _ exist); } tm_table_put(self->symtab,sym_key,(void*)topic); TM_LOG(self->tm,TM_LOG_INFO,"[tm|%s] added t%d as %s to symtab" _ self->tag _ topic _ sym_key ); } TMTopic tm_transaction_get_topic(TMTransaction self,const char *sym) { TMTopic t; assert(self); t = (TMTopic)tm_table_get(self->symtab,sym); TM_LOG(self->tm,TM_LOG_INFO,"[tm|%s] lookup of %s yields topic %d" _ self->tag _ sym _ t); return t; }