db_pipes.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /* -*- mode:c; c-file-style:"k&r"; c-basic-offset: 4; tab-width:4; indent-tabs-mode:nil; mode:auto-fill; fill-column:78; -*- */
  2. /* vim: set ts=4 sw=4 et tw=78 fo=cqt wm=0: */
  3. /* Copyright (C) 2014 Stony Brook University
  4. This file is part of Graphene Library OS.
  5. Graphene Library OS is free software: you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public License
  7. as published by the Free Software Foundation, either version 3 of the
  8. License, or (at your option) any later version.
  9. Graphene Library OS is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  15. /*
  16. * db_pipes.c
  17. *
  18. * This file contains oeprands to handle streams with URIs that start with
  19. * "pipe:" or "pipe.srv:".
  20. */
  21. #include "pal_defs.h"
  22. #include "pal.h"
  23. #include "pal_internal.h"
  24. #include "pal_error.h"
  25. #include "pal_debug.h"
  26. #include "api.h"
  27. static int pipe_listen (PAL_HANDLE * handle, PAL_NUM pipeid, int create)
  28. {
  29. return -PAL_ERROR_NOTIMPLEMENTED;
  30. }
  31. static int pipe_waitforclient (PAL_HANDLE handle, PAL_HANDLE *client)
  32. {
  33. return -PAL_ERROR_NOTIMPLEMENTED;
  34. }
  35. static int pipe_connect (PAL_HANDLE * handle, PAL_NUM pipeid, PAL_IDX connid,
  36. int create)
  37. {
  38. return -PAL_ERROR_NOTIMPLEMENTED;
  39. }
  40. static int pipe_private (PAL_HANDLE * handle)
  41. {
  42. return -PAL_ERROR_NOTIMPLEMENTED;
  43. }
  44. /* 'open' operation of pipe stream. For each pipe stream, it is
  45. identified by a decimal number in URI. There could be two
  46. types: pipe and pipe.srv. They behave pretty much the same,
  47. except they are two ends of the pipe. */
  48. static int pipe_open (PAL_HANDLE *handle, const char * type,
  49. const char * uri, int access, int share,
  50. int create, int options)
  51. {
  52. if (strpartcmp_static(type, "pipe:") && !*uri)
  53. return pipe_private(handle);
  54. char * endptr;
  55. PAL_NUM pipeid = strtol(uri, &endptr, 10);
  56. PAL_IDX connid = 0;
  57. if (*endptr == ':') {
  58. if (create & PAL_CREAT_TRY)
  59. return -PAL_ERROR_INVAL;
  60. connid = strtol(endptr + 1, &endptr, 10);
  61. }
  62. if (*endptr)
  63. return -PAL_ERROR_INVAL;
  64. if (strpartcmp_static(type, "pipe.srv:"))
  65. return pipe_listen(handle, pipeid, create);
  66. if (strpartcmp_static(type, "pipe:"))
  67. return pipe_connect(handle, pipeid, connid, create);
  68. return -PAL_ERROR_INVAL;
  69. }
  70. /* 'read' operation of pipe stream. offset does not apply here. */
  71. static int pipe_read (PAL_HANDLE handle, int offset, int len,
  72. void * buffer)
  73. {
  74. return -PAL_ERROR_NOTIMPLEMENTED;
  75. }
  76. /* 'write' operation of pipe stream. offset does not apply here. */
  77. static int pipe_write (PAL_HANDLE handle, int offset, int len,
  78. const void * buffer)
  79. {
  80. return -PAL_ERROR_NOTIMPLEMENTED;
  81. }
  82. /* 'close' operation of pipe stream. */
  83. static int pipe_close (PAL_HANDLE handle)
  84. {
  85. return -PAL_ERROR_NOTIMPLEMENTED;
  86. }
  87. /* 'delete' operation of pipe stream. */
  88. static int pipe_delete (PAL_HANDLE handle, int access)
  89. {
  90. return -PAL_ERROR_NOTIMPLEMENTED;
  91. }
  92. static int pipe_getname (PAL_HANDLE handle, char * buffer, int count)
  93. {
  94. return -PAL_ERROR_NOTIMPLEMENTED;
  95. }
  96. struct handle_ops pipe_ops = {
  97. .getname = &pipe_getname,
  98. .open = &pipe_open,
  99. .waitforclient = &pipe_waitforclient,
  100. .read = &pipe_read,
  101. .write = &pipe_write,
  102. .close = &pipe_close,
  103. .delete = &pipe_delete,
  104. };
  105. struct handle_ops pipeprv_ops = {
  106. .open = &pipe_open,
  107. .read = &pipe_read,
  108. .write = &pipe_write,
  109. .close = &pipe_close,
  110. };