| 1 |
/* sysprof-document-file-chunk.c |
| 2 |
* |
| 3 |
* Copyright 2023 Christian Hergert <[email protected]> |
| 4 |
* |
| 5 |
* This program is free software: you can redistribute it and/or modify |
| 6 |
* it under the terms of the GNU General Public License as published by |
| 7 |
* the Free Software Foundation, either version 3 of the License, or |
| 8 |
* (at your option) any later version. |
| 9 |
* |
| 10 |
* This program is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
* GNU General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License |
| 16 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
* |
| 18 |
* SPDX-License-Identifier: GPL-3.0-or-later |
| 19 |
*/ |
| 20 |
|
| 21 |
#include "config.h" |
| 22 |
|
| 23 |
#include "sysprof-document-frame-private.h" |
| 24 |
|
| 25 |
#include "sysprof-document-file-chunk.h" |
| 26 |
|
| 27 |
struct _SysprofDocumentFileChunk |
| 28 |
{ |
| 29 |
SysprofDocumentFrame parent_instance; |
| 30 |
}; |
| 31 |
|
| 32 |
struct _SysprofDocumentFileChunkClass |
| 33 |
{ |
| 34 |
SysprofDocumentFrameClass parent_instance; |
| 35 |
}; |
| 36 |
|
| 37 |
enum { |
| 38 |
PROP_0, |
| 39 |
PROP_IS_LAST, |
| 40 |
PROP_SIZE, |
| 41 |
PROP_PATH, |
| 42 |
N_PROPS |
| 43 |
}; |
| 44 |
|
| 45 |
G_DEFINE_FINAL_TYPE (SysprofDocumentFileChunk, sysprof_document_file_chunk, SYSPROF_TYPE_DOCUMENT_FRAME) |
| 46 |
|
| 47 |
static GParamSpec *properties [N_PROPS]; |
| 48 |
|
| 49 |
static void |
| 50 |
sysprof_document_file_chunk_get_property (GObject *object, |
| 51 |
guint prop_id, |
| 52 |
GValue *value, |
| 53 |
GParamSpec *pspec) |
| 54 |
{ |
| 55 |
SysprofDocumentFileChunk *self = SYSPROF_DOCUMENT_FILE_CHUNK (object); |
| 56 |
|
| 57 |
switch (prop_id) |
| 58 |
{ |
| 59 |
case PROP_IS_LAST: |
| 60 |
g_value_set_boolean (value, sysprof_document_file_chunk_get_is_last (self)); |
| 61 |
break; |
| 62 |
|
| 63 |
case PROP_SIZE: |
| 64 |
g_value_set_uint (value, sysprof_document_file_chunk_get_size (self)); |
| 65 |
break; |
| 66 |
|
| 67 |
case PROP_PATH: |
| 68 |
g_value_set_string (value, sysprof_document_file_chunk_get_path (self)); |
| 69 |
break; |
| 70 |
|
| 71 |
default: |
| 72 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
static void |
| 77 |
sysprof_document_file_chunk_class_init (SysprofDocumentFileChunkClass *klass) |
| 78 |
{ |
| 79 |
GObjectClass *object_class = G_OBJECT_CLASS (klass); |
| 80 |
|
| 81 |
object_class->get_property = sysprof_document_file_chunk_get_property; |
| 82 |
|
| 83 |
properties [PROP_IS_LAST] = |
| 84 |
g_param_spec_boolean ("is-last", NULL, NULL, |
| 85 |
FALSE, |
| 86 |
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); |
| 87 |
|
| 88 |
properties [PROP_SIZE] = |
| 89 |
g_param_spec_uint ("size", NULL, NULL, |
| 90 |
0, G_MAXUINT16, 0, |
| 91 |
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); |
| 92 |
|
| 93 |
properties [PROP_PATH] = |
| 94 |
g_param_spec_string ("path", NULL, NULL, |
| 95 |
NULL, |
| 96 |
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); |
| 97 |
|
| 98 |
g_object_class_install_properties (object_class, N_PROPS, properties); |
| 99 |
} |
| 100 |
|
| 101 |
static void |
| 102 |
sysprof_document_file_chunk_init (SysprofDocumentFileChunk *self) |
| 103 |
{ |
| 104 |
} |
| 105 |
|
| 106 |
gboolean |
| 107 |
sysprof_document_file_chunk_get_is_last (SysprofDocumentFileChunk *self) |
| 108 |
{ |
| 109 |
const SysprofCaptureFileChunk *file_chunk; |
| 110 |
|
| 111 |
g_return_val_if_fail (SYSPROF_IS_DOCUMENT_FILE_CHUNK (self), FALSE); |
| 112 |
|
| 113 |
file_chunk = SYSPROF_DOCUMENT_FRAME_GET (self, SysprofCaptureFileChunk); |
| 114 |
|
| 115 |
return file_chunk->is_last; |
| 116 |
} |
| 117 |
|
| 118 |
guint |
| 119 |
sysprof_document_file_chunk_get_size (SysprofDocumentFileChunk *self) |
| 120 |
{ |
| 121 |
const SysprofCaptureFileChunk *file_chunk; |
| 122 |
|
| 123 |
g_return_val_if_fail (SYSPROF_IS_DOCUMENT_FILE_CHUNK (self), FALSE); |
| 124 |
|
| 125 |
file_chunk = SYSPROF_DOCUMENT_FRAME_GET (self, SysprofCaptureFileChunk); |
| 126 |
|
| 127 |
return SYSPROF_DOCUMENT_FRAME_UINT16 (self, file_chunk->len); |
| 128 |
} |
| 129 |
|
| 130 |
const char * |
| 131 |
sysprof_document_file_chunk_get_path (SysprofDocumentFileChunk *self) |
| 132 |
{ |
| 133 |
const SysprofCaptureFileChunk *file_chunk; |
| 134 |
|
| 135 |
g_return_val_if_fail (SYSPROF_IS_DOCUMENT_FILE_CHUNK (self), FALSE); |
| 136 |
|
| 137 |
file_chunk = SYSPROF_DOCUMENT_FRAME_GET (self, SysprofCaptureFileChunk); |
| 138 |
|
| 139 |
return SYSPROF_DOCUMENT_FRAME_CSTRING (self, file_chunk->path); |
| 140 |
} |
| 141 |
|
| 142 |
const guint8 * |
| 143 |
sysprof_document_file_chunk_get_data (SysprofDocumentFileChunk *self, |
| 144 |
guint *size) |
| 145 |
{ |
| 146 |
const SysprofCaptureFileChunk *file_chunk; |
| 147 |
|
| 148 |
g_return_val_if_fail (SYSPROF_IS_DOCUMENT_FILE_CHUNK (self), FALSE); |
| 149 |
|
| 150 |
file_chunk = SYSPROF_DOCUMENT_FRAME_GET (self, SysprofCaptureFileChunk); |
| 151 |
|
| 152 |
if (size != NULL) |
| 153 |
*size = sysprof_document_file_chunk_get_size (self); |
| 154 |
|
| 155 |
return file_chunk->data; |
| 156 |
} |