[PROTO] actualize return type for tizen_lifecycle
[platform/core/system/swap-probe.git] / probe_tizenapi / tizen_file.cpp
1 /*
2  *  DA probe
3  *
4  * Copyright (File::*c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact:
7  *
8  * Jaewon Lim <jaewon81.lim@samsung.com>
9  * Woojin Jung <woojin2.jung@samsung.com>
10  * Juyoung Kim <j0.kim@samsung.com>
11  * Anastasia Lyupa <a.lyupa@samsung.com>
12  *
13  * This library is free software; you can redistribute it and/or modify it under
14  * the terms of the GNU Lesser General Public License as published by the
15  * Free Software Foundation; either version 2.1 of the License, or (at your option)
16  * any later version.
17  *
18  * This library is distributed in the hope that it will be useful, but WITHOUT ANY
19  * WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
21  * License for more details.
22  *
23  * You should have received a copy of the GNU Lesser General Public License
24  * along with this library; if not, write to the Free Software Foundation, Inc., 51
25  * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26  *
27  * Contributors:
28  * - S-Core Co., Ltd
29  * - Samsung RnD Institute Russia
30  *
31  */
32
33 #include <FIo.h>
34 #include <linux/limits.h>
35 #include "daprobe.h"
36 #include "probeinfo.h"
37 #include "dahelper.h"
38
39 #include "binproto.h"
40
41 static enum DaOptions _sopt = OPT_FILE;
42
43 namespace Tizen {
44 namespace Io {
45
46 result File::Construct(const Tizen::Base::String& filePath,
47                 const Tizen::Base::String& openMode, bool createParentDirectories) {
48         typedef result (File::*methodType)(const Tizen::Base::String& filePath,
49                         const Tizen::Base::String& openMode, bool createParentDirectories);
50         static methodType Constructp = 0;
51         result ret;
52         probeInfo_t     probeInfo;
53         int blockresult;
54         bool bfiltering = true;
55         char temp_path[50];
56         char temp_mode[50];
57         FileAttributes attr;
58         long long size = 0L;
59
60         if (!Constructp) {
61                 probeBlockStart();
62                 void *tmpPtr = dlsym(RTLD_NEXT,
63                                 "_ZN5Tizen2Io4File9ConstructERKNS_4Base6StringES5_b");
64
65                 if (tmpPtr == NULL || dlerror() != NULL) {
66                         perror("dlsym failed : Tizen::Io::File::Construct");
67                         exit(0);
68                 }
69
70                 memcpy(&Constructp, &tmpPtr, sizeof(tmpPtr));
71                 probeBlockEnd();
72         }
73
74         if((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) {
75                 setProbePoint(&probeInfo);
76                 preBlockEnd();
77         }
78
79         ret = (this->*Constructp)(filePath, openMode, createParentDirectories);
80
81         if(postBlockBegin(blockresult)) {
82                 char buffer[PATH_MAX];
83
84                 if(E_SUCCESS == File::GetAttributes(this->GetName(), attr))
85                         size = attr.GetFileSize();
86                 WcharToChar(temp_path,filePath.GetPointer());
87                 WcharToChar(temp_mode,openMode.GetPointer());
88
89                 PREPARE_LOCAL_BUF();
90                 PACK_COMMON_BEGIN(MSG_PROBE_RESOURCE, API_ID_result_File__Construct_const_Tizen__Base__String__filePath__const_Tizen__Base__String__openMode__bool_createParentDirectories_,
91                                   "ssd", absolutize_filepath(buffer,temp_path),
92                                   temp_mode, createParentDirectories);
93                 PACK_COMMON_END('p', ret, ret, blockresult);
94                 PACK_RESOURCE(0, (unsigned long)this, FD_API_OPEN, size, temp_path);
95                 FLUSH_LOCAL_BUF();
96
97                 postBlockEnd();
98         }
99
100         return ret;
101 }
102
103 result File::Construct(const Tizen::Base::String& filePath,
104                 const Tizen::Base::String& openMode) {
105         typedef result (File::*methodType)(const Tizen::Base::String& filePath,
106                         const Tizen::Base::String& openMode);
107         static methodType Constructp = 0;
108         result ret;
109         probeInfo_t     probeInfo;
110         int blockresult;
111         bool bfiltering = true;
112         char temp_path[50];
113         char temp_mode[50];
114         FileAttributes attr;
115         long long size = 0L;
116
117         if(!Constructp) {
118                 probeBlockStart();
119                 void *tmpPtr = dlsym(RTLD_NEXT,
120                                 "_ZN5Tizen2Io4File9ConstructERKNS_4Base6StringES5_");
121
122                 if(tmpPtr == NULL || dlerror() != NULL) {
123                         perror("dlsym failed : Tizen::Io::File::Construct");
124                         exit(0);
125                 }
126
127                 memcpy(&Constructp, &tmpPtr, sizeof(tmpPtr));
128                 probeBlockEnd();
129         }
130
131         if((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) {
132                 setProbePoint(&probeInfo);
133                 preBlockEnd();
134         }
135
136         ret = (this->*Constructp)(filePath, openMode);
137
138         if(postBlockBegin(blockresult)) {
139                 char buffer[PATH_MAX];
140
141                 WcharToChar(temp_path,filePath.GetPointer());
142                 WcharToChar(temp_mode,openMode.GetPointer());
143                 // Comment this because of fault during Internet application profiling
144                 // (it closes unexpectedly) but for DATizenTestApp it is ok
145                 // There is the same problem at File::~File(void)
146                 //if(E_SUCCESS == File::GetAttributes(this->GetName(), attr))
147                 //      size = attr.GetFileSize();
148
149                 PREPARE_LOCAL_BUF();
150                 PACK_COMMON_BEGIN(MSG_PROBE_RESOURCE,
151                                   API_ID_result_File__Construct_const_Tizen__Base__String__filePath__const_Tizen__Base__String__openMode_,
152                                   "ss", absolutize_filepath(buffer, temp_path), temp_mode);
153                 PACK_COMMON_END('p', ret, ret, blockresult);
154                 PACK_RESOURCE(0, (unsigned long)this, FD_API_OPEN, size, temp_path);
155                 FLUSH_LOCAL_BUF();
156
157                 postBlockEnd();
158         }
159
160         return ret;
161 }
162
163 result File::Construct(const Tizen::Base::String& filePath,
164                 const char *pOpenMode) {
165         typedef result (File::*methodType)(const Tizen::Base::String& filePath,
166                         const char *pOpenMode);
167         static methodType Constructp = 0;
168         result ret;
169         probeInfo_t     probeInfo;
170         int blockresult;
171         bool bfiltering = true;
172         char temp[50];
173         FileAttributes attr;
174         long long size = 0L;
175
176         if(!Constructp) {
177                 probeBlockStart();
178                 void *tmpPtr = dlsym(RTLD_NEXT,
179                                 "_ZN5Tizen2Io4File9ConstructERKNS_4Base6StringEPKc");
180
181                 if(tmpPtr == NULL || dlerror() != NULL) {
182                         perror("dlsym failed : Tizen::Io::File::Construct");
183                         exit(0);
184                 }
185
186                 memcpy(&Constructp, &tmpPtr, sizeof(tmpPtr));
187                 probeBlockEnd();
188         }
189
190         if((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) {
191                 setProbePoint(&probeInfo);
192                 preBlockEnd();
193         }
194
195         ret = (this->*Constructp)(filePath, pOpenMode);
196
197         if(postBlockBegin(blockresult)) {
198                 char buffer[PATH_MAX];
199
200                 WcharToChar(temp,filePath.GetPointer());
201                 if(E_SUCCESS == File::GetAttributes(this->GetName(), attr))
202                         size = attr.GetFileSize();
203
204                 PREPARE_LOCAL_BUF();
205                 PACK_COMMON_BEGIN(MSG_PROBE_RESOURCE,
206                                   API_ID_result_File__Construct_const_Tizen__Base__String__filePath__const_char__pOpenMode_,
207                                   "sp", absolutize_filepath(buffer, temp),
208                                   voidp_to_uint64(pOpenMode));
209                 PACK_COMMON_END('p', ret, ret, blockresult);
210                 PACK_RESOURCE(0, (unsigned long)this, FD_API_OPEN, size, temp);
211                 FLUSH_LOCAL_BUF();
212
213                 postBlockEnd();
214         }
215
216         return ret;
217 }
218
219 result File::Construct(const Tizen::Base::String& filePath,
220                 const char *pOpenMode,
221                 const Tizen::Base::ByteBuffer& secretKey) {
222         typedef result (File::*methodType)(const Tizen::Base::String& filePath,
223                         const char *pOpenMode,
224                         const Tizen::Base::ByteBuffer& secretKey);
225         static methodType Constructp = 0;
226         result ret;
227         probeInfo_t probeInfo;
228         int blockresult;
229         bool bfiltering = true;
230         char temp[50];
231         FileAttributes attr;
232         long long size = 0L;
233
234         if(!Constructp) {
235                 probeBlockStart();
236
237                 void *tmpPtr = dlsym(RTLD_NEXT,
238                                                 "_ZN5Tizen2Io4File9ConstructERKNS_4Base6StringEPKcRKNS2_10ByteBufferE");
239
240                 if(tmpPtr == NULL || dlerror() != NULL) {
241                         perror("dlsym failed : Tizen::Io::File::Construct");
242                         exit(0);
243                 }
244
245                 memcpy(&Constructp, &tmpPtr, sizeof(tmpPtr));
246                 probeBlockEnd();
247         }
248
249         if((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) {
250                 setProbePoint(&probeInfo);
251                 preBlockEnd();
252         }
253
254         ret = (this->*Constructp)(filePath, pOpenMode, secretKey);
255
256         if(postBlockBegin(blockresult)) {
257                 WcharToChar(temp,filePath.GetPointer());
258                 if(E_SUCCESS == File::GetAttributes(this->GetName(), attr))
259                         size = attr.GetFileSize();
260
261                 PREPARE_LOCAL_BUF();
262                 PACK_COMMON_BEGIN(MSG_PROBE_RESOURCE,
263                                   API_ID_result_File__Construct_const_Tizen__Base__String__filePath__const_char__pOpenMode__const_Tizen__Base__ByteBuffer__secretKey_,
264                                   "sp", temp,
265                                   voidp_to_uint64(pOpenMode));
266                 PACK_COMMON_END('p', ret, ret, blockresult);
267                 PACK_RESOURCE(0, (unsigned long)this, FD_API_OPEN, size, temp);
268                 FLUSH_LOCAL_BUF();
269
270                 postBlockEnd();
271         }
272
273         return ret;
274 }
275
276 result File::Flush(void) {
277         typedef result (File::*methodType)(void);
278         static methodType Flushp = 0;
279         result ret;
280         probeInfo_t     probeInfo;
281         int blockresult;
282         bool bfiltering = true;
283         char temp[50];
284         FileAttributes attr;
285         long long size = 0L;
286
287         if (!Flushp) {
288                 probeBlockStart();
289
290                 void *tmpPtr = dlsym(RTLD_NEXT, "_ZN5Tizen2Io4File5FlushEv");
291
292                 if (tmpPtr == NULL || dlerror() != NULL) {
293                         perror("dlsym failed : Tizen::Io::File::Flush");
294                         exit(0);
295                 }
296
297                 memcpy(&Flushp, &tmpPtr, sizeof(tmpPtr));
298                 probeBlockEnd();
299         }
300
301         if((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) {
302                 setProbePoint(&probeInfo);
303                 preBlockEnd();
304         }
305
306         ret = (this->*Flushp)();
307
308         if(postBlockBegin(blockresult)) {
309                 WcharToChar(temp,this->GetName().GetPointer());
310                 if(E_SUCCESS == File::GetAttributes(this->GetName(), attr))
311                         size = attr.GetFileSize();
312
313                 PREPARE_LOCAL_BUF();
314                 PACK_COMMON_BEGIN(MSG_PROBE_RESOURCE,
315                                   API_ID_result_File__Flush_void_,
316                                   "", 0);
317                 PACK_COMMON_END('p', ret, ret, blockresult);
318                 PACK_RESOURCE(0, (unsigned long)this, FD_API_OTHER, size, temp);
319                 FLUSH_LOCAL_BUF();
320
321                 postBlockEnd();
322         }
323
324         return ret;
325 }
326
327 Tizen::Base::String File::GetName(void) const{
328         typedef Tizen::Base::String (File::*methodType)(void) const;
329         static methodType GetNamep = 0;
330         Tizen::Base::String ret;
331         probeInfo_t     probeInfo;
332         int blockresult;
333         bool bfiltering = true;
334         char temp[50];
335         FileAttributes attr;
336         long long size = 0L;
337
338         if (!GetNamep) {
339                 probeBlockStart();
340
341                 void *tmpPtr = dlsym(RTLD_NEXT, "_ZNK5Tizen2Io4File7GetNameEv");
342
343                 if (tmpPtr == NULL || dlerror() != NULL) {
344                         perror("dlsym failed : Tizen::Io::File::GetName");
345                         exit(0);
346                 }
347
348                 memcpy(&GetNamep, &tmpPtr, sizeof(tmpPtr));
349                 probeBlockEnd();
350         }
351
352         if((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) {
353                 setProbePoint(&probeInfo);
354                 preBlockEnd();
355         }
356
357         ret = (this->*GetNamep)();
358         result res = GetLastResult();
359
360         if(postBlockBegin(blockresult)) {
361                 WcharToChar(temp,ret.GetPointer());
362                 if (E_SUCCESS == File::GetAttributes(this->GetName(), attr))
363                         size = attr.GetFileSize();
364
365                 PREPARE_LOCAL_BUF();
366                 PACK_COMMON_BEGIN(MSG_PROBE_RESOURCE,
367                                   API_ID_Tizen__Base__String_File__GetName_void__const,
368                                   "", 0);
369                 PACK_COMMON_END('p', ret.GetPointer(), res, blockresult);
370                 PACK_RESOURCE(0, (unsigned long)this, FD_API_OTHER, size, temp);
371                 FLUSH_LOCAL_BUF();
372
373                  postBlockEnd();
374         }
375
376         return ret;
377 }
378
379 result File::Read(Tizen::Base::String& buffer) {
380         typedef result (File::*methodType)(Tizen::Base::String & buffer);
381         static methodType Readp = 0;
382         result ret;
383         probeInfo_t     probeInfo;
384         int blockresult;
385         bool bfiltering = true;
386         char temp[50];
387         int nRead = 0;
388         FileAttributes attr;
389         long long size = 0L;
390
391         if (!Readp) {
392                 probeBlockStart();
393
394                 void *tmpPtr = dlsym(RTLD_NEXT,
395                                 "_ZN5Tizen2Io4File4ReadERNS_4Base6StringE");
396
397                 if (tmpPtr == NULL || dlerror() != NULL) {
398                         perror("dlsym failed : Tizen::Io::File::Read");
399                         exit(0);
400                 }
401
402                 memcpy(&Readp, &tmpPtr, sizeof(tmpPtr));
403                 probeBlockEnd();
404         }
405
406         if((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) {
407                 setProbePoint(&probeInfo);
408                 if(E_SUCCESS == File::GetAttributes(this->GetName(), attr))
409                         size = attr.GetFileSize();
410                 WcharToChar(temp, this->GetName().GetPointer());
411
412                 PREPARE_LOCAL_BUF();
413                 PACK_COMMON_BEGIN(MSG_PROBE_RESOURCE,
414                                   API_ID_result_File__Read_Tizen__Base__String__buffer_,
415                                   "x", (uint64_t)(&buffer));
416                 PACK_COMMON_END('p', 0, 0, blockresult);
417                 PACK_RESOURCE(0, (unsigned long)this, FD_API_READ_START, size, temp);
418                 FLUSH_LOCAL_BUF();
419
420                 preBlockEnd();
421         }
422
423         ret = (this->*Readp)(buffer);
424
425         if(postBlockBegin(blockresult)) {
426                 setProbePoint(&probeInfo);
427                 if(E_SUCCESS == File::GetAttributes(this->GetName(), attr))
428                         size = attr.GetFileSize();
429                 WcharToChar(temp, this->GetName().GetPointer());
430                 nRead = buffer.GetLength();
431
432                 PREPARE_LOCAL_BUF();
433                 PACK_COMMON_BEGIN(MSG_PROBE_RESOURCE,
434                                   API_ID_result_File__Read_Tizen__Base__String__buffer_,
435                                   "x", (uint64_t)(&buffer));
436                 PACK_COMMON_END('p', ret, ret, blockresult);
437                 PACK_RESOURCE(nRead, (unsigned long)this, FD_API_READ_END, size, temp);
438                 FLUSH_LOCAL_BUF();
439
440                 postBlockEnd();
441         }
442
443         return ret;
444 }
445
446 result File::Read(Tizen::Base::ByteBuffer& buffer) {
447         typedef result (File::*methodType)(Tizen::Base::ByteBuffer & buffer);
448         static methodType Readp = 0;
449         result ret;
450         probeInfo_t     probeInfo;
451         int blockresult;
452         bool bfiltering = true;
453         char temp[50];
454         int nRead = 0;
455         FileAttributes attr;
456         long long size = 0L;
457
458         if (!Readp) {
459                 probeBlockStart();
460
461                 void *tmpPtr = dlsym(RTLD_NEXT,
462                                 "_ZN5Tizen2Io4File4ReadERNS_4Base10ByteBufferE");
463
464                 if (tmpPtr == NULL || dlerror() != NULL) {
465                         perror("dlsym failed : Tizen::Io::File::Read");
466                         exit(0);
467                 }
468
469                 memcpy(&Readp, &tmpPtr, sizeof(tmpPtr));
470                 probeBlockEnd();
471         }
472
473         if((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) {
474                 setProbePoint(&probeInfo);
475                 if(E_SUCCESS == File::GetAttributes(this->GetName(), attr))
476                         size = attr.GetFileSize();
477                 WcharToChar(temp, this->GetName().GetPointer());
478
479                 PREPARE_LOCAL_BUF();
480                 PACK_COMMON_BEGIN(MSG_PROBE_RESOURCE,
481                                   API_ID_result_File__Read_Tizen__Base__ByteBuffer__buffer_,
482                                   "x", (uint64_t)(&buffer));
483                 PACK_COMMON_END('p', 0, 0, blockresult);
484                 PACK_RESOURCE(0, (unsigned long)this, FD_API_READ_START, size, temp);
485                 FLUSH_LOCAL_BUF();
486
487                 preBlockEnd();
488         }
489
490         ret = (this->*Readp)(buffer);
491
492         if(postBlockBegin(blockresult)) {
493                 setProbePoint(&probeInfo);
494                 if(E_SUCCESS == File::GetAttributes(this->GetName(), attr))
495                         size = attr.GetFileSize();
496                 WcharToChar(temp, this->GetName().GetPointer());
497                 buffer.GetInt(nRead);
498
499                 PREPARE_LOCAL_BUF();
500                 PACK_COMMON_BEGIN(MSG_PROBE_RESOURCE,
501                                   API_ID_result_File__Read_Tizen__Base__ByteBuffer__buffer_,
502                                   "x", (uint64_t)(&buffer));
503                 PACK_COMMON_END('p', ret, ret, blockresult);
504                 PACK_RESOURCE(nRead, (unsigned long)this, FD_API_READ_END, size, temp);
505                 FLUSH_LOCAL_BUF();
506
507                 postBlockEnd();
508         }
509
510         return ret;
511 }
512
513 int File::Read(void *buffer, int length) {
514         typedef int (File::*methodType)(void *buffer, int length);
515         static methodType Readp = 0;
516         int ret;
517         probeInfo_t     probeInfo;
518         int blockresult;
519         bool bfiltering = true;
520         char temp[50];
521         int nRead = 0;
522         FileAttributes attr;
523         long long size = 0L;
524
525         if (!Readp) {
526                 probeBlockStart();
527
528                 void *tmpPtr = dlsym(RTLD_NEXT, "_ZN5Tizen2Io4File4ReadEPvi");
529
530                 if (tmpPtr == NULL || dlerror() != NULL) {
531                         perror("dlsym failed : Tizen::Io::File::Read");
532                         exit(0);
533                 }
534
535                 memcpy(&Readp, &tmpPtr, sizeof(tmpPtr));
536                 probeBlockEnd();
537         }
538
539         if((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) {
540                 setProbePoint(&probeInfo);
541                 nRead = Tell();
542                 if(E_SUCCESS == File::GetAttributes(this->GetName(), attr))
543                         size = attr.GetFileSize();
544                 WcharToChar(temp, this->GetName().GetPointer());
545
546                 PREPARE_LOCAL_BUF();
547                 PACK_COMMON_BEGIN(MSG_PROBE_RESOURCE,
548                                   API_ID_int_File__Read_void__buffer__int_length_,
549                                   "xd", (uint64_t)(buffer), length);
550                 PACK_COMMON_END('p', 0, 0, blockresult);
551                 PACK_RESOURCE(0, (unsigned long)this, FD_API_READ_START, size, temp);
552                 FLUSH_LOCAL_BUF();
553
554                 preBlockEnd();
555         }
556
557         ret = (this->*Readp)(buffer, length);
558         result res = GetLastResult();
559
560         if(postBlockBegin(blockresult)) {
561                 setProbePoint(&probeInfo);
562                 if(E_SUCCESS == File::GetAttributes(this->GetName(), attr))
563                         size = attr.GetFileSize();
564                 WcharToChar(temp, this->GetName().GetPointer());
565                 nRead = Tell() - nRead;
566
567                 PREPARE_LOCAL_BUF();
568                 PACK_COMMON_BEGIN(MSG_PROBE_RESOURCE,
569                                   API_ID_int_File__Read_void__buffer__int_length_,
570                                   "xd", (uint64_t)(buffer), length);
571                 PACK_COMMON_END('p', ret, res, blockresult);
572                 PACK_RESOURCE(nRead, (unsigned long)this, FD_API_READ_END, size, temp);
573                 FLUSH_LOCAL_BUF();
574
575                 postBlockEnd();
576         }
577
578         return ret;
579 }
580
581 result File::Seek(FileSeekPosition position, long offset) {
582         typedef result (File::*methodType)(FileSeekPosition position, long offset);
583         static methodType Seekp = 0;
584         result ret;
585         probeInfo_t     probeInfo;
586         int blockresult;
587         bool bfiltering = true;
588         char temp[1024];
589         char temp_pos[50];
590         FileAttributes attr;
591         long long size = 0;
592
593         if (!Seekp) {
594                 probeBlockStart();
595
596                 void *tmpPtr = dlsym(RTLD_NEXT,
597                                 "_ZN5Tizen2Io4File4SeekENS0_16FileSeekPositionEl");
598
599                 if (tmpPtr == NULL || dlerror() != NULL) {
600                         perror("dlsym failed : Tizen::Io::File::Seek");
601                         exit(0);
602                 }
603
604                 memcpy(&Seekp, &tmpPtr, sizeof(tmpPtr));
605
606                 probeBlockEnd();
607         }
608
609         if((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) {
610                 setProbePoint(&probeInfo);
611                 preBlockEnd();
612         }
613
614         ret = (this->*Seekp)(position, offset);
615
616         if(postBlockBegin(blockresult)) {
617
618                  if(FILESEEKPOSITION_BEGIN == position)
619                          strcpy(temp_pos, "FILESEEKPOSITION_BEGIN");
620                  else if(FILESEEKPOSITION_CURRENT == position)
621                          strcpy(temp_pos, "FILESEEKPOSITION_CURRENT");
622                  else if(FILESEEKPOSITION_END == position)
623                          strcpy(temp_pos, "FILESEEKPOSITION_END");
624                  else
625
626                 sprintf(temp_pos, "%d", position);
627
628                 if(E_SUCCESS == File::GetAttributes(this->GetName(), attr))
629                         size = attr.GetFileSize();
630                 WcharToChar(temp, this->GetName().GetPointer());
631
632                 PREPARE_LOCAL_BUF();
633                 PACK_COMMON_BEGIN(MSG_PROBE_RESOURCE,
634                                   API_ID_result_File__Seek_FileSeekPosition_position__long_offset_,
635                                   "sx", temp_pos, (uint64_t)(offset));
636                 PACK_COMMON_END('p', ret, ret, blockresult);
637                 PACK_RESOURCE(0, (unsigned long)this, FD_API_OTHER, size, temp);
638                 FLUSH_LOCAL_BUF();
639
640                  postBlockEnd();
641         }
642
643         return ret;
644 }
645
646 int File::Tell(void) const {
647         typedef int (File::*methodType)(void) const;
648         static methodType Tellp = 0;
649         int ret;
650         probeInfo_t     probeInfo;
651         int blockresult;
652         bool bfiltering = true;
653         char temp[50];
654         FileAttributes attr;
655         long long size = 0L;
656
657         if (!Tellp) {
658                 probeBlockStart();
659
660                 void *tmpPtr = dlsym(RTLD_NEXT, "_ZNK5Tizen2Io4File4TellEv");
661
662                 if (tmpPtr == NULL || dlerror() != NULL) {
663                         perror("dlsym failed : Tizen::Io::File::Tell");
664                         exit(0);
665                 }
666
667                 memcpy(&Tellp, &tmpPtr, sizeof(tmpPtr));
668
669                 probeBlockEnd();
670         }
671
672         if((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) {
673                 setProbePoint(&probeInfo);
674                 preBlockEnd();
675         }
676
677         ret = (this->*Tellp)();
678         result res = GetLastResult();
679
680         if(postBlockBegin(blockresult)) {
681                 if(E_SUCCESS == File::GetAttributes(this->GetName(), attr))
682                         size = attr.GetFileSize();
683                 WcharToChar(temp,this->GetName().GetPointer());
684
685                 PREPARE_LOCAL_BUF();
686                 PACK_COMMON_BEGIN(MSG_PROBE_RESOURCE,
687                                   API_ID_int_File__Tell_void__const,
688                                   "", 0);
689                 PACK_COMMON_END('p', ret, res, blockresult);
690                 PACK_RESOURCE(0, (unsigned long)this, FD_API_OTHER, size, temp);
691                 FLUSH_LOCAL_BUF();
692
693                  postBlockEnd();
694         }
695
696         return ret;
697 }
698
699 result File::Truncate(int length) {
700         typedef result (File::*methodType)(int length);
701         static methodType Truncatep = 0;
702         result ret;
703         probeInfo_t     probeInfo;
704         int blockresult;
705         bool bfiltering = true;
706         char temp[50];
707         FileAttributes attr;
708         long long size = 0L;
709
710         if (!Truncatep) {
711                 probeBlockStart();
712
713                 void *tmpPtr = dlsym(RTLD_NEXT, "_ZN5Tizen2Io4File8TruncateEi");
714
715                 if (tmpPtr == NULL || dlerror() != NULL) {
716                         perror("dlsym failed : Tizen::Io::File::Truncate");
717                         exit(0);
718                 }
719
720                 memcpy(&Truncatep, &tmpPtr, sizeof(tmpPtr));
721                 probeBlockEnd();
722         }
723
724         if((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) {
725                 setProbePoint(&probeInfo);
726                 preBlockEnd();
727         }
728
729         ret = (this->*Truncatep)(length);
730
731         if(postBlockBegin(blockresult)) {
732                 if(E_SUCCESS == File::GetAttributes(this->GetName(), attr))
733                         size = attr.GetFileSize();
734                 WcharToChar(temp,this->GetName().GetPointer());
735
736                 PREPARE_LOCAL_BUF();
737                 PACK_COMMON_BEGIN(MSG_PROBE_RESOURCE,
738                                   API_ID_result_File__Truncate_int_length_,
739                                   "d", length);
740                 PACK_COMMON_END('p', ret, ret, blockresult);
741                 PACK_RESOURCE(0, (unsigned long)this, FD_API_OTHER, size, temp);
742                 FLUSH_LOCAL_BUF();
743
744                  postBlockEnd();
745         }
746
747         return ret;
748 }
749
750 result File::Write(const void *buffer, int length) {
751         typedef result (File::*methodType)(const void *buffer, int length);
752         static methodType Writep = 0;
753         result ret;
754         probeInfo_t     probeInfo;
755         int blockresult;
756         bool bfiltering = true;
757         char temp[50];
758         int nWritten = 0;
759         FileAttributes attr;
760         long long size = 0L;
761
762         if (!Writep) {
763                 probeBlockStart();
764
765                 void *tmpPtr = dlsym(RTLD_NEXT, "_ZN5Tizen2Io4File5WriteEPKvi");
766
767                 if (tmpPtr == NULL || dlerror() != NULL) {
768                         perror("dlsym failed : Tizen::Io::File::Write");
769                         exit(0);
770                 }
771
772                 memcpy(&Writep, &tmpPtr, sizeof(tmpPtr));
773                 probeBlockEnd();
774         }
775
776         if((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) {
777                 setProbePoint(&probeInfo);
778                 nWritten = Tell();
779                 if(E_SUCCESS == File::GetAttributes(this->GetName(), attr))
780                         size = attr.GetFileSize();
781                 WcharToChar(temp, this->GetName().GetPointer());
782
783                 PREPARE_LOCAL_BUF();
784                 PACK_COMMON_BEGIN(MSG_PROBE_RESOURCE,
785                                   API_ID_result_File__Write_const_void__buffer__int_length_,
786                                   "xd", (uint64_t)(buffer), length);
787                 PACK_COMMON_END('p', 0, 0, blockresult);
788                 PACK_RESOURCE(0, (unsigned long)this, FD_API_WRITE_START, size, temp);
789                 FLUSH_LOCAL_BUF();
790
791                 preBlockEnd();
792         }
793
794         ret = (this->*Writep)(buffer, length);
795
796         if(postBlockBegin(blockresult)) {
797                 setProbePoint(&probeInfo);
798                 if(E_SUCCESS == File::GetAttributes(this->GetName(), attr))
799                         size = attr.GetFileSize();
800                 WcharToChar(temp, this->GetName().GetPointer());
801                 nWritten = Tell() - nWritten;
802
803                 PREPARE_LOCAL_BUF();
804                 PACK_COMMON_BEGIN(MSG_PROBE_RESOURCE,
805                                   API_ID_result_File__Write_const_void__buffer__int_length_,
806                                   "xd", (uint64_t)(buffer), length);
807                 PACK_COMMON_END('p', ret, ret, blockresult);
808                 PACK_RESOURCE(nWritten, (unsigned long)this, FD_API_WRITE_END, size, temp);
809                 FLUSH_LOCAL_BUF();
810
811                 postBlockEnd();
812         }
813
814         return ret;
815 }
816
817 result File::Write(const Tizen::Base::ByteBuffer& buffer) {
818         typedef result (File::*methodType)(const Tizen::Base::ByteBuffer& buffer);
819         static methodType Writep = 0;
820         result ret;
821         probeInfo_t     probeInfo;
822         int blockresult;
823         bool bfiltering = true;
824         char temp[50];
825         int nWritten = 0;
826         FileAttributes attr;
827         long long size = 0L;
828
829         if (!Writep) {
830                 probeBlockStart();
831
832                 void *tmpPtr = dlsym(RTLD_NEXT, "_ZN5Tizen2Io4File5WriteERKNS_4Base10ByteBufferE");
833
834                 if (tmpPtr == NULL || dlerror() != NULL) {
835                         perror("dlsym failed : Tizen::Io::File::Write");
836                         exit(0);
837                 }
838
839                 memcpy(&Writep, &tmpPtr, sizeof(tmpPtr));
840                 probeBlockEnd();
841         }
842
843         if((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) {
844                 setProbePoint(&probeInfo);
845                 nWritten = Tell();
846                 if(E_SUCCESS == File::GetAttributes(this->GetName(), attr))
847                         size = attr.GetFileSize();
848                 WcharToChar(temp,this->GetName().GetPointer());
849
850                 PREPARE_LOCAL_BUF();
851                 PACK_COMMON_BEGIN(MSG_PROBE_RESOURCE,
852                                   API_ID_result_File__Write_const_Tizen__Base__ByteBuffer__buffer_,
853                                   "x", (uint64_t)(&buffer));
854                 PACK_COMMON_END('p', 0, 0, blockresult);
855                 PACK_RESOURCE(0, (unsigned long)this, FD_API_WRITE_START, size, temp);
856                 FLUSH_LOCAL_BUF();
857
858                 preBlockEnd();
859         }
860
861         ret = (this->*Writep)(buffer);
862
863         if(postBlockBegin(blockresult)) {
864                 setProbePoint(&probeInfo);
865                 if(E_SUCCESS == File::GetAttributes(this->GetName(), attr))
866                         size = attr.GetFileSize();
867                 WcharToChar(temp,this->GetName().GetPointer());
868                 nWritten = Tell() - nWritten;
869
870                 PREPARE_LOCAL_BUF();
871                 PACK_COMMON_BEGIN(MSG_PROBE_RESOURCE,
872                                   API_ID_result_File__Write_const_Tizen__Base__ByteBuffer__buffer_,
873                                   "x", (uint64_t)(&buffer));
874                 PACK_COMMON_END('p', ret, ret, blockresult);
875                 PACK_RESOURCE(nWritten, (unsigned long)this, FD_API_WRITE_END, size, temp);
876                 FLUSH_LOCAL_BUF();
877
878                 postBlockEnd();
879         }
880
881         return ret;
882 }
883
884 result File::Write(const Tizen::Base::String& buffer) {
885         typedef result (File::*methodType)(const Tizen::Base::String& buffer);
886         static methodType Writep = 0;
887         result ret;
888         probeInfo_t     probeInfo;
889         int blockresult;
890         bool bfiltering = true;
891         char temp_buf[50];
892         char temp_path[50];
893         int nWritten = 0;
894         FileAttributes attr;
895         long long size = 0L;
896
897         if (!Writep) {
898                 probeBlockStart();
899
900                 void *tmpPtr = dlsym(RTLD_NEXT, "_ZN5Tizen2Io4File5WriteERKNS_4Base6StringE");
901
902                 if (tmpPtr == NULL || dlerror() != NULL) {
903                         perror("dlsym failed : Tizen::Io::File::Write");
904                         exit(0);
905                 }
906
907                 memcpy(&Writep, &tmpPtr, sizeof(tmpPtr));
908                 probeBlockEnd();
909         }
910
911         if((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) {
912                 setProbePoint(&probeInfo);
913                 nWritten = Tell();
914                 WcharToChar(temp_buf, buffer.GetPointer());
915                 if(E_SUCCESS == File::GetAttributes(this->GetName(), attr))
916                         size = attr.GetFileSize();
917                 WcharToChar(temp_path, this->GetName().GetPointer());
918
919                 PREPARE_LOCAL_BUF();
920                 PACK_COMMON_BEGIN(MSG_PROBE_RESOURCE,
921                                   API_ID_result_File__Write_const_Tizen__Base__String__buffer_,
922                                   "s", temp_buf);
923                 PACK_COMMON_END('p', 0, 0, blockresult);
924                 PACK_RESOURCE(0, (unsigned long)this, FD_API_WRITE_START, size, temp_path);
925                 FLUSH_LOCAL_BUF();
926
927                 preBlockEnd();
928         }
929
930         ret = (this->*Writep)(buffer);
931
932         if(postBlockBegin(blockresult)) {
933                 setProbePoint(&probeInfo);
934                 WcharToChar(temp_buf,buffer.GetPointer());
935                 WcharToChar(temp_path,this->GetName().GetPointer());
936                 nWritten = Tell() - nWritten;
937                 if(E_SUCCESS == File::GetAttributes(this->GetName(),attr))
938                         size = attr.GetFileSize();
939                 nWritten = Tell() - nWritten;
940
941                 PREPARE_LOCAL_BUF();
942                 PACK_COMMON_BEGIN(MSG_PROBE_RESOURCE,
943                                   API_ID_result_File__Write_const_Tizen__Base__String__buffer_,
944                                   "s", temp_buf);
945                 PACK_COMMON_END('p', ret, ret, blockresult);
946                 PACK_RESOURCE(nWritten, (unsigned long)this, FD_API_WRITE_END, size, temp_path);
947                 FLUSH_LOCAL_BUF();
948
949                 postBlockEnd();
950         }
951         return ret;
952 }
953
954 File::~File(void) {
955         typedef void (File::*methodType)();
956         static methodType FileDp = 0;
957         probeInfo_t     probeInfo;
958         int blockresult;
959         bool bfiltering = true;
960         void *tmpPtr;
961         // FileAttributes attr;
962         long long size = 0L;
963
964         if (!FileDp) {
965                 probeBlockStart();
966
967                 tmpPtr = dlsym(RTLD_NEXT, "_ZN5Tizen2Io4FileD1Ev");
968
969                 if (tmpPtr == NULL || dlerror() != NULL) {
970                         perror("dlsym failed : Tizen::Io::File::~File");
971                         exit(0);
972                 }
973
974                 memcpy(&FileDp, &tmpPtr, sizeof(tmpPtr));
975                 probeBlockEnd();
976         }
977
978         if((blockresult = preBlockBegin(CALLER_ADDRESS, bfiltering, _sopt)) != 0) {
979                 setProbePoint(&probeInfo);
980 // error occur if File class was failed to contruct
981                 // if (ret == E_SUCCESS &&
982                 //     E_SUCCESS == File::GetAttributes(this->GetName(), attr))
983                 //     size = attr.GetFileSize();
984                 preBlockEnd();
985         }
986
987         (this->*FileDp)();
988
989         if(postBlockBegin(blockresult)) {
990
991                 PREPARE_LOCAL_BUF();
992                 PACK_COMMON_BEGIN(MSG_PROBE_RESOURCE,
993                                   API_ID_File___File_void_,
994                                   "", 0);
995                 PACK_COMMON_END('p', 0, 0, blockresult);
996                 PACK_RESOURCE(0, (unsigned long)this, FD_API_CLOSE, size, "");
997                 FLUSH_LOCAL_BUF();
998
999                 postBlockEnd();
1000         }
1001 }
1002
1003
1004 // static methods
1005 //static result File::ConvertToSecureFile(const Tizen::Base::String &plainFilePath,
1006 //              const Tizen::Base::String &secureFilePath) {
1007 //      typedef result (File::*methodType)(
1008 //                      const Tizen::Base::String &plainFilePath,
1009 //                      const Tizen::Base::String &secureFilePath);
1010 //      static methodType ConvertToSecureFilep = 0;
1011 //
1012 //}
1013 //static result File::ConvertToSecureFile(const Tizen::Base::String &plainFilePath,
1014 //              const Tizen::Base::String &secureFilePath,
1015 //              const Tizen::Base::ByteBuffer& key) {
1016 //      typedef result (File::*methodType)(
1017 //                      const Tizen::Base::String &plainFilePath,
1018 //                      const Tizen::Base::String &secureFilePath,
1019 //                      const Tizen::Base::ByteBuffer& key);
1020 //      static methodType ConvertToSecureFilep = 0;
1021 //
1022 //}
1023 //static result File::Copy(const Tizen::Base::String& srcFilePath,
1024 //              const Tizen::Base::String& destFilePath, bool failIfExist) {
1025 //      typedef result (File::*methodType)(const Tizen::Base::String& srcFilePath,
1026 //                      const Tizen::Base::String& destFilePath, bool failIfExist);
1027 //      static methodType Copyp = 0;
1028 //
1029 //}
1030 //static result File::GetAttributes(const Tizen::Base::String& filePath,
1031 //              FileAttributes& attribute) {
1032 //      typedef result (File::*methodType)(const Tizen::Base::String& filePath,
1033 //                      FileAttributes& attribute);
1034 //      static methodType GetAttributesp = 0;
1035 //
1036 //}
1037 //static const Tizen::Base::String File::GetFileExtension(
1038 //              const Tizen::Base::String& filePath) {
1039 //      typedef const Tizen::Base::String (File::*methodType)(
1040 //                      const Tizen::Base::String& filePath);
1041 //      static methodType GetFileExtensionp = 0;
1042 //
1043 //}
1044 //const Tizen::Base::String File::GetFileName(
1045 //              const Tizen::Base::String& filePath) {
1046 //      typedef const Tizen::Base::String (File::*methodType)(
1047 //                      const Tizen::Base::String& filePath);
1048 //      static methodType GetFileNamep = 0;
1049 //      Tizen::Base::String ret;
1050 //
1051 //      if (!GetFileNamep) {
1052 //                      probeBlockStart();
1053 //                      void *tmpPtr = dlsym(RTLD_NEXT,
1054 //                                      "_ZN5Tizen2Io4File11GetFileNameERKNS_4Base6StringE");
1055 //
1056 //                      if (tmpPtr == NULL || dlerror() != NULL) {
1057 //                              perror("dlsym failed : Tizen::Io::File::GetFileName");
1058 //                              exit(0);
1059 //                      }
1060 //
1061 //                      memcpy(&GetFileNamep, &tmpPtr, sizeof(tmpPtr));
1062 //                      probeBlockEnd();
1063 //              }
1064 //      ret = (File::(*GetFileNamep))(filePath);
1065 //
1066 //return ret;
1067 //}
1068 //static bool File::IsEncrypted(const Tizen::Base::String &filePath) {
1069 //      typedef bool (File::*methodType)(const Tizen::Base::String &filePath);
1070 //      static methodType IsEncryptedp = 0;
1071 //
1072 //}
1073 //static bool File::IsFileExist(const Tizen::Base::String& filePath) {
1074 //      typedef bool (File::*methodType)(const Tizen::Base::String& filePath);
1075 //      static methodType IsFileExistp = 0;
1076 //
1077 //}
1078 //static result File::Move(const Tizen::Base::String& oldFilePath,
1079 //              const Tizen::Base::String& newFilePath) {
1080 //      typedef result (File::*methodType)(const Tizen::Base::String& oldFilePath,
1081 //                      const Tizen::Base::String& newFilePath);
1082 //      static methodType Movep = 0;
1083 //
1084 //}
1085 //static result File::Remove(const Tizen::Base::String& filePath) {
1086 //      typedef result (File::*methodType)(const Tizen::Base::String& filePath);
1087 //      static methodType Removep = 0;
1088 //
1089 //}
1090
1091 }
1092 }