xref: /aoo41x/main/slideshow/source/engine/debug.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #include "precompiled_slideshow.hxx"
29 
30 #include "debug.hxx"
31 
32 #if OSL_DEBUG_LEVEL > 1
33 
34 #include "animationnodes/basecontainernode.hxx"
35 #include "animationnodes/paralleltimecontainer.hxx"
36 #include "animationnodes/sequentialtimecontainer.hxx"
37 #include "animationnodes/animationtransitionfilternode.hxx"
38 #include "animationnodes/animationaudionode.hxx"
39 #include "animationnodes/animationcolornode.hxx"
40 #include "animationnodes/animationcommandnode.hxx"
41 #include "animationnodes/animationpathmotionnode.hxx"
42 #include "animationnodes/animationsetnode.hxx"
43 #include "animationnodes/animationtransformnode.hxx"
44 #include "animationnodes/propertyanimationnode.hxx"
45 
46 #include <com/sun/star/animations/XAnimationNode.hpp>
47 #include <com/sun/star/animations/Event.hpp>
48 
49 #include <cstdio>
50 #include <cstdarg>
51 
52 using ::rtl::OUString;
53 using namespace ::com::sun::star;
54 
55 
56 namespace slideshow { namespace internal {
57 
58 namespace {
59 
60 class NodeContainer : public BaseContainerNode
61 {
62 public:
63     void ShowChildrenState (void) const;
64 };
65 
66 
67 
68 
69 OUString DebugGetDescription (const AnimationNodeSharedPtr& rpNode)
70 {
71     if (::boost::dynamic_pointer_cast<BaseContainerNode>(rpNode))
72     {
73         // Node is a container.
74         if (::boost::dynamic_pointer_cast<ParallelTimeContainer>(rpNode))
75             return OUString::createFromAscii("ParallelTimeContainer");
76         else if (::boost::dynamic_pointer_cast<SequentialTimeContainer>(rpNode))
77             return OUString::createFromAscii("SequentialTimeContainer");
78         else
79             return OUString::createFromAscii("<unknown container>");
80     }
81     else if (::boost::dynamic_pointer_cast<AnimationTransitionFilterNode>(rpNode))
82         return OUString::createFromAscii("AnimationTransitionFilterNode");
83     else if (::boost::dynamic_pointer_cast<AnimationAudioNode>(rpNode))
84         return OUString::createFromAscii("AnimationAudioNode");
85     else if (::boost::dynamic_pointer_cast<AnimationColorNode>(rpNode))
86         return OUString::createFromAscii("AnimationColorNode");
87     else if (::boost::dynamic_pointer_cast<AnimationCommandNode>(rpNode))
88         return OUString::createFromAscii("AnimationCommandNode");
89     else if (::boost::dynamic_pointer_cast<AnimationPathMotionNode>(rpNode))
90         return OUString::createFromAscii("AnimationPathMotionNode");
91     else if (::boost::dynamic_pointer_cast<AnimationSetNode>(rpNode))
92         return OUString::createFromAscii("AnimationSetNode");
93     else if (::boost::dynamic_pointer_cast<AnimationTransformNode>(rpNode))
94         return OUString::createFromAscii("AnimationTransformNode");
95     else if (::boost::dynamic_pointer_cast<PropertyAnimationNode>(rpNode))
96         return OUString::createFromAscii("PropertyAnimationNode");
97     else
98         return OUString::createFromAscii("<unknown node type>");
99 }
100 
101 
102 
103 
104 void DebugShowState (const AnimationNodeSharedPtr& rpNode)
105 {
106     if ( ! rpNode)
107         return;
108 
109     OUString sState;
110     OUString sStateColor;
111     switch (rpNode->getState())
112     {
113         default:
114         case AnimationNode::INVALID:
115             sState = OUString::createFromAscii("Invalid");
116             sStateColor = OUString::createFromAscii("firebrick1");
117             break;
118         case AnimationNode::UNRESOLVED:
119             sState = OUString::createFromAscii("Unresolved");
120             sStateColor = OUString::createFromAscii("dodgerblue4");
121             break;
122         case AnimationNode::RESOLVED:
123             sState = OUString::createFromAscii("Resolved");
124             sStateColor = OUString::createFromAscii("dodgerblue");
125             break;
126         case AnimationNode::ACTIVE:
127             sState = OUString::createFromAscii("Active");
128             sStateColor = OUString::createFromAscii("seagreen1");
129             break;
130         case AnimationNode::FROZEN:
131             sState = OUString::createFromAscii("Frozen");
132             sStateColor = OUString::createFromAscii("lightskyblue1");
133             break;
134         case AnimationNode::ENDED:
135             sState = OUString::createFromAscii("Ended");
136             sStateColor = OUString::createFromAscii("slategray3");
137             break;
138     }
139 
140     const uno::Any aBegin (rpNode->getXAnimationNode()->getBegin());
141     OUString sTrigger;
142     if (aBegin.hasValue())
143     {
144         animations::Event aEvent;
145         double nTimeOffset;
146         const static char* sEventTriggers[] = {
147             "NONE", "ON_BEGIN", "ON_END", "BEGIN_EVENT", "END_EVENT", "ON_CLICK",
148             "ON_DBL_CLICK", "ON_MOUSE_ENTER", "ON_MOUSE_LEAVE", "ON_NEXT", "ON_PREV",
149             "ON_STOP_AUDIO", "REPEAT"};
150         if (aBegin >>= aEvent)
151         {
152             sTrigger = OUString::createFromAscii(sEventTriggers[aEvent.Trigger]);
153         }
154         else if (aBegin >>= nTimeOffset)
155         {
156             sTrigger = OUString::valueOf(nTimeOffset);
157         }
158         else
159         {
160             sTrigger = OUString::createFromAscii("other");
161         }
162     }
163     else
164         sTrigger = ::rtl::OUString::createFromAscii("void");
165 
166     TRACE("Node state: n%x [label=\"%x / %x / %s\\n%s\\n%s\",style=filled,fillcolor=\"%s\"]\r",
167         rpNode.get(),
168         rpNode.get(),
169         rpNode->getXAnimationNode().get(),
170         ::rtl::OUStringToOString(sState, RTL_TEXTENCODING_ASCII_US).getStr(),
171         ::rtl::OUStringToOString(DebugGetDescription(rpNode), RTL_TEXTENCODING_ASCII_US).getStr(),
172         ::rtl::OUStringToOString(sTrigger, RTL_TEXTENCODING_ASCII_US).getStr(),
173         ::rtl::OUStringToOString(sStateColor, RTL_TEXTENCODING_ASCII_US).getStr());
174 
175     BaseContainerNodeSharedPtr pContainer (
176         ::boost::dynamic_pointer_cast<BaseContainerNode>(rpNode));
177     if (pContainer)
178         ::boost::static_pointer_cast<NodeContainer>(rpNode)->ShowChildrenState();
179 }
180 
181 
182 
183 
184 void NodeContainer::ShowChildrenState (void) const
185 {
186     for (std::size_t nIndex=0; nIndex<maChildren.size(); ++nIndex)
187     {
188         TRACE("Node connection: n%x -> n%x", this, maChildren[nIndex].get());
189         DebugShowState(maChildren[nIndex]);
190     }
191 }
192 
193 
194 
195 
196 AnimationNodeSharedPtr DebugGetTreeRoot (const BaseNodeSharedPtr& rpNode)
197 {
198     BaseNodeSharedPtr pNode (rpNode);
199     if (pNode)
200     {
201         BaseNodeSharedPtr pParent (pNode->getParentNode());
202         while (pParent)
203         {
204             pNode = pParent;
205             pParent = pNode->getParentNode();
206         }
207     }
208     return pNode;
209 }
210 
211 } // end of anonymous namespace
212 
213 
214 
215 
216 void Debug_ShowNodeTree (const AnimationNodeSharedPtr& rpNode)
217 {
218     DebugTraceScope aTraceScope ("NodeTree");
219 
220     DebugShowState(DebugGetTreeRoot(::boost::dynamic_pointer_cast<BaseNode>(rpNode)));
221 }
222 
223 
224 
225 
226 //----- Tracing ---------------------------------------------------------------
227 
228 extern "C" {
229 
230     namespace {
231 
232     class TraceData
233     {
234     public:
235         TraceData (void)
236             : mnIndentation(0),
237               mpFile(fopen(TRACE_LOG_FILE_NAME, "w")),
238               maTime()
239         {
240         }
241 
242         int mnIndentation;
243         FILE* mpFile;
244         ::canvas::tools::ElapsedTime maTime;
245     };
246     static TraceData gTraceData;
247 
248     inline void SAL_CALL DebugTrace (
249         const int nIndentationOffset,
250         const sal_Char* sFormat,
251         va_list args)
252     {
253         if (gTraceData.mpFile != NULL)
254         {
255             // Write line head with current time and indentation.
256             // Adapt indentation.
257             if (nIndentationOffset < 0)
258                 gTraceData.mnIndentation += nIndentationOffset;
259             fprintf(gTraceData.mpFile, "%10.8f ", gTraceData.maTime.getElapsedTime());
260             for (int nIndentation=0; nIndentation<gTraceData.mnIndentation; ++nIndentation)
261                 fprintf(gTraceData.mpFile, "    ");
262             if (nIndentationOffset > 0)
263                 gTraceData.mnIndentation += nIndentationOffset;
264 
265             // Write message.
266             vfprintf(gTraceData.mpFile, sFormat, args);
267             fprintf(gTraceData.mpFile, "\n");
268             fflush(gTraceData.mpFile);
269         }
270     }
271 
272 } // end of anonymous namespace
273 
274 
275 } // end of extern "C"
276 
277 void SAL_CALL DebugTraceBegin (const sal_Char* sFormat, ...)
278 {
279     va_list args;
280     va_start(args, sFormat);
281     DebugTrace(+1,sFormat, args);
282     va_end(args);
283 }
284 
285 void SAL_CALL DebugTraceEnd (const sal_Char* sFormat, ...)
286 {
287     va_list args;
288     va_start(args, sFormat);
289     DebugTrace(-1,sFormat, args);
290     va_end(args);
291 }
292 
293 void SAL_CALL DebugTraceMessage (const sal_Char* sFormat, ...)
294 {
295     va_list args;
296     va_start(args, sFormat);
297     DebugTrace(0,sFormat, args);
298     va_end(args);
299 }
300 
301 
302 
303 DebugTraceScope::DebugTraceScope (const sal_Char* sFormat, ...)
304     : msMessage(new sal_Char[mnBufferSize])
305 {
306     va_list args;
307     va_start(args, sFormat);
308 
309     msMessage[mnBufferSize-1] = 0;
310     vsnprintf(msMessage, mnBufferSize-1, sFormat, args);
311     TRACE_BEGIN("[ %s", msMessage);
312     va_end(args);
313 }
314 
315 DebugTraceScope::~DebugTraceScope (void)
316 {
317     TRACE_END("] %s", msMessage);
318     delete [] msMessage;
319 }
320 
321 
322 } }
323 
324 #endif // OSL_DEBUG_LEVEL > 1
325