LibreOffice Module connectivity (master) 1
ConnectionLog.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20
22
23#include <com/sun/star/util/Date.hpp>
24#include <com/sun/star/util/Time.hpp>
25#include <com/sun/star/util/DateTime.hpp>
26
27#include <stdio.h>
28
29
31
32
33 namespace
34 {
35 sal_Int32 lcl_getFreeID( ConnectionLog::ObjectType _eType )
36 {
37 static oslInterlockedCount s_nCounts[ ConnectionLog::ObjectTypeCount ] = { 0, 0 };
38 return osl_atomic_increment( s_nCounts + _eType );
39 }
40 }
41
42 ConnectionLog::ConnectionLog( const ::comphelper::EventLogger& _rDriverLog )
43 :ConnectionLog_Base( _rDriverLog )
44 ,m_nObjectID( lcl_getFreeID( CONNECTION ) )
45 {
46 }
47
48
50 :ConnectionLog_Base( _rSourceLog )
51 ,m_nObjectID( _rSourceLog.m_nObjectID )
52 {
53 }
54
55
57 :ConnectionLog_Base( _rSourceLog )
58 ,m_nObjectID( lcl_getFreeID( _eType ) )
59 {
60 }
61
62
63} // namespace connectivity::java::sql
64
65
67{
68
69
70 using ::com::sun::star::util::Date;
71 using ::com::sun::star::util::Time;
72 using ::com::sun::star::util::DateTime;
73
74
75 OUString convertLogArgToString( const Date& _rDate )
76 {
77 char buffer[ 30 ];
78 const size_t buffer_size = sizeof( buffer );
79 snprintf( buffer, buffer_size, "%04i-%02i-%02i",
80 static_cast<int>(_rDate.Year), static_cast<int>(_rDate.Month), static_cast<int>(_rDate.Day) );
81 return OUString::createFromAscii( buffer );
82 }
83
84
85 OUString convertLogArgToString( const css::util::Time& _rTime )
86 {
87 char buffer[ 30 ];
88 const size_t buffer_size = sizeof( buffer );
89 snprintf( buffer, buffer_size, "%02i:%02i:%02i.%09i",
90 static_cast<int>(_rTime.Hours), static_cast<int>(_rTime.Minutes), static_cast<int>(_rTime.Seconds), static_cast<int>(_rTime.NanoSeconds) );
91 return OUString::createFromAscii( buffer );
92 }
93
94
95 OUString convertLogArgToString( const DateTime& _rDateTime )
96 {
97 char buffer[ sizeof("-32768-65535-65535 65535:65535:65535.4294967295") ];
98 // reserve enough space for hypothetical max length
99 const size_t buffer_size = sizeof( buffer );
100 snprintf( buffer, buffer_size, "%04" SAL_PRIdINT32 "-%02" SAL_PRIuUINT32 "-%02" SAL_PRIuUINT32 " %02" SAL_PRIuUINT32 ":%02" SAL_PRIuUINT32 ":%02" SAL_PRIuUINT32 ".%09" SAL_PRIuUINT32,
101 static_cast<sal_Int32>(_rDateTime.Year), static_cast<sal_uInt32>(_rDateTime.Month), static_cast<sal_uInt32>(_rDateTime.Day),
102 static_cast<sal_uInt32>(_rDateTime.Hours), static_cast<sal_uInt32>(_rDateTime.Minutes), static_cast<sal_uInt32>(_rDateTime.Seconds), _rDateTime.NanoSeconds );
103 return OUString::createFromAscii( buffer );
104 }
105
106
107} // comphelper::log::convert
108
109
110/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ConnectionLog(const ::comphelper::EventLogger &_rDriverLog)
will construct an instance of ObjectType CONNECTION
OUString convertLogArgToString(const DateTime &_rDateTime)