transaction: Initial commit to create a transaction id

Create a README file to describe the transaction id.
Hash specialization to create a unique transaction id
by combining the hash values of the dbus bus name and
message cookie.

Change-Id: Ida52774857a7ed2cca9364da15f84a30d2c3af06
Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
diff --git a/Makefile.am b/Makefile.am
index 78ab597..377c62d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -16,6 +16,7 @@
 	sdbusplus/server/manager.hpp \
 	sdbusplus/server/match.hpp \
 	sdbusplus/server/object.hpp \
+	sdbusplus/server/transaction.hpp \
 	sdbusplus/slot.hpp \
 	sdbusplus/utility/tuple_to_array.hpp \
 	sdbusplus/utility/type_traits.hpp \
diff --git a/sdbusplus/server.hpp b/sdbusplus/server.hpp
index 468bd98..22bf440 100644
--- a/sdbusplus/server.hpp
+++ b/sdbusplus/server.hpp
@@ -8,3 +8,4 @@
 #include <sdbusplus/server/object.hpp>
 #include <sdbusplus/server/match.hpp>
 #include <sdbusplus/server/bindings.hpp>
+#include <sdbusplus/server/transaction.hpp>
diff --git a/sdbusplus/server/README.md b/sdbusplus/server/README.md
new file mode 100644
index 0000000..c369b57
--- /dev/null
+++ b/sdbusplus/server/README.md
@@ -0,0 +1,28 @@
+# transaction.hpp
+
+Handles the generation and maintenance of the _transaction id_.
+
+**What is _transaction id_** - A unique identifier created by hashing the bus
+name and message cookie from a dbus call. The bus name (unique to each
+application) and message cookie (unique within each bus peer) allows each dbus
+message to be uniquely identifed.
+
+**When is _transaction id_ generated** - When an error response message is
+created, and whenever the id is requested and has not been initialized yet.
+
+**Where is _transaction id_ stored** - In the exception object when an
+application error occurs.
+
+**How is _transaction id_ used** - Used to identify all the journal entries
+associated with a dbus operation.
+
+* When a journal entry is created, the _transaction id_ is added as metadata.
+Therefore all journal entries created within a message have the same
+_transaction id_ value.
+
+* When an error/event log is created, the _transaction id_ of that message will
+be used to collect the journal entries associated with that message, providing
+debug information for the complete operation.
+
+**Multiple _transaction ids_** - The exception object can store multiple
+_transaction ids_ for operations that create multiple messages.
diff --git a/sdbusplus/server/transaction.hpp b/sdbusplus/server/transaction.hpp
new file mode 100644
index 0000000..c23bc04
--- /dev/null
+++ b/sdbusplus/server/transaction.hpp
@@ -0,0 +1,68 @@
+#pragma once
+
+#include <sdbusplus/bus.hpp>
+
+namespace sdbusplus
+{
+namespace server
+{
+namespace transaction
+{
+
+struct Transaction
+{
+    Transaction(sdbusplus::bus::bus &bus, sdbusplus::message::message& msg):
+        bus(bus), msg(msg) {}
+
+    sdbusplus::bus::bus& bus;
+    sdbusplus::message::message& msg;
+};
+
+} // namespace transaction
+} // namespace server
+} // namespace sdbusplus
+
+namespace std
+{
+
+/** @ brief Overload of std::hash for sdbusplus::bus::bus */
+template <>
+struct hash<sdbusplus::bus::bus>
+{
+    auto operator()
+        (sdbusplus::bus::bus& b) const
+    {
+        auto name = b.get_unique_name();
+        return std::hash<std::string>{}(name);
+    }
+};
+
+/** @ brief Overload of std::hash for sdbusplus::message::message */
+template <>
+struct hash<sdbusplus::message::message>
+{
+    auto operator()
+        (sdbusplus::message::message& m) const
+    {
+        auto cookie = m.get_cookie();
+        return std::hash<uint64_t>{}(cookie);
+    }
+};
+
+/** @ brief Overload of std::hash for Transaction */
+template <>
+struct hash<sdbusplus::server::transaction::Transaction>
+{
+    auto operator()
+        (sdbusplus::server::transaction::Transaction const& t) const
+    {
+        auto hash1 = std::hash<sdbusplus::bus::bus>{}(t.bus);
+        auto hash2 = std::hash<sdbusplus::message::message>{}(t.msg);
+
+        // boost::hash_combine() algorithm.
+        return static_cast<size_t>(hash1 ^ (hash2 + 0x9e3779b9 + (hash1 << 6) +
+            (hash1 >> 2)));
+    }
+};
+
+} // namespace std