]> git.ipfire.org Git - thirdparty/plymouth.git/commitdiff
Improve the ply-terminal api
authorRay Strode <rstrode@redhat.com>
Wed, 16 May 2007 20:29:22 +0000 (16:29 -0400)
committerRay Strode <rstrode@redhat.com>
Wed, 16 May 2007 20:29:22 +0000 (16:29 -0400)
Previously, the api for creating the pseudo-terminal
was ply_terminal_open ().  This is a bit confusing of an api
because often a program will want to open the pseudo-terminal
after creating it, so you end up with:

ply_terminal_open (terminal);
pts_fd = open (ply_terminal_get_name (terminal), O_RDWR);

or whatever. Now it would be something like:

ply_terminal_create_device (terminal);
device_name = ply_terminal_get_device_name (terminal);
pts_fd = open (device_name, O_RDWR);

which I think is a little clearer.

src/ply-terminal.c
src/ply-terminal.h

index 196ff3a0d507495093c2a432b2fd1ce695ee10a6..1f0f113b377f48d4a5223a33a66e44cd30f12c80 100644 (file)
@@ -58,17 +58,17 @@ ply_terminal_free (ply_terminal_t *terminal)
 {
   assert (terminal != NULL);
 
-  ply_terminal_close (terminal);
+  ply_terminal_destroy_device (terminal);
   free (terminal);
 }
 
 bool
-ply_terminal_open (ply_terminal_t *terminal)
+ply_terminal_create_device (ply_terminal_t *terminal)
 {
   int saved_errno;
 
   assert (terminal != NULL);
-  assert (!ply_terminal_is_open (terminal));
+  assert (!ply_terminal_has_device (terminal));
 
   terminal->fd = posix_openpt (O_RDWR | O_NOCTTY);
 
@@ -78,7 +78,7 @@ ply_terminal_open (ply_terminal_t *terminal)
   if (grantpt (terminal->fd) < 0)
     {
       saved_errno = errno;
-      ply_terminal_close (terminal);
+      ply_terminal_destroy_device (terminal);
       errno = saved_errno;
       return false;
     }
@@ -86,7 +86,7 @@ ply_terminal_open (ply_terminal_t *terminal)
   if (unlockpt (terminal->fd) < 0)
     {
       saved_errno = errno;
-      ply_terminal_close (terminal);
+      ply_terminal_destroy_device (terminal);
       errno = saved_errno;
       return false;
     }
@@ -97,7 +97,7 @@ ply_terminal_open (ply_terminal_t *terminal)
 }
 
 bool
-ply_terminal_is_open (ply_terminal_t *terminal)
+ply_terminal_has_device (ply_terminal_t *terminal)
 {
   assert (terminal != NULL);
 
@@ -105,7 +105,7 @@ ply_terminal_is_open (ply_terminal_t *terminal)
 }
 
 void
-ply_terminal_close (ply_terminal_t *terminal)
+ply_terminal_destroy_device (ply_terminal_t *terminal)
 {
   assert (terminal != NULL);
 
@@ -125,10 +125,10 @@ ply_terminal_get_fd (ply_terminal_t *terminal)
 }
 
 const char *
-ply_terminal_get_name (ply_terminal_t *terminal)
+ply_terminal_get_device_name (ply_terminal_t *terminal)
 {
   assert (terminal != NULL);
-  assert (ply_terminal_is_open (terminal));
+  assert (ply_terminal_has_device (terminal));
 
   assert (terminal->name != NULL);
   return terminal->name;
@@ -151,14 +151,14 @@ main (int    argc,
 
   terminal = ply_terminal_new ();
 
-  if (!ply_terminal_open (terminal))
+  if (!ply_terminal_create_device (terminal))
     {
       exit_code = errno;
       perror ("could not open new terminal");
       return exit_code;
     }
 
-  name = ply_terminal_get_name (terminal);
+  name = ply_terminal_get_device_name (terminal);
   printf ("terminal name is '%s'\n", name);
 
   while (read (ply_terminal_get_fd (terminal), 
index 4821ed2671e1ebf178e0be8828c89b57328a99e1..ae9aa331501add78e2eb58b2afad018e79dd74b3 100644 (file)
@@ -31,11 +31,11 @@ typedef struct _ply_terminal ply_terminal_t;
 #ifndef PLY_HIDE_FUNCTION_DECLARATIONS
 ply_terminal_t *ply_terminal_new ();
 void ply_terminal_free (ply_terminal_t *terminal);
-bool ply_terminal_open (ply_terminal_t *terminal);
-bool ply_terminal_is_open (ply_terminal_t *terminal);
-void ply_terminal_close (ply_terminal_t *terminal);
+bool ply_terminal_create_device (ply_terminal_t *terminal);
+bool ply_terminal_has_device (ply_terminal_t *terminal);
+void ply_terminal_destroy_device (ply_terminal_t *terminal);
 int ply_terminal_get_fd (ply_terminal_t *terminal);
-const char *ply_terminal_get_name (ply_terminal_t *terminal);
+const char *ply_terminal_get_device_name (ply_terminal_t *terminal);
 #endif
 
 #endif /* PLY_TERMINAL_H */