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