xref: /trunk/main/framework/inc/macros/debug/targeting.hxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
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 #ifndef __FRAMEWORK_MACROS_DEBUG_TARGETING_HXX_
29 #define __FRAMEWORK_MACROS_DEBUG_TARGETING_HXX_
30 
31 //*****************************************************************************************************************
32 //  special macros for targeting of frames
33 //*****************************************************************************************************************
34 
35 #ifdef  ENABLE_TARGETINGDEBUG
36 
37     //_____________________________________________________________________________________________________________
38     //  includes
39     //_____________________________________________________________________________________________________________
40 
41     #ifndef _RTL_STRBUF_HXX_
42     #include <rtl/strbuf.hxx>
43     #endif
44 
45     /*_____________________________________________________________________________________________________________
46         LOGFILE_TARGETING
47 
48         For follow macros we need a special log file. If user forget to specify anyone, we must do it for him!
49     _____________________________________________________________________________________________________________*/
50 
51     #ifndef LOGFILE_TARGETING
52         #define LOGFILE_TARGETSTEPS     "targetsteps.log"
53         #define LOGFILE_TARGETPARAM     "targetparam.log"
54     #endif
55 
56     /*_____________________________________________________________________________________________________________
57         LOG_PARAMETER_FINDFRAME( SSERVICE, SFRAMENAME, STARGETNAME, NSEARCHFLAGS )
58 
59         Log format for parameter e.g.: Desktop::findFrame( "frame1", 23 ) my name is "desktop"
60         Log format for steps     e.g.: desktop--
61 
62         With this macro you can log informations about search parameter of method "findFrame()" of an service.
63         Use it at beginning of search only!
64     _____________________________________________________________________________________________________________*/
65 
66     #define LOG_PARAMETER_FINDFRAME( SSERVICE, SFRAMENAME, STARGETNAME, NSEARCHFLAGS )                          \
67                 /* Use new scope to prevent code against multiple variable defines! */                          \
68                 {                                                                                               \
69                     ::rtl::OStringBuffer sBufferParam(256);                                                     \
70                     ::rtl::OStringBuffer sBufferSteps(256);                                                     \
71                     sBufferParam.append( SSERVICE                                               );              \
72                     sBufferParam.append( "::findFrame( \""                                      );              \
73                     sBufferParam.append( U2B( STARGETNAME )                                     );              \
74                     sBufferParam.append( "\", "                                                 );              \
75                     sBufferParam.append( ::rtl::OString::valueOf( sal_Int32( NSEARCHFLAGS ) )   );              \
76                     sBufferParam.append( " ) my name is \""                                     );              \
77                     sBufferParam.append( U2B( SFRAMENAME )                                      );              \
78                     sBufferParam.append( "\"\n"                                                 );              \
79                     sBufferSteps.append( U2B( SFRAMENAME )                                      );              \
80                     sBufferSteps.append( "--"                                                   );              \
81                     WRITE_LOGFILE( LOGFILE_TARGETPARAM, sBufferParam.makeStringAndClear() )                     \
82                     WRITE_LOGFILE( LOGFILE_TARGETSTEPS, sBufferSteps.makeStringAndClear() )                     \
83                 }
84 
85     /*_____________________________________________________________________________________________________________
86         LOG_PARAMETER_QUERYDISPATCH( SSERVICE, SFRAMENAME, AURL, STARGETNAME, NSEARCHFLAGS )
87 
88         With this macro you can log informations about search parameter of method "queryDispatch()" of an service.
89         Use it at beginning of search only!
90     _____________________________________________________________________________________________________________*/
91 
92     #define LOG_PARAMETER_QUERYDISPATCH( SSERVICE, SFRAMENAME, AURL, STARGETNAME, NSEARCHFLAGS )                        \
93                 /* Use new scope to prevent code against multiple variable defines! */                                  \
94                 {                                                                                                       \
95                     ::rtl::OStringBuffer sBuffer(1024);                                                                 \
96                     sBuffer.append( "[ "                                                    );                          \
97                     sBuffer.append( U2B( SFRAMENAME )                                       );                          \
98                     sBuffer.append( "] "                                                    );                          \
99                     sBuffer.append( SSERVICE                                                );                          \
100                     sBuffer.append( "::queryDispatch( \""                                   );                          \
101                     sBuffer.append( U2B( AURL.Complete )                                    );                          \
102                     sBuffer.append( "\", \""                                                );                          \
103                     sBuffer.append( U2B( STARGETNAME )                                      );                          \
104                     sBuffer.append( "\", "                                                  );                          \
105                     sBuffer.append( ::rtl::OString::valueOf( sal_Int32( NSEARCHFLAGS ) )    );                          \
106                     sBuffer.append( " )\n"                                                  );                          \
107                     WRITE_LOGFILE( LOGFILE_TARGETPARAM, sBuffer.makeStringAndClear() )                                  \
108                 }
109 
110     /*_____________________________________________________________________________________________________________
111         LOG_PARAMETER_LOADCOMPONENTFROMURL( SSERVICE, SFRAMENAME, SURL, STARGETNAME, NSEARCHFLAGS, SEQPARAMETER )
112 
113         With this macro you can log informations about search parameter of method "loadComponentFromURL()" of an service.
114         Use it at beginning of search only!
115     _____________________________________________________________________________________________________________*/
116 
117     #define LOG_PARAMETER_LOADCOMPONENTFROMURL( SSERVICE, SFRAMENAME, SURL, STARGETNAME, NSEARCHFLAGS, SEQPARAMETER )   \
118                 /* Use new scope to prevent code against multiple variable defines! */                                  \
119                 {                                                                                                       \
120                     ::rtl::OStringBuffer sBuffer(1024);                                                                 \
121                     sBuffer.append( "[ "                                                    );                          \
122                     sBuffer.append( U2B( SFRAMENAME )                                       );                          \
123                     sBuffer.append( "] "                                                    );                          \
124                     sBuffer.append( SSERVICE                                                );                          \
125                     sBuffer.append( "::loadComponentFromURL( \""                            );                          \
126                     sBuffer.append( U2B( SURL )                                             );                          \
127                     sBuffer.append( "\", \""                                                );                          \
128                     sBuffer.append( U2B( STARGETNAME )                                      );                          \
129                     sBuffer.append( "\", "                                                  );                          \
130                     sBuffer.append( ::rtl::OString::valueOf( sal_Int32( NSEARCHFLAGS ) )    );                          \
131                     sBuffer.append( ", "                                                    );                          \
132                     sal_Int32 nCount = SEQPARAMETER.getLength();                                                        \
133                     for( sal_Int32 nParameter=0; nParameter<nCount; ++nParameter )                                      \
134                     {                                                                                                   \
135                         sBuffer.append( U2B( SEQPARAMETER[nParameter].Name ));                                          \
136                         if( nParameter<(nCount-1) )                                                                     \
137                         {                                                                                               \
138                             sBuffer.append( " | " );                                                                    \
139                         }                                                                                               \
140                     }                                                                                                   \
141                     sBuffer.append( " )\n"                                                  );                          \
142                     WRITE_LOGFILE( LOGFILE_TARGETPARAM, sBuffer.makeStringAndClear() )                                  \
143                 }
144 
145     /*_____________________________________________________________________________________________________________
146         LOG_RESULT_FINDFRAME( SSERVICE, SFRAMENAME, XFRAME )
147 
148         With this macro you can log informations about search result of "findFrame()".
149         Use it at the end of this method only!
150     _____________________________________________________________________________________________________________*/
151 
152     #define LOG_RESULT_FINDFRAME( SSERVICE, SFRAMENAME, XFRAME )                                                        \
153                 /* Use new scope to prevent code against multiple variable defines! */                                  \
154                 {                                                                                                       \
155                     ::rtl::OStringBuffer sBufferParam(256);                                                             \
156                     ::rtl::OStringBuffer sBufferSteps(256);                                                             \
157                     sBufferParam.append( SSERVICE               );                                                      \
158                     sBufferParam.append( "::findFrame() at \""  );                                                      \
159                     sBufferParam.append( U2B( SFRAMENAME )      );                                                      \
160                     sBufferParam.append( "\" "                  );                                                      \
161                     if( XFRAME.is() == sal_True )                                                                       \
162                     {                                                                                                   \
163                         sBufferParam.append( "return with valid frame.\n"       );                                      \
164                         sBufferSteps.append( "OK ["                             );                                      \
165                         sBufferSteps.append( U2B( XFRAME->getName() )           );                                      \
166                         sBufferSteps.append( "]\n"                              );                                      \
167                     }                                                                                                   \
168                     else                                                                                                \
169                     {                                                                                                   \
170                         sBufferParam.append( "return with NULL frame!\n");                                              \
171                         sBufferSteps.append( "??\n"                     );                                              \
172                     }                                                                                                   \
173                     WRITE_LOGFILE( LOGFILE_TARGETPARAM, sBufferParam.makeStringAndClear() )                             \
174                     WRITE_LOGFILE( LOGFILE_TARGETSTEPS, sBufferSteps.makeStringAndClear() )                             \
175                 }
176 
177     /*_____________________________________________________________________________________________________________
178         LOG_RESULT_QUERYDISPATCH( SSERVICE, SFRAMENAME, XDISPATCHER )
179 
180         With this macro you can log informations about search result of "queryDispatch()".
181         Use it at the end of this method only!
182     _____________________________________________________________________________________________________________*/
183 
184     #define LOG_RESULT_QUERYDISPATCH( SSERVICE, SFRAMENAME, XDISPATCHER )                                               \
185                 /* Use new scope to prevent code against multiple variable defines! */                                  \
186                 {                                                                                                       \
187                     ::rtl::OStringBuffer sBuffer(1024);                                                                 \
188                     sBuffer.append( "[ "                );                                                              \
189                     sBuffer.append( U2B( SFRAMENAME )   );                                                              \
190                     sBuffer.append( "] "                );                                                              \
191                     sBuffer.append( SSERVICE            );                                                              \
192                     if( XDISPATCHER.is() == sal_True )                                                                  \
193                     {                                                                                                   \
194                         sBuffer.append( "::queryDispatch() return with valid dispatcher."   );                          \
195                     }                                                                                                   \
196                     else                                                                                                \
197                     {                                                                                                   \
198                         sBuffer.append( "::queryDispatch() return with NULL dispatcher!"    );                          \
199                     }                                                                                                   \
200                     sBuffer.append( "\n" );                                                                             \
201                     WRITE_LOGFILE( LOGFILE_TARGETPARAM, sBuffer.makeStringAndClear() )                                  \
202                 }
203 
204     /*_____________________________________________________________________________________________________________
205         LOG_RESULT_LOADCOMPONENTFROMURL( SSERVICE, SFRAMENAME, XCOMPONENT )
206 
207         With this macro you can log informations about search result of "loadComponentFromURL()".
208         Use it at the end of this method only!
209     _____________________________________________________________________________________________________________*/
210 
211     #define LOG_RESULT_LOADCOMPONENTFROMURL( SSERVICE, SFRAMENAME, XCOMPONENT )                                         \
212                 /* Use new scope to prevent code against multiple variable defines! */                                  \
213                 {                                                                                                       \
214                     ::rtl::OStringBuffer sBuffer(1024);                                                                 \
215                     sBuffer.append( "[ "                );                                                              \
216                     sBuffer.append( U2B( SFRAMENAME )   );                                                              \
217                     sBuffer.append( "] "                );                                                              \
218                     sBuffer.append( SSERVICE            );                                                              \
219                     if( XCOMPONENT.is() == sal_True )                                                                   \
220                     {                                                                                                   \
221                         sBuffer.append( "::loadComponentFromURL() return with valid component." );                      \
222                     }                                                                                                   \
223                     else                                                                                                \
224                     {                                                                                                   \
225                         sBuffer.append( "::loadComponentFromURL() return with NULL component!"  );                      \
226                     }                                                                                                   \
227                     sBuffer.append( "\n" );                                                                             \
228                     WRITE_LOGFILE( LOGFILE_TARGETPARAM, sBuffer.makeStringAndClear() )                                  \
229                 }
230 
231 #else   // #ifdef ENABLE_TARGETINGDEBUG
232 
233     /*_____________________________________________________________________________________________________________
234         If right testmode is'nt set - implements these macro empty!
235     _____________________________________________________________________________________________________________*/
236 
237     #undef  LOGFILE_TARGETPARAM
238     #undef  LOGFILE_TARGETSTEPS
239     #define LOG_PARAMETER_FINDFRAME( SSERVICE, SFRAMENAME, STARGETNAME, NSEARCHFLAGS )
240     #define LOG_PARAMETER_QUERYDISPATCH( SSERVICE, SFRAMENAME, AURL, STARGETNAME, NSEARCHFLAGS )
241     #define LOG_PARAMETER_LOADCOMPONENTFROMURL( SSERVICE, SFRAMENAME, SURL, STARGETNAME, NSEARCHFLAGS, SEQPARAMETER )
242     #define LOG_RESULT_FINDFRAME( SSERVICE, SFRAMENAME, XFRAME )
243     #define LOG_RESULT_QUERYDISPATCH( SSERVICE, SFRAMENAME, XDISPATCHER )
244     #define LOG_RESULT_LOADCOMPONENTFROMURL( SSERVICE, SFRAMENAME, XCOMPONENT )
245 
246 #endif  // #ifdef ENABLE_TARGETINGDEBUG
247 
248 //*****************************************************************************************************************
249 //  end of file
250 //*****************************************************************************************************************
251 
252 #endif  // #ifndef __FRAMEWORK_MACROS_DEBUG_TARGETING_HXX_
253