summaryrefslogtreecommitdiff
path: root/examples/DLL
diff options
context:
space:
mode:
authorkirthika <kirthika@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1998-11-26 07:58:58 +0000
committerkirthika <kirthika@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1998-11-26 07:58:58 +0000
commit1a7711dbb8fdadae715b1a6a11d1f7c9df873fab (patch)
treec889440a61accf2e4a6aa512862c73efbc77f16a /examples/DLL
parent9ed8b6f20327da8a3f3cb92559c2008791f55e85 (diff)
downloadATCD-1a7711dbb8fdadae715b1a6a11d1f7c9df873fab.tar.gz
*** empty log message ***
Diffstat (limited to 'examples/DLL')
-rw-r--r--examples/DLL/Magazine.h23
-rw-r--r--examples/DLL/Makefile45
-rw-r--r--examples/DLL/Newsweek.cpp24
-rw-r--r--examples/DLL/Newsweek.h27
-rw-r--r--examples/DLL/Today.cpp26
-rw-r--r--examples/DLL/Today.h27
-rw-r--r--examples/DLL/test_dll.cpp73
7 files changed, 245 insertions, 0 deletions
diff --git a/examples/DLL/Magazine.h b/examples/DLL/Magazine.h
new file mode 100644
index 00000000000..f1df7f506dd
--- /dev/null
+++ b/examples/DLL/Magazine.h
@@ -0,0 +1,23 @@
+// $Id$
+
+#ifndef MAGAZINE_H
+#define MAGAZINE_H
+
+class Magazine
+{
+ //= TITLE
+ // This is an abstract class used in the DLL example.
+ //
+ //= DESCRIPTION
+ // This class simply is an inetrface which the derived classes will
+ // exploit.
+ public:
+
+ // No-op virtual destructor.
+ virtual ~Magazine (void) {};
+
+ // This method gives the title of the magazine.
+ virtual void title (void) = 0;
+};
+
+#endif /* MAGAZINE_H */
diff --git a/examples/DLL/Makefile b/examples/DLL/Makefile
new file mode 100644
index 00000000000..c0e0584a8db
--- /dev/null
+++ b/examples/DLL/Makefile
@@ -0,0 +1,45 @@
+#----------------------------------------------------------------------------
+# $Id$
+#
+# Makefile for the miscellaneous Reactor examples
+#----------------------------------------------------------------------------
+
+#----------------------------------------------------------------------------
+# Local macros
+#----------------------------------------------------------------------------
+
+BIN = test_dll
+SHLIB = libToday.$(SOEXT) \
+ libNewsweek.$(SOEXT)
+
+FILES = Today \
+ Newsweek
+
+PSRC = $(addsuffix .cpp,$(BIN))
+LSRC = $(addsuffix .cpp,$(FILES))
+
+VLDLIBS = $(LDLIBS:%=%$(VAR))
+
+BUILD = $(VSHLIB) $(VBIN)
+
+#----------------------------------------------------------------------------
+# Include macros and targets
+#----------------------------------------------------------------------------
+
+include $(ACE_ROOT)/include/makeinclude/wrapper_macros.GNU
+include $(ACE_ROOT)/include/makeinclude/macros.GNU
+include $(ACE_ROOT)/include/makeinclude/rules.common.GNU
+include $(ACE_ROOT)/include/makeinclude/rules.nonested.GNU
+include $(ACE_ROOT)/include/makeinclude/rules.lib.GNU
+include $(ACE_ROOT)/include/makeinclude/rules.bin.GNU
+include $(ACE_ROOT)/include/makeinclude/rules.local.GNU
+
+#----------------------------------------------------------------------------
+# Local targets
+#----------------------------------------------------------------------------
+
+#----------------------------------------------------------------------------
+# Dependencies
+#----------------------------------------------------------------------------
+# DO NOT DELETE THIS LINE -- g++dep uses it.
+# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.
diff --git a/examples/DLL/Newsweek.cpp b/examples/DLL/Newsweek.cpp
new file mode 100644
index 00000000000..c689edacc0a
--- /dev/null
+++ b/examples/DLL/Newsweek.cpp
@@ -0,0 +1,24 @@
+// $Id$
+
+#include "Newsweek.h"
+
+// Implementation of the abstract class method which describes
+// the magazine.
+void Newsweek::title (void)
+{
+ ACE_DEBUG ((LM_DEBUG,
+ "Newsweek: Vol 23 Dec87\n"));
+}
+
+// Returns the Newsweek class pointer.
+extern "C"
+
+Magazine *
+create_magazine (void)
+{
+ Magazine *mag;
+ ACE_NEW_RETURN (mag,
+ Newsweek,
+ 0);
+ return mag;
+}
diff --git a/examples/DLL/Newsweek.h b/examples/DLL/Newsweek.h
new file mode 100644
index 00000000000..850bc507cdb
--- /dev/null
+++ b/examples/DLL/Newsweek.h
@@ -0,0 +1,27 @@
+// $Id$
+
+#ifndef NEWSWEEK_H
+#define NEWSWEEK_H
+
+#include "ace/OS.h"
+#include "Magazine.h"
+
+#if !defined (ACE_LACKS_PRAGMA_ONCE)
+# pragma once
+#endif /* ACE_LACKS_PRAGMA_ONCE */
+
+class Newsweek : public Magazine
+{
+ //= TITLE
+ // This is an derived class of Magazine.
+ //
+ //= DESCRIPTION
+ // Polymoriphism is exploited and an object pointer
+ // of Magazine is bound to the Newsweek object at runtime.
+ public:
+
+ // This is the abstract class method which describes the magazine.
+ void title (void);
+};
+
+# endif /* NEWSWEEK_H */
diff --git a/examples/DLL/Today.cpp b/examples/DLL/Today.cpp
new file mode 100644
index 00000000000..8c5f66ae4d6
--- /dev/null
+++ b/examples/DLL/Today.cpp
@@ -0,0 +1,26 @@
+// $Id$
+
+#include "Today.h"
+
+// Implementation of the abstract class method which describes the
+// magazine.
+void
+Today::title (void)
+{
+ ACE_DEBUG ((LM_DEBUG,
+ "Today: Information Technology Special Nov98\n"));
+}
+
+// Returns the pointer to the Today class.
+
+extern "C"
+
+Magazine *
+create_magazine (void)
+{
+ Magazine *mag;
+ ACE_NEW_RETURN (mag,
+ Today,
+ 0);
+ return mag;
+}
diff --git a/examples/DLL/Today.h b/examples/DLL/Today.h
new file mode 100644
index 00000000000..b2446fc952e
--- /dev/null
+++ b/examples/DLL/Today.h
@@ -0,0 +1,27 @@
+// $Id$
+
+#ifndef TODAY_H
+#define TODAY_H
+
+#include "ace/OS.h"
+#include "Magazine.h"
+
+#if !defined (ACE_LACKS_PRAGMA_ONCE)
+# pragma once
+#endif /* ACE_LACKS_PRAGMA_ONCE */
+
+class Today : public Magazine
+{
+ //= TITLE
+ // This is an derived class of Magazine.
+ //
+ //= DESCRIPTION
+ // Polymoriphism is exploited and an object pointer
+ // of Magazine is bound to the Today object at runtime.
+ public:
+
+ // The virtual abstract class method.
+ void title (void);
+};
+
+#endif /* TODAY_H */
diff --git a/examples/DLL/test_dll.cpp b/examples/DLL/test_dll.cpp
new file mode 100644
index 00000000000..63224923e95
--- /dev/null
+++ b/examples/DLL/test_dll.cpp
@@ -0,0 +1,73 @@
+// $Id$
+
+// This program tests out how the various objects can be loaded
+// dynamically and method calls made on them.
+
+#include "Magazine.h"
+#include "ace/DLL.h"
+#include "ace/Auto_Ptr.h"
+
+ACE_RCSID(DLL, test_dll, "$Id$")
+
+typedef Magazine* (*Magazine_Creator) (void);
+
+int
+main (void)
+{
+ ACE_DLL dll;
+
+ int retval = dll.open ("./" ACE_DLL_PREFIX "Today" ACE_DLL_SUFFIX);
+ if (retval != 0)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "%s",
+ dll.error ()),
+ -1);
+ Magazine_Creator mc;
+
+ mc = (Magazine_Creator) dll.symbol ("create_magazine");
+ if (mc == 0)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ dll.error ()),
+ -1);
+
+ Magazine *magazine = mc ();
+
+ magazine->title ();
+
+ delete magazine;
+
+ dll.close ();
+
+ // The other library is now loaded on demand.
+
+ retval = dll.open ("./" ACE_DLL_PREFIX "Newsweek" ACE_DLL_SUFFIX);
+ if (retval != 0)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "%s",
+ dll.error ()),
+ -1);
+
+ mc = (Magazine_Creator) dll.symbol ("create_magazine");
+ if (mc == 0)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ dll.error ()),
+ -1);
+
+ magazine = mc ();
+
+ magazine->title ();
+
+ delete magazine;
+
+ dll.close ();
+
+ return 0;
+}
+
+#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
+template class auto_ptr <Magazine>;
+#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
+#pragma instantiate auto_ptr <Magazine>
+#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */
+
+