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