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 #ifndef __ASTypes__
00031 #include "ASTypes.h"
00032 #endif
00033
00034
00035 #include "SPBasic.h"
00036
00037 #ifndef __UserInteractionCheckerDefined__
00038 #include "IAIUnicodeString.h"
00039 #endif
00040
00041 #include "AIHeaderBegin.h"
00042
00043
00044
00045
00046
00047
00048
00049
00051 #define kASUserInteractionSuite "AS User Interaction Suite"
00052
00053 #define kASUserInteractionSuiteVersion4 4
00054
00055 #define kASUserInteractionSuiteVersion kASUserInteractionSuiteVersion4
00056
00057 #define kASUserInteractionVersion kASUserInteractionSuiteVersion
00058
00059
00060
00061
00062
00063
00064
00067 #define kErrUnknowInteractionLevel 'UILv'
00068
00069
00070
00071
00072
00073
00074
00078 typedef enum _t_ASInteractionAllowed {
00081 kASInteractWithNone = -1,
00084 kASInteractWithSelf = 0,
00087 kASInteractWithLocal = 1,
00089 kASInteractWithAll = 2
00090 } ASInteractionAllowed;
00091
00092
00093
00094
00095
00096
00097
00098
00108 typedef struct {
00109
00115 ASAPI ASInteractionAllowed (*GetInteractionAllowed) ( void );
00120 ASAPI ASErr (*SetInteractionAllowed) ( ASInteractionAllowed allowed );
00121
00128 ASAPI ASBoolean (*InteractWithUser) ( void );
00129
00135 ASAPI ASErr (*LogInteraction) ( const char *msg );
00136
00142 ASAPI ASErr (*LogInteractionW) ( const ASUnicode *msg );
00143
00144
00145 } ASUserInteractionSuite;
00146
00147 #ifndef __UserInteractionCheckerDefined__
00148
00149
00150
00151 class ASUserInteractionChecker
00152 {
00153 public:
00158 ASUserInteractionChecker(SPBasicSuite *spBasic)
00159 {
00160 m_SPBasic = spBasic;
00161 m_SuitePtr = NULL;
00162 if (m_SPBasic)
00163 {
00164 ASErr error = m_SPBasic->AcquireSuite(kASUserInteractionSuite,
00165 kASUserInteractionVersion,
00166 (const void **)&m_SuitePtr);
00167 if(error != kNoErr)
00168 {
00169 m_SuitePtr = NULL;
00170 }
00171 }
00172 }
00179 ASBoolean InteractWithUser(void)
00180 {
00181 if (m_SuitePtr)
00182 return m_SuitePtr->InteractWithUser();
00183 else
00184 return true;
00185 }
00186
00192 ASErr logInfo(const ai::UnicodeString& msg1, const ai::UnicodeString *msg2=NULL)
00193 {
00194 ASErr err = kNoErr;
00195
00196 if (m_SuitePtr && !InteractWithUser())
00197 {
00198 if (msg2)
00199 {
00200 ai::UnicodeString::UTF32TextChar c = ' ';
00201 ai::UnicodeString msg = msg1;
00202 msg += ai::UnicodeString(1,c);
00203 msg.append(*msg2);
00204 err = m_SuitePtr->LogInteraction(msg.as_UTF8().c_str());
00205 }
00206 else
00207 {
00208 err = m_SuitePtr->LogInteraction(msg1.as_UTF8().c_str());
00209 }
00210 }
00211
00212 return err;
00213 }
00219 void logError(const ai::UnicodeString& msg1, const ai::UnicodeString *msg2=NULL)
00220 {
00221 ai::UnicodeString msg("Error: ");
00222 msg += msg1;
00223 logInfo(msg, msg2);
00224 }
00230 void logWarning(const ai::UnicodeString& msg1, const ai::UnicodeString *msg2=NULL)
00231 {
00232 ai::UnicodeString msg("Warning: ");
00233 msg += msg1;
00234 logInfo(msg, msg2);
00235 }
00237 ~ASUserInteractionChecker()
00238 {
00239 if (m_SuitePtr && m_SPBasic)
00240 {
00241 m_SPBasic->ReleaseSuite(kASUserInteractionSuite, kASUserInteractionVersion);
00242 m_SuitePtr = NULL;
00243 }
00244 }
00245
00246 private:
00247 SPBasicSuite *m_SPBasic;
00248 ASUserInteractionSuite *m_SuitePtr;
00249 };
00250
00251 #endif // __UserInteractionCheckerDefined__
00252
00253 #include "AIHeaderEnd.h"
00254
00255 #endif // __ASUserInteraction__
00256