source: issm/trunk-jpl/src/c/io/PrintfFunction.cpp@ 14082

Last change on this file since 14082 was 14082, checked in by Eric.Larour, 12 years ago

NEW: fixed unresolved symbols when using android logging capability (Android.mk).
Introduced logging from libISSMCore.a directly into JNI using the _pprintLine_ macro and android
logging capabilities. Requires android ndk setup -> made corresponding mods in src/c/io
and m4/ and configs/
In short, we can now construct FemModel within the ISSM android app!

File size: 1.7 KB
Line 
1/*\file PrintfFunction.c
2 *\brief: this function is used by the _printf_ macro, to take into account the
3 *fact we may be running on a cluster.
4 */
5
6#include <stdarg.h>
7#include <stdio.h>
8#include "../shared/shared.h"
9#include "../include/include.h"
10
11#ifdef _HAVE_ANDROID_NDK_
12#include <android/log.h>
13#endif
14
15int PrintfFunction(const char* format,...){
16 /*http://linux.die.net/man/3/vsnprintf*/
17
18 /*string to be printed: */
19 char *buffer = NULL;
20 int n,size = 100;
21 int my_rank;
22 //variable list of arguments
23 va_list args;
24
25 /*recover my_rank:*/
26 my_rank=IssmComm::GetRank();
27
28 while(true){
29
30 /*allocate buffer for given string size*/
31 buffer=xNew<char>(size);
32
33 /* Try to print in the allocated space. */
34 va_start(args, format);
35 n=vsnprintf(buffer,size,format,args);
36 va_end(args);
37
38 /* If that worked, return the string. */
39 if(n>-1 && n<size) break;
40
41 /* Else try again with more space. */
42 if(n>-1) /* glibc 2.1 */
43 size=n+1; /* precisely what is needed */
44 else /* glibc 2.0 */
45 size*=2; /* twice the old size */
46
47 xDelete<char>(buffer);
48 }
49
50 /*Ok, if we are running in parallel, get node 0 to print*/
51 if(my_rank==0)_printString_(buffer);
52
53 /*Clean up and return*/
54 xDelete<char>(buffer);
55 return 1;
56}
57int PrintfFunction(const string & message){
58 int my_rank;
59
60 /*recover my_rank:*/
61 my_rank=IssmComm::GetRank();
62
63 if(my_rank==0){
64 #ifdef _HAVE_ANDROID_JNI_
65 __android_log_print(ANDROID_LOG_INFO, "Native",message.c_str());
66 #else
67 printf("%s\n",message.c_str());
68 #endif
69 }
70 return 1;
71}
72int PrintfFunction2(const string & message){
73 int my_rank;
74
75 /*recover my_rank:*/
76 my_rank=IssmComm::GetRank();
77
78 if(my_rank==0){
79 printf("%s",message.c_str());
80 }
81 return 1;
82}
Note: See TracBrowser for help on using the repository browser.