00001 #ifndef __ASUserInteraction__
00002 #define __ASUserInteraction__
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "SPBasic.h"
00031
00032 #ifndef __UserInteractionCheckerDefined__
00033 #include "IAIUnicodeString.h"
00034 #include "AIErrorHandler.h"
00035 #endif
00036
00037
00038 #include "AIHeaderBegin.h"
00039
00040
00041
00042
00043
00044
00045
00046
00048 #define kASUserInteractionSuite "AS User Interaction Suite"
00049
00050 #define kASUserInteractionSuiteVersion4 4
00051
00052 #define kASUserInteractionSuiteVersion kASUserInteractionSuiteVersion4
00053
00054 #define kASUserInteractionVersion kASUserInteractionSuiteVersion
00055
00056
00057
00058
00059
00060
00061
00064 #define kErrUnknowInteractionLevel 'UILv'
00065
00066
00067
00068
00069
00070
00071
00075 typedef enum _t_ASInteractionAllowed {
00078 kASInteractWithNone = -1,
00081 kASInteractWithSelf = 0,
00084 kASInteractWithLocal = 1,
00086 kASInteractWithAll = 2
00087 } ASInteractionAllowed;
00088
00089
00090
00091
00092
00093
00094
00095
00105 typedef struct {
00106
00112 ASAPI ASInteractionAllowed (*GetInteractionAllowed) ( void );
00117 ASAPI ASErr (*SetInteractionAllowed) ( ASInteractionAllowed allowed );
00118
00125 ASAPI ASBoolean (*InteractWithUser) ( void );
00126
00132 ASAPI ASErr (*LogInteraction) ( const char *msg );
00133
00139 ASAPI ASErr (*LogInteractionW) ( const ASUnicode *msg );
00140
00141
00142 } ASUserInteractionSuite;
00143
00144 #ifndef __UserInteractionCheckerDefined__
00145
00146
00147
00148 class ASUserInteractionChecker
00149 {
00150 public:
00155 ASUserInteractionChecker(SPBasicSuite *spBasic)
00156 {
00157 m_SPBasic = spBasic;
00158 m_SuitePtr = NULL;
00159 if (m_SPBasic)
00160 {
00161 ASErr error = m_SPBasic->AcquireSuite(kASUserInteractionSuite,
00162 kASUserInteractionVersion,
00163 (const void **)&m_SuitePtr);
00164 if(error != kNoErr)
00165 {
00166 m_SuitePtr = NULL;
00167 }
00168 }
00169 }
00176 ASBoolean InteractWithUser(void)
00177 {
00178 if (m_SuitePtr)
00179 return m_SuitePtr->InteractWithUser();
00180 else
00181 return true;
00182 }
00183
00189 ASErr logInfo(const ai::UnicodeString& msg1, const ai::UnicodeString *msg2=NULL)
00190 {
00191 ASErr err = kNoErr;
00192
00193 try
00194 {
00195 if (m_SuitePtr && !InteractWithUser())
00196 {
00197 if (msg2)
00198 {
00199 ai::UnicodeString::UTF32TextChar c = ' ';
00200 ai::UnicodeString msg = msg1;
00201 msg += ai::UnicodeString(1,c);
00202 msg.append(*msg2);
00203 err = m_SuitePtr->LogInteraction(msg.as_UTF8().c_str());
00204 }
00205 else
00206 {
00207 err = m_SuitePtr->LogInteraction(msg1.as_UTF8().c_str());
00208 }
00209 }
00210 }
00211 AI_CATCH_RETURN;
00212
00213 return err;
00214 }
00220 void logError(const ai::UnicodeString& msg1, const ai::UnicodeString *msg2=NULL)
00221 {
00222 try
00223 {
00224 ai::UnicodeString msg("Error: ");
00225 msg += msg1;
00226 logInfo(msg, msg2);
00227 }
00228 AI_CATCH_NO_RETURN;
00229 }
00235 void logWarning(const ai::UnicodeString& msg1, const ai::UnicodeString *msg2 = NULL)
00236 {
00237 try
00238 {
00239 ai::UnicodeString msg("Warning: ");
00240 msg += msg1;
00241 logInfo(msg, msg2);
00242 }
00243 AI_CATCH_NO_RETURN;
00244 }
00246 ~ASUserInteractionChecker()
00247 {
00248 if (m_SuitePtr && m_SPBasic)
00249 {
00250 m_SPBasic->ReleaseSuite(kASUserInteractionSuite, kASUserInteractionVersion);
00251 m_SuitePtr = NULL;
00252 }
00253 }
00254
00255 private:
00256 SPBasicSuite *m_SPBasic;
00257 ASUserInteractionSuite *m_SuitePtr;
00258 };
00259
00260 #endif // __UserInteractionCheckerDefined__
00261
00262 #include "AIHeaderEnd.h"
00263
00264 #endif // __ASUserInteraction__
00265