File: foundry-dap-debugger-source.c

package info (click to toggle)
foundry 1.1~beta-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 15,552 kB
  • sloc: ansic: 167,487; xml: 417; makefile: 21; sh: 19; javascript: 10
file content (113 lines) | stat: -rw-r--r-- 3,421 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/* foundry-dap-debugger-source.c
 *
 * Copyright 2025 Christian Hergert
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program. If not, see <http://www.gnu.org/licenses/>.
 *
 * SPDX-License-Identifier: LGPL-2.1-or-later
 */

#include "config.h"

#include "foundry-dap-debugger-source-private.h"
#include "foundry-json-node.h"

struct _FoundryDapDebuggerSource
{
  FoundryDebuggerSource parent_instance;
  GWeakRef debugger_wr;
  JsonNode *node;
};

G_DEFINE_FINAL_TYPE (FoundryDapDebuggerSource, foundry_dap_debugger_source, FOUNDRY_TYPE_DEBUGGER_SOURCE)

static char *
foundry_dap_debugger_source_dup_id (FoundryDebuggerSource *source)
{
  FoundryDapDebuggerSource *self = FOUNDRY_DAP_DEBUGGER_SOURCE (source);
  const char *name;

  /* TODO: Check sourceReference <int> */

  if (FOUNDRY_JSON_OBJECT_PARSE (self->node, "name", FOUNDRY_JSON_NODE_GET_STRING (&name)))
    return g_strdup (name);

  return NULL;
}

static char *
foundry_dap_debugger_source_dup_name (FoundryDebuggerSource *source)
{
  FoundryDapDebuggerSource *self = FOUNDRY_DAP_DEBUGGER_SOURCE (source);
  const char *name;

  if (FOUNDRY_JSON_OBJECT_PARSE (self->node, "name", FOUNDRY_JSON_NODE_GET_STRING (&name)))
    return g_strdup (name);

  return NULL;
}

static char *
foundry_dap_debugger_source_dup_path (FoundryDebuggerSource *source)
{
  FoundryDapDebuggerSource *self = FOUNDRY_DAP_DEBUGGER_SOURCE (source);
  const char *path;

  if (FOUNDRY_JSON_OBJECT_PARSE (self->node, "path", FOUNDRY_JSON_NODE_GET_STRING (&path)))
    return g_strdup (path);

  return NULL;
}

static void
foundry_dap_debugger_source_finalize (GObject *object)
{
  FoundryDapDebuggerSource *self = (FoundryDapDebuggerSource *)object;

  g_weak_ref_clear (&self->debugger_wr);
  g_clear_pointer (&self->node, json_node_unref);

  G_OBJECT_CLASS (foundry_dap_debugger_source_parent_class)->finalize (object);
}

static void
foundry_dap_debugger_source_class_init (FoundryDapDebuggerSourceClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
  FoundryDebuggerSourceClass *source_class = FOUNDRY_DEBUGGER_SOURCE_CLASS (klass);

  object_class->finalize = foundry_dap_debugger_source_finalize;

  source_class->dup_id = foundry_dap_debugger_source_dup_id;
  source_class->dup_name = foundry_dap_debugger_source_dup_name;
  source_class->dup_path = foundry_dap_debugger_source_dup_path;
}

static void
foundry_dap_debugger_source_init (FoundryDapDebuggerSource *self)
{
  g_weak_ref_init (&self->debugger_wr, NULL);
}

FoundryDebuggerSource *
foundry_dap_debugger_source_new (FoundryDapDebugger *debugger,
                                 JsonNode           *node)
{
  FoundryDapDebuggerSource *self = g_object_new (FOUNDRY_TYPE_DAP_DEBUGGER_SOURCE, NULL);

  g_weak_ref_set (&self->debugger_wr, debugger);
  self->node = json_node_ref (node);

  return FOUNDRY_DEBUGGER_SOURCE (self);
}