-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
262 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** @file value.h | ||
* @brief Value function prototypes | ||
* | ||
* This file contains the function prototypes for arbitary values, | ||
* which are used for linked lists. | ||
*/ | ||
#ifndef FUSE_VALUE_H | ||
#define FUSE_VALUE_H | ||
|
||
#include "fuse.h" | ||
|
||
/** @brief Value defintion | ||
*/ | ||
typedef struct fuse_value_instance fuse_value_t; | ||
|
||
/** @brief Create a new NULL value | ||
* @param fuse The fuse application | ||
* @returns A NULL value | ||
*/ | ||
fuse_value_t *fuse_new_null(fuse_t *fuse); | ||
|
||
/** @brief Create a new pointer value | ||
* | ||
* The pointer value can be used to store a pointer to an arbitary value, | ||
* including a NULL pointer. | ||
* | ||
* @param fuse The fuse application | ||
* @param ptr The pointer to store | ||
* @returns A pointer value | ||
*/ | ||
fuse_value_t *fuse_new_ptr(fuse_t *fuse, void *ptr); | ||
|
||
/** @brief Return the pointer value | ||
*/ | ||
void *fuse_ptr(fuse_value_t *value); | ||
|
||
/** @brief Return the value as a zero-terminated JSON value | ||
*/ | ||
const char *fuse_jsonstring(fuse_value_t *value); | ||
|
||
/** @brief Return true if the value contains NULL | ||
*/ | ||
bool fuse_equal_null(fuse_value_t *value); | ||
|
||
#endif // FUSE_VALUE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#include <string.h> | ||
#include <fuse/fuse.h> | ||
|
||
// Private includes | ||
#include "value.h" | ||
|
||
/////////////////////////////////////////////////////////////////////////////// | ||
// PUBLIC METHODS | ||
|
||
inline fuse_value_t *fuse_new_null(fuse_t *fuse) | ||
{ | ||
assert(fuse); | ||
return fuse_new_ptr(fuse, NULL); | ||
} | ||
|
||
fuse_value_t *fuse_new_ptr(fuse_t *fuse, void *ptr) { | ||
assert(fuse); | ||
|
||
// Allocate memory for the value | ||
fuse_value_t *value = fuse_alloc(fuse, sizeof(fuse_value_t)); | ||
if (value == NULL) | ||
{ | ||
return NULL; | ||
} | ||
|
||
// Zero all data structures | ||
memset(value, 0, sizeof(fuse_value_t)); | ||
|
||
// Set the pointer | ||
value->ptr = ptr; | ||
|
||
// Return the value | ||
return value; | ||
} | ||
|
||
inline bool fuse_equal_null(fuse_value_t *value) | ||
{ | ||
assert(value); | ||
return value->ptr == NULL; | ||
} | ||
|
||
inline void* fuse_ptr(fuse_value_t *value) | ||
{ | ||
assert(value); | ||
return value->ptr; | ||
} | ||
|
||
const char *fuse_jsonstring(fuse_value_t *value) | ||
{ | ||
assert(value); | ||
// Simple case where value is NULL | ||
if(value->ptr == NULL) | ||
{ | ||
return "null"; | ||
} | ||
|
||
// Other use-cases here | ||
assert(false); | ||
return NULL; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** @file value.h | ||
* @brief Private function prototypes and structure definitions for values | ||
*/ | ||
#ifndef FUSE_PRIVATE_VALUE_H | ||
#define FUSE_PRIVATE_VALUE_H | ||
|
||
#include <fuse/fuse.h> | ||
|
||
/** @brief Represents a value | ||
* | ||
* This data structure represents an arbitary value, including NULL values | ||
*/ | ||
struct fuse_value_instance | ||
{ | ||
void *ptr; ///< A pointer to the value storage | ||
struct fuse_value_instance *prev; ///< The previous value in the list (when the value is part of a list) | ||
struct fuse_value_instance *next; ///< The next value in the list (when the value is part of a list) | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
set(NAME "value") | ||
add_executable(${NAME} | ||
main.c | ||
) | ||
|
||
target_include_directories(${NAME} PRIVATE | ||
${CMAKE_CURRENT_LIST_DIR}/../../include | ||
) | ||
|
||
target_link_libraries(${NAME} | ||
fuse | ||
) |
Oops, something went wrong.