![]() |
AppEasy Core SDK
1.5.0
Cross platform mobile and desktop app and game development SDK - The easy way to make apps
|
00001 // 00002 // 00003 // AppEasy SDK - Cross Platform Multi-purpose Game and App Engine 00004 // 00005 // Developed by Matthew Hopwood of Pocketeers Limited - www.pocketeers.co.uk 00006 // 00007 // For updates, tutorials and more details check out www.appeasymobile.com 00008 // 00009 // This code is provided free of charge and without any warranty whatsoever. You must ensure that this whole notice is present in all files and derivatives, so the reader knows its origin. 00010 // If you use this SDK in your product then please ensure that you credit AppEasy's usage appropriately. Please see www.appeasymobile.com for licensing details and support 00011 // 00012 // 00013 00014 // 00015 // Working ad providers 00016 // -------------------- 00017 // Inner-active 00018 // AdFonic 00019 // VServ - Allows you to set up other networks including InMobi, BuzzCity, JumpTap, Zestadz and Inner-active 00020 // Mojiva 00021 // MillennialMedia - Allows you to set up other networks including AdMob, Amobee, JumpTap and Mojiva 00022 // AdModa 00023 // 00024 // Ad providers that will never work 00025 // --------------------------------- 00026 // AdMob - Closed their REST API so will never be available 00027 // MoPub - API is closed so will never be available 00028 // 00029 // Ad Providers with issues 00030 // ------------------------ 00031 // MobClix - Cant find a REST API 00032 // MobFox - Ads wont deliver over WiFi or Carrier and clicks are not registered 00033 // InMobi - Cannot get a single ad, either get bad request error or no ad error 00034 // Madvertise - Registering impressions but never returns any ads 00035 // KomliMobile - Always receieve "your account has been banned" message so gave up 00036 // 00037 // Ad Providers that need implementation 00038 // ------------------------------------- 00039 // BuzzCity - 00040 00041 00042 #if !defined(_CZ_ADS_H_) 00043 #define _CZ_ADS_H_ 00044 00045 #include "CzUtil.h" 00046 #include "CzHttp.h" 00047 #include "CzImage.h" 00048 #include "CzTime.h" 00049 00050 //#define _AD_DO_NOT_USE_ 00051 00052 #define CZ_ADS (CzAds::getInstance()) 00053 00054 #define CZ_ADS_TIMEOUT 10000 00055 #define CZ_MAX_CACHED_ADS 4 00056 #define CZ_MAX_AD_AGE (5 * 60000) 00057 00058 class CzAdsMediator; 00059 00060 // 00061 // 00062 // CzAd - The CzAd structure contains all data relating to the ad returned from the ad server 00063 // 00064 // 00065 struct CzAd 00066 { 00067 CzAd(): Image(NULL), isHtml(false), AdTime(0) {} 00068 virtual ~CzAd() 00069 { 00070 SAFE_DELETE(Image) 00071 } 00072 00073 bool isHtml; // If isHtml is set to true then only Text is valid and that cnotains the Ad HTML 00074 bool isText; // If true then the ad is a text ad 00075 CzString Text; // Ad text 00076 CzString ImageURI; // URI of image 00077 CzString LinkURI; // URI to be called when user clicks the ad 00078 CzImage* Image; // 2D image that represents the banner Ad 00079 int ImageFormat; // 2D Image format 00080 int64 AdTime; // Time ad was collected 00081 00082 CzAd* getCopy(); 00083 }; 00084 00085 // 00086 // 00087 // CzAds - The CzAds class is responsible for streaming ad data 00088 // 00089 // 00090 class CzAds 00091 { 00092 public: 00093 enum eAdProvider 00094 { 00095 InnerActive, 00096 AdFonic, 00097 VServ, 00098 Mojiva, 00099 MillennialMedia, 00100 AdModa, 00101 #if defined(_AD_DO_NOT_USE_) 00102 InMobi, 00103 MobClix, 00104 MobFox, 00105 Madvertise, 00106 KomliMobile, 00107 BuzzCity, 00108 #endif // _AD_DO_NOT_USE_ 00109 }; 00110 00111 enum eAdsPortalType 00112 { 00113 PortalNone, 00114 AndroidBanner, 00115 AndroidText, 00116 BadaBanner, 00117 BadaText, 00118 BlackberryBanner, 00119 BlackberryText, 00120 iPadBanner, 00121 iPadText, 00122 iPhoneBanner, 00123 iPhoneText, 00124 OVIBanner, 00125 OVIText, 00126 WebOSBanner, 00127 WebOSText, 00128 WinMobileBanner, 00129 WinMobileText, 00130 MobileWebBanner, 00131 MobileWebText, 00132 }; 00133 enum eAdsGender 00134 { 00135 GenderInvalid, 00136 GenderMale, 00137 GenderFemale, 00138 }; 00139 enum eAdsError 00140 { 00141 ErrorNone, 00142 ErrorHouseAd, 00143 ErrorInternalError, 00144 ErrorInvalidInput, 00145 ErrorUnknownAppId, 00146 ErrorNoAd, 00147 ErrorHttp, 00148 ErrorHttpImage, 00149 ErrorInvalidImage, 00150 ErrorRequestTimedOut, 00151 ErrorInvalidAdData, 00152 }; 00153 enum eAdsImageFormat 00154 { 00155 ImageFormatInvalid, 00156 ImageFormatPNG, 00157 ImageFormatGIF, 00158 ImageFormatJPG, 00159 }; 00160 00161 CDEFINE_SINGLETON(CzAds) 00162 00163 // Properties 00164 protected: 00165 CzString Version; // Protocol version string (for inner-active) 00166 CzString ApplicationID; // ID of the application thats making the request (you will need to be assigned this from your ad provider) 00167 CzString OtherID; // Extra ID information 00168 unsigned int UDID; // Unique ID of the device (used to identify device type, language and approx location to deliver more appropriate ads) 00169 int Width, Height; // Dimensions of device (used to collect more appropriate sized ads) 00170 eAdsPortalType PortalType; // Type of portal to collect ads from 00171 bool TextAds; // True if you want text ads to be returned, false if banner ads 00172 bool HtmlAds; // True if you want ads to be returned as html instead of xml (used by inner-active) 00173 int UserAge; // The users ages (optional) 00174 CzString UserAgent; // User agent string (system will build this but it can be replaced) 00175 CzString IPAddress; // IP Address of users device 00176 eAdsGender UserGender; // The users gender (optional) 00177 CzString UserLocation; // Location string – comma separated list of country, state/province, city (optional) 00178 CzString UserGPSLocation; // GPS Location string – ISO code location data in latitude, longitude format (optional) 00179 CzString Category; // Single word description of the application (optional) 00180 CzString UserMobileNumber; // Users mobile number - MSISDN format, with international prefix (optional) 00181 CzString UserKeywords; // Comma separated list of keywords relevant to this user’s specific session (optional) 00182 CzString ExtraInfo; // Pass in any extra pareneters as name vakue pairs, e.g. &city=london&ad_unit=1 (optional) 00183 bool AdAvailable; // True when ad is available 00184 CzCallback AdAvailableCallback; // Callback to be called when Ad is available 00185 eAdsError Error; // Comntains error code if any if ad not received 00186 CzString ErrorString; // Human readable error string 00187 CzAd AdInfo; // The returned ad info 00188 CzAdsMediator* Mediator; // Ad mediator (optional) 00189 00190 public: 00191 void setVersion(const char* version) { Version = version; } 00192 CzString& getVersion() { return Version; } 00193 void setApplicationID(const char* id) { ApplicationID = id; } 00194 CzString& getApplicationID() { return ApplicationID; } 00195 void setOtherID(const char* id) { OtherID = id; } 00196 CzString& getOtherID() { return OtherID; } 00197 void setUDID(unsigned int udid) { UDID = udid; } 00198 unsigned int getUDID() const { return UDID; } 00199 void setSize(int width, int height) { Width = width; Height = height; } 00200 int getWidth() const { return Width; } 00201 int getHeight() const { return Height; } 00202 void setPortalType(eAdsPortalType type) { PortalType = type; } 00203 eAdsPortalType getPortaltype() const { return PortalType; } 00204 void setTextAds(bool text_ads) { if (TextAds != text_ads) { TextAds = text_ads; PortalType = FindPortalType(TextAds); } } 00205 bool getTextAds() const { return TextAds; } 00206 void setHtmlAds(bool html_ads) { HtmlAds = html_ads; } 00207 bool getHtmlAds() const { return HtmlAds; } 00208 void setUserAgent(const char* user_agent) { UserAgent.setString(user_agent); } 00209 CzString& getUserAgent() { return UserAgent; } 00210 void setUserAge(int age) { UserAge = age; } 00211 int getUserAge() const { return UserAge; } 00212 void setUserGender(eAdsGender gender) { UserGender = gender; } 00213 eAdsGender getUserGender() const { return UserGender; } 00214 void setUserLocation(const char* location) { UserLocation = location; } 00215 CzString& getUserLocation() { return UserLocation; } 00216 void setUserGPSLocation(const char* location) { UserGPSLocation = location; } 00217 CzString& getUserGPSLocation() { return UserGPSLocation; } 00218 void setMobileNumber(const char* number) { UserMobileNumber = number; } 00219 CzString& getUserMobileNumber() { return UserMobileNumber; } 00220 void setUserKeywords(const char* keywords) { UserKeywords = keywords; } 00221 CzString& getUserKeywords() { return UserKeywords; } 00222 void setCategory(const char* category) { Category = category; } 00223 CzString& getCategory() { return Category; } 00224 void setExtraInfo(const char* extras) { ExtraInfo = extras; } 00225 CzString& getExtraInfo() { return ExtraInfo; } 00226 void setAdAvailable(bool available) { AdAvailable = available; } 00227 bool isAdAvailable() const { return AdAvailable; } 00228 void setAdAvailableCallback(CzCallback callback) { AdAvailableCallback = callback; } 00229 void setError(eAdsError error) { Error = error; } 00230 eAdsError getError() const { return Error; } 00231 void setErrorString(const char* error) { ErrorString.setString(error); } 00232 CzString& getErrorString() { return ErrorString; } 00233 CzAd& getAd() { return AdInfo; } 00234 int getMaxAds() const { return CZ_MAX_CACHED_ADS; } 00235 void setMediator(CzAdsMediator* med) { Mediator = med; } 00236 CzAdsMediator* getMediator() { return Mediator; } 00237 00238 // Properties end 00239 00240 protected: 00241 static unsigned int ResponseCodes[]; 00242 static int PortalIDs[]; 00243 00244 CzString ContentType; 00245 CzString UserIP; 00246 CzString ClientID; 00247 CzString RequestURI; 00248 CzHttpRequest AdRequest; 00249 CzTimer BusyTimer; 00250 eAdProvider AdProvider; 00251 00252 bool ExtractAd(CzAd& ad, CzString& ad_body); 00253 void ErrorFromResponse(const char* error, int error_len); 00254 bool RequestBannerImage(CzAd& ad); 00255 void NotifyAdAvailable(); 00256 eAdsImageFormat GetImageFormatFromHeader(); 00257 bool RequestAdInnerActive(); 00258 bool RequestAdInMobi(); 00259 bool RequestAdMobClix(); 00260 bool RequestAdMobFox(); 00261 bool RequestAdAdFonic(); 00262 bool RequestAdMadvertise(); 00263 bool RequestAdMojiva(); 00264 bool RequestAdMillennialMedia(); 00265 bool RequestAdVServ(); 00266 bool RequestAdKomliMobile(); 00267 bool RequestAdAdModa(); 00268 bool ExtractLinkAndImageFromtHTML(CzAd& ad, CzString& html); 00269 bool ExtractAdInnerActive(CzAd& ad, CzString& ad_body); 00270 bool ExtractAdInMobi(CzAd& ad, CzString& ad_body); 00271 bool ExtractAdMobClix(CzAd& ad, CzString& ad_body); 00272 bool ExtractAdMobFox(CzAd& ad, CzString& ad_body); 00273 bool ExtractAdAdFonic(CzAd& ad, CzString& ad_body); 00274 bool ExtractAdMadvertise(CzAd& ad, CzString& ad_body); 00275 bool ExtractAdMojiva(CzAd& ad, CzString& ad_body); 00276 bool ExtractAdMillennialMedia(CzAd& ad, CzString& ad_body); 00277 bool ExtractAdVServ(CzAd& ad, CzString& ad_body); 00278 bool ExtractAdKomliMobile(CzAd& ad, CzString& ad_body); 00279 bool ExtractAdAdModa(CzAd& ad, CzString& ad_body); 00280 00281 00282 public: 00283 bool Init(); // Initialises the Ads system (returns true if ads are supported) 00284 void Release(); // Releases data used by the Ads system 00285 void Update(); // Update ads 00286 bool RequestAd(eAdProvider provider, bool reset_mediator = true); // Requests an ad from the specified ad provider 00287 00288 // Utility 00289 static eAdsPortalType FindPortalType(bool text_ad = false); // Auto find portal type from OS type and ad type 00290 static int getPortalID(eAdsPortalType type); // Return portal iD 00291 00292 // Internal 00293 void AdImageReceived(CzHttpRequest* request, int error); // Called by the http callback internally when an ad image is received 00294 void AdReceived(CzHttpRequest* request, int error); // Called by the http callback internally when an ad is received 00295 00296 }; 00297 00298 00299 #endif // _CZ_ADS_H_