X-TraceC++Library
XtrContext.h
Go to the documentation of this file.
00001 /*
00002 * Copyright (c) 2005,2006,2007 The Regents of the University of California.
00003 * All rights reserved.
00004 * 
00005 * Redistribution and use in source and binary forms, with or without
00006 * modification, are permitted provided that the following conditions are met:
00007 *     * Redistributions of source code must retain the above copyright
00008 *       notice, this list of conditions and the following disclaimer.
00009 *     * Redistributions in binary form must reproduce the above copyright
00010 *       notice, this list of conditions and the following disclaimer in the
00011 *       documentation and/or other materials provided with the distribution.
00012 *     * Neither the name of the University of California, nor the
00013 *       names of its contributors may be used to endorse or promote products
00014 *       derived from this software without specific prior written permission.
00015 * 
00016 * THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF CALIFORNIA ``AS IS'' AND ANY
00017 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00018 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019 * DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE FOR ANY
00020 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00021 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00022 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00023 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00024 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00025 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 */
00027 
00028 #include "XtrMetadata.h"
00029 #include "XtrEvent.h"
00030 #include <pthread.h>
00031 #include <unistd.h>
00032 #include <memory>
00033 
00034 #ifndef _XTR_CONTEXT_H
00035 #define _XTR_CONTEXT_H
00036 
00037 #define MAXHOSTNAME 256
00038 
00039 using namespace std;
00040 
00062 namespace xtr {
00063     
00068 class Context {
00069 public:
00070 
00072     static const Metadata& getContext ();
00073 
00077     static void setContext (Metadata const& xtr);
00078 
00083     static void unsetContext ();
00084     
00085 
00121     static xtr_result logEvent(const char* agent, const char* label,
00122                           u_int8_t severity = OptionSeverity::_DEFAULT);
00123 
00145     static xtr_result logEvent(Event* e,
00146                           u_int8_t severity = OptionSeverity::_DEFAULT);
00147 
00167     static auto_ptr<Event> 
00168     createEvent( const char* agent, const char* label,
00169                  u_int8_t severity = OptionSeverity::_DEFAULT); 
00170 
00201     static auto_ptr<Event>
00202     prepareEvent( const char* agent, const char* label, 
00203                   u_int8_t severity = OptionSeverity::_DEFAULT);
00204     
00211     static void setHost(const char* name);
00212     
00216     static void forkContext ();
00217 private:
00218 
00219     static void ensureKey();
00220     static bool is_host_set;
00221     static char host_name[MAXHOSTNAME+1];
00222     static void _set_host();
00223 public: // so it can be inited
00224     static pthread_key_t context_key;
00225 };
00226 
00227 }; //namespace xtr
00228 
00229 
00230 #endif //_XTR_CONTEXT_H