2022-08-26 19:19:27 +08:00
|
|
|
// Copyright 2022 Memgraph Ltd.
|
|
|
|
//
|
|
|
|
// Use of this software is governed by the Business Source License
|
|
|
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
|
|
|
// License, and you may not use this file except in compliance with the Business Source License.
|
|
|
|
//
|
|
|
|
// As of the Change Date specified in that file, in accordance with
|
|
|
|
// the Business Source License, use of this software will be governed
|
|
|
|
// by the Apache License, Version 2.0, included in the file
|
|
|
|
// licenses/APL.txt.
|
|
|
|
|
2021-06-07 20:45:05 +08:00
|
|
|
#include "mg_procedure.h"
|
|
|
|
|
|
|
|
int *gVal = NULL;
|
|
|
|
|
|
|
|
void set_error(struct mgp_result *result) { mgp_result_set_error_msg(result, "Something went wrong"); }
|
|
|
|
|
2022-08-26 19:19:27 +08:00
|
|
|
static void procedure(struct mgp_list *args, struct mgp_graph *graph, struct mgp_result *result,
|
2021-06-07 20:45:05 +08:00
|
|
|
struct mgp_memory *memory) {
|
2021-09-09 16:44:47 +08:00
|
|
|
struct mgp_result_record *record = NULL;
|
|
|
|
const enum mgp_error new_record_err = mgp_result_new_record(result, &record);
|
|
|
|
if (new_record_err != MGP_ERROR_NO_ERROR) return set_error(result);
|
2021-06-07 20:45:05 +08:00
|
|
|
|
2021-09-09 16:44:47 +08:00
|
|
|
struct mgp_value *result_msg = NULL;
|
|
|
|
const enum mgp_error make_string_err = mgp_value_make_string("mgp_init_module allocation works", memory, &result_msg);
|
|
|
|
if (make_string_err != MGP_ERROR_NO_ERROR) return set_error(result);
|
2021-06-07 20:45:05 +08:00
|
|
|
|
2021-09-09 16:44:47 +08:00
|
|
|
const enum mgp_error result_inserted = mgp_result_record_insert(record, "result", result_msg);
|
2021-06-07 20:45:05 +08:00
|
|
|
mgp_value_destroy(result_msg);
|
2021-09-09 16:44:47 +08:00
|
|
|
if (result_inserted != MGP_ERROR_NO_ERROR) return set_error(result);
|
2021-06-07 20:45:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int mgp_init_module(struct mgp_module *module, struct mgp_memory *memory) {
|
|
|
|
const size_t one_gb = 1 << 30;
|
2022-08-26 19:19:27 +08:00
|
|
|
const enum mgp_error alloc_err = mgp_global_alloc(one_gb, (void **)(&gVal));
|
2021-09-09 16:44:47 +08:00
|
|
|
if (alloc_err != MGP_ERROR_NO_ERROR) return 1;
|
2021-06-07 20:45:05 +08:00
|
|
|
|
2021-09-09 16:44:47 +08:00
|
|
|
struct mgp_proc *proc = NULL;
|
|
|
|
const enum mgp_error proc_err = mgp_module_add_read_procedure(module, "procedure", procedure, &proc);
|
|
|
|
if (proc_err != MGP_ERROR_NO_ERROR) return 1;
|
2021-06-07 20:45:05 +08:00
|
|
|
|
2022-08-26 19:19:27 +08:00
|
|
|
struct mgp_type *string_type = NULL;
|
2021-09-09 16:44:47 +08:00
|
|
|
const enum mgp_error string_type_err = mgp_type_string(&string_type);
|
|
|
|
if (string_type_err != MGP_ERROR_NO_ERROR) return 1;
|
|
|
|
if (mgp_proc_add_result(proc, "result", string_type) != MGP_ERROR_NO_ERROR) return 1;
|
2021-06-07 20:45:05 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int mgp_shutdown_module() {
|
|
|
|
if (gVal) mgp_global_free(gVal);
|
|
|
|
return 0;
|
|
|
|
}
|