Changes between Version 9 and Version 10 of AppDev
- Timestamp:
- Jun 19, 2014, 9:54:38 AM (10 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
AppDev
v9 v10 1 = Application development tips =1 = Cross-platform functions = 2 2 3 == Cross-platform functions == 3 If you're porting an existing Unix app to Windows, 4 you'll find that while most POSIX calls are supported on Windows, 5 some are not. 4 6 5 Most POSIX calls are supported on Unix and Windows. For areas that are different (e.g. scanning directories) BOINC supplies some generic functions with implementations for all platforms. Similar code may be available from other open-source projects. 7 BOINC supplies some generic functions with implementations for all platforms. 8 Similar code may be available from other open-source projects 9 10 General functions (in lib/util.cpp/h): 6 11 7 12 double dtime():: return Unix time with fractional seconds 8 13 double dday():: return Unix time at start of this day 9 14 void boinc_sleep(double):: sleep for given period 10 read_file_string(const char*, string):: read file into string 15 double drand(), rand_normal():: uniform and normal random numbers 16 read_file_string(const char* path, std::string&):: read file into string 11 17 12 etc. See lib/util.h and lib/filesys.h for others. 18 Filesystem functions (in lib/filesys.cpp/h): 19 {{{ 20 extern int boinc_delete_file(const char*); 21 extern int boinc_touch_file(const char *path); 22 extern FILE* boinc_fopen(const char* path, const char* mode); 23 extern int boinc_copy(const char* orig, const char* newf); 24 extern int boinc_rename(const char* old, const char* newf); 25 extern int boinc_mkdir(const char*); 26 #ifdef _WIN32 27 extern int boinc_allocate_file(const char*, double size); 28 #else 29 extern int boinc_chown(const char*, gid_t); 30 #endif 31 extern int boinc_rmdir(const char*); 32 extern void boinc_getcwd(char*); 33 extern void relative_to_absolute(const char* relname, char* path); 34 extern int is_file(const char* path); 35 extern int is_dir(const char* path); 36 extern int is_file_follow_symlinks(const char* path); 37 extern int is_dir_follow_symlinks(const char* path); 38 extern int is_symlink(const char* path); 39 extern bool is_dir_empty(const char*); 40 extern int boinc_truncate(const char*, double); 41 extern int boinc_file_exists(const char* path); 42 extern int boinc_file_or_symlink_exists(const char* path); 43 extern int file_size(const char*, double&); 44 extern int clean_out_dir(const char*); 45 extern int dir_size(const char* dirpath, double&, bool recurse=true); 13 46 14 == Windows-specific issues == 47 class DirScanner; // for scanning directories 48 struct FILE_LOCK; // for locking a file 49 }}} 15 50 16 * Visual Studio: set '!Create/Use Precompiled Header' to 'Automatically Generate' ({{{/YX}}}) in C/C++ Precompiled Header project properties. 17 * Visual Studio: change 'Compile As' to 'Compile as C++ Code ({{{/TP}}})' in C/C++ 'Compile As' project properties. 51 Various RSA cryptographic functions: lib/crypt.cpp,h 18 52 19 == Unix-specific issues == 53 Various MD5 hash functions: lib/md5.cpp,h 20 54 21 === Shared libraries === 55 Semaphores: lib/synch.cpp,h 22 56 23 Your application can use shared libraries (.so). 24 Include these as separate files. 25 They will reside in your project's directory on the client host. 26 The BOINC client appends the project directory to LD_LIBRARY_PATH, 27 so your program will find them and run correctly. 57 Shared memory: lib/shmem.cpp,h 28 58 29 A problem may arise if you support multiple platforms 30 (say, Linux32 and Linux64). 31 You need different versions of the shared library for each platform. 32 These libraries must have distinct physical names - say, libfoo_1.1_linux32.so 33 and libfoo_1.1_linux64.so. 34 35 But what if there are multiple shared libraries, and some depend on others? 36 It may be difficult to change the Makefiles to use these distinct names. 37 Here's what you can do to solve this problem: 38 39 * Give each shared library its 'natural' name (e.g., libfoo.so) as its logical name. 40 * Give shared libraries the "copy_file" attribute. 41 42 The client will then copy these libraries into the app's execution directory, 43 giving it the logical name. 59 Network communication: lib/network.cpp,h