From 87b4f2b23f2250673c5cfecb4de21932b3ece394 Mon Sep 17 00:00:00 2001
From: David Garcia Quintas <dgq@google.com>
Date: Sun, 9 Aug 2015 13:52:19 -0700
Subject: [PATCH] wip. we need a way to pass args to server construction

---
 include/grpc/compression.h      |  1 +
 src/core/channel/channel_args.c | 42 +++++++++++++++++++++++++++++++++
 src/core/channel/channel_args.h | 14 +++++++++++
 test/cpp/interop/server.cc      |  2 --
 4 files changed, 57 insertions(+), 2 deletions(-)

diff --git a/include/grpc/compression.h b/include/grpc/compression.h
index e35fb03eb2a..a1a3236d3bf 100644
--- a/include/grpc/compression.h
+++ b/include/grpc/compression.h
@@ -42,6 +42,7 @@ extern "C" {
 
 /** To be used in channel arguments */
 #define GRPC_COMPRESSION_ALGORITHM_ARG "grpc.compression_algorithm"
+#define GRPC_COMPRESSION_ALGORITHM_STATE_ARG "grpc.compression_algorithm_state"
 
 /* The various compression algorithms supported by GRPC */
 typedef enum {
diff --git a/src/core/channel/channel_args.c b/src/core/channel/channel_args.c
index c430b56fa2d..77449c0df5f 100644
--- a/src/core/channel/channel_args.c
+++ b/src/core/channel/channel_args.c
@@ -37,6 +37,7 @@
 
 #include <grpc/support/alloc.h>
 #include <grpc/support/string_util.h>
+#include <grpc/support/useful.h>
 
 #include <string.h>
 
@@ -146,3 +147,44 @@ grpc_channel_args *grpc_channel_args_set_compression_algorithm(
   tmp.value.integer = algorithm;
   return grpc_channel_args_copy_and_add(a, &tmp, 1);
 }
+
+static gpr_uint32 find_compression_algorithm_states_bitset(
+    const grpc_channel_args *a) {
+  size_t i;
+  gpr_uint32 states_bitset = 0;
+  if (a == NULL) return 0;
+  for (i = 0; i < a->num_args; ++i) {
+    if (a->args[i].type == GRPC_ARG_INTEGER &&
+        !strcmp(GRPC_COMPRESSION_ALGORITHM_STATE_ARG, a->args[i].key)) {
+      states_bitset = a->args[i].value.integer;
+      break;
+    }
+  }
+  return states_bitset;
+}
+
+grpc_channel_args *grpc_channel_args_compression_algorithm_set_state(
+    grpc_channel_args *a,
+    grpc_compression_algorithm algorithm,
+    int state) {
+  gpr_uint32 states_bitset = find_compression_algorithm_states_bitset(a);
+  grpc_arg tmp;
+
+  if (state != 0) {
+    GPR_BITSET(&states_bitset, algorithm);
+  } else {
+    GPR_BITCLEAR(&states_bitset, algorithm); 
+  }
+
+  tmp.type = GRPC_ARG_INTEGER;
+  tmp.key = GRPC_COMPRESSION_ALGORITHM_STATE_ARG;
+  tmp.value.integer = states_bitset;
+  return grpc_channel_args_copy_and_add(a, &tmp, 1);
+}
+
+int grpc_channel_args_compression_algorithm_get_state(
+    grpc_channel_args *a,
+    grpc_compression_algorithm algorithm) {
+  const gpr_uint32 states_bitset = find_compression_algorithm_states_bitset(a);
+  return GPR_BITGET(states_bitset, algorithm);
+}
diff --git a/src/core/channel/channel_args.h b/src/core/channel/channel_args.h
index 7e6ddd3997a..f1a75117af4 100644
--- a/src/core/channel/channel_args.h
+++ b/src/core/channel/channel_args.h
@@ -67,4 +67,18 @@ grpc_compression_algorithm grpc_channel_args_get_compression_algorithm(
 grpc_channel_args *grpc_channel_args_set_compression_algorithm(
     grpc_channel_args *a, grpc_compression_algorithm algorithm);
 
+/** Sets the support for the given compression algorithm. By default, all
+ * compression algorithms are enabled. Disabling an algorithm set by 
+ * grpc_channel_args_set_compression_algorithm disables compression altogether
+ * */
+grpc_channel_args *grpc_channel_args_compression_algorithm_set_state(
+    grpc_channel_args *a,
+    grpc_compression_algorithm algorithm,
+    int enabled);
+
+/** Returns the state (true for enabled, false for disabled) for \a algorithm */
+int grpc_channel_args_compression_algorithm_get_state(
+    grpc_channel_args *a,
+    grpc_compression_algorithm algorithm);
+
 #endif /* GRPC_INTERNAL_CORE_CHANNEL_CHANNEL_ARGS_H */
diff --git a/test/cpp/interop/server.cc b/test/cpp/interop/server.cc
index 0097d1678c2..0485e447e5c 100644
--- a/test/cpp/interop/server.cc
+++ b/test/cpp/interop/server.cc
@@ -148,8 +148,6 @@ class TestServiceImpl : public TestService::Service {
         return Status(grpc::StatusCode::INTERNAL, "Error creating payload.");
       }
     }
-    const gpr_uint32 client_accept_encodings_bitset =
-        inspector.GetEncodingsAcceptedByClient();
 
     if (request->has_response_status()) {
       return Status(static_cast<grpc::StatusCode>